資源簡介
經(jīng)典的光流計算,用matlab編寫的程序,希望對學(xué)習(xí)者有所幫助
代碼片段和文件信息
function?[usvs]?=?HSoptflow(Xrgbn)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?Author:?Gregory?Power?gregory.power@wpafb.af.mil
%?This?MATLAB?code?shows?a?Motion?Estimation?map?created?by
%?using?a?Horn?and?Schunck?motion?estimation?technique?on?two
%?consecutive?frames.??Input?requires.
%?????Xrgb(hwdN)?where?X?is?a?frame?sequence?of?a?certain
%????????????????height(h)?width?(w)?depth?(d=3?for?color)?
%????????????????and?number?of?frames?(N).?
%?????n=?is?the?starting?frame?number?which?is?less?than?N?
%?????V=?the?output?variable?which?is?a?2D?velocity?array
%
%?Sample?Call:?V=HSoptflow(X3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[hwdN]=size(Xrgb)
if?n>N-1
???error(1‘requested?file?greater?than?frame?number?required‘);
end;?
%get?two?image?frames
if?d==1
????Xn=double(Xrgb(::1n));
????Xnp1=double(Xrgb(::1n+1));
elseif?d==3
????Xn=double(Xrgb(::1n)*0.299+Xrgb(::2n)*0.587+Xrgb(::3n)*0.114);
????Xnp1=double(Xrgb(::1n+1)*0.299+Xrgb(::2n+1)*0.587+Xrgb(::3n+1)*0.114);
else
????error(2‘not?an?RGB?or?Monochrome?image?file‘);
end;
%get?image?size?and?adjust?for?border
size(Xn)
hm5=h-5;?wm5=w-5;
z=zeros(hw);?v1=z;?v2=z;
評論
共有 條評論