Motion Tracking in original video(avi)
Show older comments
Hi sir, can I know what should I do to tacking the motion object in original video clips(avi file)? basically, I have the code which is tacking a motion object in grayscale, but I don't know how to convert or work in original video. I really need your help. Please help. Thank you.
This is my code. Please point out my false. Thank you.
function trackingF1
ischar('barbeq')
%read the avi file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
avi = aviread('barbeq');
pix = double(cat(4,avi(1:2:end).cdata))/255; %get all pixels(normalize)
nFrames = size(pix,4);
% Create a movie struct from the video frames.
% turn every frames to gray
for f = 1:nFrames %read one frame at a time
%mov= avi(f).cdata;
pix(:,:,f) = (rgb2gray(pix(:,:,:,f))); %convert rgb to gray
end
a=240; % the max value
b=320; %the max value
width=a;
height=b;
nrames=f;
% Create a movie struct from the video frames f .
for b = 2:nrames
bw(:,:,b) = imabsdiff(pix(:,:,b),pix(:,:,b-1));
threshold=0.3;
k = bw(:,:,b);
bw(:,:,b) = im2bw(k,threshold);
bg1=bwlabel(bw(:,:,b));
%imshow(bw(:,:,b));
hold on
count1=1;
for h=1:width
for w=1:height
if(bw(h,w,b)>0.5)
tlength=h;
if (count1 == 1)
tpl=tlength;
count1=count1+1;
end
break
end
end
end
disp(tlength);
disp(tpl);
count2=1;
for w=1:height
for h=1:width
if(bw(h,w,b)>0.5)
lefside = w;
if (count2 == 1)
leflength=lefside;
end
count2=count2+1;
break
end
end
end
disp(lefside); % lefside
disp(leflength); % leflength
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wid=lefside-leflength;
hei=tlength-tpl;
widt=wid/2;
disp(widt);
heig=hei/2;
widthT=leflength+widt;
heightT=tpl+heig;
wth(b)=widthT;
hth(b)=heightT;
disp(heig); %heig
disp(widt); %widt
disp(hei); %hei
rectangle('Position',[leflength tpl wid hei],'EdgeColor','g');
disp(widthT);
disp(heightT);
plot(widthT,heightT, 'r*');
drawnow;
hold off
end
figure,subplot(1,2,1),
imshow(mov)
%subplot(1,2,2),imshow(bw(:,:,b))
f= mm;
for O= 1: mm;
nn = avi(O).cdata;
gray2in =(gray2ind(pix(:,:,:,O)));
p=gray2in;
gray2in = ind2rgb(gray2in,rgb);
imshow(gray2in)
end
b=u;
for TT = 1:u;
jj = avi(TT).cdata;
ind2g = ind2rgb(bw(:,:,b));
end
imshow(ind2g)
ori =ind2rgb(bw(:,:,b));
imshow(ori)
4 Comments
Walter Roberson
on 30 Apr 2012
The objects that you are tracking: are they sometimes distinguishable only by color? If they can be adequately distinguished by grayscale, then it might not be worth changing the algorithm.
Ernest
on 1 May 2012
Image Analyst
on 1 May 2012
Huh??? If it's ONLY distinguishable by grayscale, (NOT by color), then the color must be changing such that the luminance (L or V channel) stays constant. That would be very strange and highly unusual. And If that were the case (grayscale segmentation works), then why are you asking about doing it in color? I think English must not be your first language so some nuances are not realized. Therefore I think it's time for you to upload an image (a frame or two from the video) so we can see what's going on.
Walter Roberson
on 1 May 2012
You take the RGB image and convert it to grayscale. The pixel locations you find in the grayscale images will correspond exactly to the pixel locations in the RGB image.
Accepted Answer
More Answers (0)
Categories
Find more on Video Formats and Interfaces 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!