object detection using RGB and image
Mostrar comentarios más antiguos
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
Respuestas (2)
Image Analyst
el 1 de Abr. de 2019
1 voto
I have code to track a colored sharpie marker. I'm attaching it. Adapt as needed.
5 comentarios
saeed ahmed
el 1 de Abr. de 2019
Editada: Image Analyst
el 2 de Abr. de 2019
Image Analyst
el 2 de Abr. de 2019
Sounds like fun. Good luck.
saeed ahmed
el 2 de Abr. de 2019
saeed ahmed
el 2 de Abr. de 2019
Image Analyst
el 2 de Abr. de 2019
Maybe you can upload a short video with your target moving in it.
saeed ahmed
el 2 de Abr. de 2019
1 voto
9 comentarios
Image Analyst
el 3 de Abr. de 2019
Editada: Image Analyst
el 3 de Abr. de 2019
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
el 3 de Abr. de 2019
Image Analyst
el 3 de Abr. de 2019
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
el 3 de Abr. de 2019
saeed ahmed
el 3 de Abr. de 2019
Image Analyst
el 3 de Abr. de 2019
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
el 4 de Abr. de 2019
Image Analyst
el 4 de Abr. de 2019
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
el 4 de Abr. de 2019
Categorías
Más información sobre Video Formats and Interfaces en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!