How to detect blue spot in an image

3 次查看(过去 30 天)
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 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-11-3
编辑:KALYAN ACHARJYA 2019-11-3
Can you clip attach the another image with marked on ROI (blue spot), which you are talking about?
Hazim Nasir
Hazim Nasir 2019-11-3
thank you KAYAN, I have maked the blue spots in white circles
spot.jpg

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2019-11-3
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.
  1 个评论
Hazim Nasir
Hazim Nasir 2019-11-3
Thank you Guillaume
I actually the point is to work with poor resolution images
we can detect blue color by eye, so I hope there is away to detect them by algorthim

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Purple 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by