object detection using RGB and image
17 ビュー (過去 30 日間)
古いコメントを表示
vid=videoinput('winvideo',1,'YUY2_640x480');
%Set the frames&RGB
set(vid,'FramesPerTrigger',inf);
set(vid,'ReturnedColorspace','rgb')
%Set timer of screenshoting of images per millisecond
vid.FrameGrabInterval=0.5;
%Acquiring video
start(vid);
%Set number of Frames in video
while(vid.FramesAcquired<=10000)
%To store extracted frames
data=getsnapshot(vid);
%extracting the Red color from grayscale image
diff_im=imsubtract(1.3*data(:,:,1),rgb2gray(data));
%Filtering the noise
diff_im=medfilt2(diff_im,[3,3]);
%Converting grayscale image into binary image
diff_im=im2bw(diff_im,0.18);
%remove all pixels less than 300 pixel
diff_im=bwareaopen(diff_im,300);
%Draw rectangular boxes around the red object detected & label image
bw=bwlabel(diff_im,8);
stats=regionprops(bw,'BoundingBox','Centroid','Orientation');
%Show image
imshow(data);
hold on
%create a loop for the regtangular box
for(object=1:length(stats))
%saving data of centroid and boundary in BB & BC
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
be=stats(object).Orientation;
%Draw the rectangle with data BB & BC
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
%Plot the rectangle output
plot(bc(1),bc(2),'-m+')
%Output X&Y coordinates
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
b=text(bc(1)-50,bc(2)+45, strcat('angel:', num2str(round(be))));
end
hold off
end
stop(vid);
%Flush the memory
flushdata(vid);
clear all;
I use this code to detect the red color of any object and i want to detect specific object from images using imread command but i am not perfect in using matlab to read the image then compare it with the live video to check if they are similar then start creating rectangle around the object so can anyone help me to modify the code
0 件のコメント
回答 (2 件)
Image Analyst
2019 年 4 月 1 日
I have code to track a colored sharpie marker. I'm attaching it. Adapt as needed.
5 件のコメント
saeed ahmed
2019 年 4 月 2 日
9 件のコメント
Image Analyst
2019 年 4 月 4 日
Yes, just use either
- getsnapshot() to read from a live video stream, or
- read() to read from a video file, or
- imread() to read from a still image file.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!