Motion Tracking in original video(avi)
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Image Analyst
2012 年 5 月 1 日
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
2012 年 5 月 1 日
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.
採用された回答
Geoff
2012 年 5 月 1 日
Okay, a quick skim over the code and it looks like your tracking algorithm works by thresholding a greyscale difference-image. It's the simplest way to detect movement on a static background without maintaining a background image, although the two-frame differencing method won't show movement of an object containing both light and dark regions.
My question is why do you want to make it operate without the greyscale conversion? The algorithm seems to rely on this.
Anyway, you can effectively do the same thing by differencing your RGB images. You'll end up with 3 times the amount of data. Now your differenced pixels are going to be the individual differences between red, green and blue components...
You now have to threshold these differenced pixel components, which means conversion to greyscale. MatLab's rgb2gray function uses the formula:
0.2989 * R + 0.5870 * G + 0.1140 * B
So in your search loops you need to do that and threshold-test the result. But your loops just examine every pixel in image until they find something, so I believe you're making unnecessary work by doing the calculation yourself inside a loop.
What I'm saying is, unless you want to completely change the algorithm, then doing a straight conversion from processing grey to processing RGB is likely to make it less efficient and ultimately a strange exercise.
1 件のコメント
Geoff
2012 年 5 月 1 日
The short answer is: you are already converting an RGB video to grayscale and then processing it. If you don't do that conversion at the start, you have to do it later. I don't see any obvious performance benefits in your algorithm to warrant that.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!