object detection using RGB and image
이전 댓글 표시
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
답변 (2개)
Image Analyst
2019년 4월 1일
1 개 추천
I have code to track a colored sharpie marker. I'm attaching it. Adapt as needed.
댓글 수: 5
saeed ahmed
2019년 4월 1일
편집: Image Analyst
2019년 4월 2일
Image Analyst
2019년 4월 2일
Sounds like fun. Good luck.
saeed ahmed
2019년 4월 2일
saeed ahmed
2019년 4월 2일
Image Analyst
2019년 4월 2일
Maybe you can upload a short video with your target moving in it.
saeed ahmed
2019년 4월 2일
1 개 추천
댓글 수: 9
Image Analyst
2019년 4월 3일
편집: Image Analyst
2019년 4월 3일
I'm sure my code is well explained. I put way, WAY more comments into my programs than anyone else.
More data (your video) please.
saeed ahmed
2019년 4월 3일
Image Analyst
2019년 4월 3일
Yes, did you see the "deep learning in 9 lines of code" video that Mathworks has posted here? Search for Deep Learning in the main web site (not Answers) and I'm sure you will find it. It does that.
saeed ahmed
2019년 4월 3일
saeed ahmed
2019년 4월 3일
Image Analyst
2019년 4월 3일
That should be pretty easy. Upload the code to process one frame, plus a frame (image) that it can work with, if you still have trouble.
saeed ahmed
2019년 4월 4일
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.
saeed ahmed
2019년 4월 4일
카테고리
도움말 센터 및 File Exchange에서 Video Formats and Interfaces에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!