- Here instead of mentioning the number of black-colored coordinates, you can take the total number from the number of rows in C. Since matrix C represents the coordinates of those pixel the size will simply represent total number.
- Here the getpts will return coordinates in cartesian format that is the xi will tell the column number whereas the yi will give the row number. So, interchanging the coordinates xi and yi while comparing with C will work.
How do I get judgement information about linetracer map? (If I choose some coordinate)
1 次查看(过去 30 天)
显示 更早的评论
I want to get information about coordinate what I choose.
If I click road, It talks it's on line, If I click no-road, It talks it's not on line.
but It's not worked I expecting.
My code is below.
A = imread('C.jpg'); %C is my linetracer map.
ww = A(:,:,1); %C is only constituted with only black & white, so I choose just first dimension.
imshow(ww); %It show my linetracer map.
[xi, yi] = getpts; %If I double-click somewhere of map, it save on xi and yi.
xi = round(xi);
yi = round(yi);
B = ww < 240; %If under 240, It is possibly black, so I choose that area.
[row, col] = find(B == 1); %I make matrix using coordinate where color is black.
C = [row, col];
alpha = 1;
while alpha < 31235 %this number is how many black-colored coordinate has.
if C(alpha,1) == xi
if C(alpha, 2) == yi
fprintf("it's on line.")
break;
end
end
alpha = alpha+1;
end
if alpha == 31235
fprintf("it's not on line.")
end
=> Then problem has happen. anywhere I clicked, It always shows me "it's not on line."
How can I get correct judgement?
0 个评论
回答(1 个)
Raunak Gupta
2020-12-27
Hi,
I see two potential issues in the code, correcting those will make the code working.
In my opinion the threshold for black is quiet loose, if the image contains pixels which are not completely black or white. You may make changes to that according to the requirement. Below code might help!
A = imread('C.jpg'); %C is my linetracer map.
ww = A(:,:,1); %C is only constituted with only black & white, so I choose just first dimension.
imshow(ww); %It show my linetracer map.
[xi, yi] = getpts; %If I double-click somewhere of map, it save on xi and yi.
xi = round(xi);
yi = round(yi);
B = ww < 240; %If under 240, It is possibly black, so I choose that area.
[row, col] = find(B == 1); %I make matrix using coordinate where color is black.
C = [row, col];
alpha = 1;
total_points = size(C,1);
while alpha < total_points %this number is how many black-colored coordinate has.
if C(alpha,1) == yi
if C(alpha, 2) == xi
fprintf("it's on line.")
break;
end
end
alpha = alpha+1;
end
if alpha == total_points
fprintf("it's not on line.")
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!