red color tracking

2 visualizzazioni (ultimi 30 giorni)
Ernest
Ernest il 15 Mag 2012
Hi Sir, this code is create for tracking the red color of the video, however, there is a error when i run the code, Can you please help me to solve the problem and let me know the fault? thank you.
here is my code.
movieInfo = aviinfo('barbeq');
mov = aviread('barbeq') ;
numberOfFrames = size(mov, 2);
numberOfFramesWritten = 0;
% Prepare a figure to show the images in the upper half of the screen.
for f = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = mov(f).cdata;
end
%imshow(thisFrame)
nrames=f;
for b = 2:nrames
% from the grayscale image to extract the red components in the image.
diff_im = imsubtract(thisFrame, rgb2gray(b));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
% Convert the resulting grayscale image into a binary image.
diff_im = im2bw(diff_im,0.18);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
imshow(thisFrame)
end
when I run this code, it gave me the feedback.
??? Error using ==> rgb2gray>parse_inputs at 82 MAP must be a m x 3 array.
Error in ==> rgb2gray at 35 X = parse_inputs(varargin{:});
Error in ==> colortest at 26
Can someone please help me in this part? Thank you very much...

Risposte (1)

Walter Roberson
Walter Roberson il 15 Mag 2012
Your "for f" loop extracts all the frames, overwriting the single matrix "thisFrame" each time, leaving "thisFrame" just as the last frame. That is unlikely to be what you want.
You are passing "b" to rgb2gray(). "b" is your scalar variable from the "for b" loop. You cannot rgb2gray() as scalar variable.
  4 Commenti
Image Analyst
Image Analyst il 15 Mag 2012
I have some color segmentation demos in my File Exchange but I haven't posted anything that tracks across video frames. There are some in the File Exchange, but I give no gaurantees about how good they are:
http://www.mathworks.com/matlabcentral/fileexchange/33666-simple-particle-filter-demo
http://www.mathworks.com/matlabcentral/fileexchange/35353-tacking-a-maroon-colour-ball-in-video
http://www.mathworks.com/matlabcentral/fileexchange/34498-skinfacedetecting
http://www.mathworks.com/matlabcentral/fileexchange/33804-tracking-of-a-point-in-video-using-kalman-filter
http://www.mathworks.com/matlabcentral/fileexchange/32492-laser-dot-isolation
and so on. 305 File Exchange items on tracking!
Ernest
Ernest il 16 Mag 2012
Do you have any code that can tracking a color object in a avi video file? but not using webcam?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by