How to detect blue spot in an image

4 ビュー (過去 30 日間)
Hazim Nasir
Hazim Nasir 2019 年 11 月 2 日
コメント済み: Hazim Nasir 2019 年 11 月 3 日
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 Center および File ExchangeRed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by