How to detect blue spot in an image
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
I have used web camera to detect the motion of specific objects that are shown in the attached image.
I can track red objects by set data(:,:,1), the only problem I can not detect blue objects or green objects even when I set data(:,:,3)
I have used the following code for this issue:
vid = videoinput('winvideo',3);
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 1;
start(vid)
h=axes;
while(ishandle(h))
data = getsnapshot(vid);
diff_im = imsubtract(data(:,:,3), rgb2gray(data)); % blue color
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
imshow(data);
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end
hold off
flushdata(vid);
end
stop(vid);
The blue and green colors can be seen by eye but the program can not detect them so any help to detect blue and green objects
thank you in advance
Hazim
2 comentarios
KALYAN ACHARJYA
el 3 de Nov. de 2019
Editada: KALYAN ACHARJYA
el 3 de Nov. de 2019
Can you clip attach the another image with marked on ROI (blue spot), which you are talking about?
Respuestas (1)
Guillaume
el 3 de Nov. de 2019
You're using a very crude way of detecting colour (working in RGB is not a good idea for colour detection) and the quality of your image is very poor (Huge light reflection and poor colour contrast) so it's no suprise that your algorithm doesn't work. In particular, the tiles that you call blue have equal amounts of green and blue, with some areas having more green than blue.
You'll have to use a better algorithm (working in hsv or lab) and improve the quality of your image.
Ver también
Categorías
Más información sobre Red en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!