Color Detection and Tracking Using USB cam

15 views (last 30 days)
Pablo Joannes
Pablo Joannes on 5 Oct 2017
Edited: Walter Roberson on 5 Nov 2024 at 4:12
I'm new to using the MATLAB tool, I'm enjoying it.
I would like the help of you to be able to make recognize colors, like red, through a USB camera. like this one: https://www.mathworks.com/help/vision/examples/face-detection-and-tracking-using-live-video-acquisition.html
Only in this he recognizes the face of people, I wanted with colors ... can you help me?

Answers (2)

Redha Reghioua
Redha Reghioua on 30 Sep 2020
vid=videoinput('winvideo',1,'YUY2_320x240');
set(vid,'FramesPerTrigger',inf);
set(vid,'ReturnedColorspace','rgb');
vid.FrameGrabInterval=5;
start(vid);
while(vid.FramesAcquired<=100)
data=getsnapshot(vid);
diff_im=imsubtract(data(:,:,2),rgb2gray(data)); % 1= red, 2=green, 3= bleu
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+');
end
hold off
end
stop(vid);
flushdata(vid);
clear all

Image Analyst
Image Analyst on 5 Nov 2024 at 4:07
See my attached video tracking demo where I track the movement of a green Sharpie marker.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!