资源简介
LK光流法,是目前来讲监测运动目标中比较高效的算法。这是我试验中的一个代码,分享出来大家学习,用的是matlab语言
代码片段和文件信息
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; %initialize
dsx2=v1; dsx1=v1; dst=v1;
alpha2=625;
imax=20;
%Calculate gradients
dst(5:hm55:wm5) = ( Xnp1(6:hm5+16:wm5+1)-Xn(6:hm5+16:wm5+1) + Xnp1(6:hm5+15:wm5)-Xn(6:hm5+15:wm5)+ Xnp1(5:hm56:wm5+1)-Xn(5:hm56:wm5+1) +Xnp1(5:hm55:wm5)-Xn(5:hm55:wm5))/4;
dsx2(5:hm55:wm5) = ( Xnp1(6:hm5+16:wm5+1)-Xnp1(5:hm56:wm5+1) + Xnp1(6:hm5+15:wm5)-Xnp1(5:hm55:wm5)+ Xn(6:hm5+16:wm5+1)-Xn(5:hm56:wm5+1) +Xn(6:hm5+15:wm5)-Xn(5:hm55:wm5))/4;
dsx1(5:hm55:wm5) = ( Xnp1(6:hm5+16:wm5+1)-Xnp1(6:hm5+15:wm5) + Xnp1(5:hm56:wm5+1)-Xnp1(5:hm55:wm5)+ Xn(6:hm5+16:wm5+1)-Xn(6:hm5+15:wm5) +Xn(5:hm56:wm5+1)-Xn(5:hm55:wm5))/4;
for i=1:imax
delta=(dsx1.*v1+dsx2.*v2+dst)./(alpha2+dsx1.^2+dsx2.^2);
v1=v1-dsx1.*delta;
v2=v2-dsx2.*delta;
end
u=z; u(5:hm55:wm5)=v1(5:hm55:wm5);
v=z; v(5:hm55:wm5)=v2(5:hm55:wm5);
xskip=round(h/64);
[hsws]=size(u(1:xskip:h1:xskip:w));
us=zeros(hsws); vs=us;
N=xskip^2;
for i=1:hs-1
for j=1:ws-1
hk=i*xskip-xskip+1;
hl=i*xskip;
wk=j*xskip-xskip+1;
wl=j*xskip;
us(ij)=sum(sum(u(hk:hlwk:wl)))/N;
vs(ij)=sum(sum(v(hk:hlwk:wl)))/N;
end
end
figure(1);
quiver(usvs);
colormap(‘default‘);
axis ij;
axis tight;
axis equal;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2486 2018-07-24 20:46 LK实现光流场特征提取\HSoptflow.m
文件 447 2018-07-24 20:51 LK实现光流场特征提取\main1.m
文件 1631 2018-07-24 20:56 LK实现光流场特征提取\main3.m
文件 1095916 2018-07-24 20:47 LK实现光流场特征提取\monkeydog.bmp
文件 2441 2018-07-24 20:58 LK实现光流场特征提取\suptype.m
目录 0 2018-07-24 20:56 LK实现光流场特征提取\
- 上一篇:A*路径规划算法
- 下一篇:基于神经网络的人脸识别代码
相关资源
- comsol有限元分析热源固体传热
- 28个实际问题建模MATLAB源程序代码.r
- 引导滤波matlab源代码
- 配套光盘:现代信号处理教程-胡广书
- 计算全息包含fig和源文件
- Matlab 图像融合源代码及数据
- 使用Matlab完成简单的树叶识别源代码
- 卡尔曼滤波原理及应用 MATLAB仿真pd
- 强化学习matlab源代码289697
- 数值方法(matlab版)源代码289629
- Ncorr DIC分析
- MATLAB模拟的电磁学时域有限差分法(
-
《基于matlab-simuli
nk仿真技术》薛定 - MATLAB高效编程技巧与应用:25个案例分
- 图论算法及其MATLAB实现全书+源代码
- PPPH源码matlab有说明书
- 精通MATLAB优化计算PDF及代码.zip
- 数字调制解调技术的MATLAB与FPGA实现—
- 精通MATLAB图像处理及源代码
- 基于MATLAB的QPSK建模仿真(小论文+m源
- UWB超宽带信道研究及源码
- 冈萨雷斯 《数字图像处理matlab版》
- Xilinx FPGA开发实用教程光盘资源
- 《MATLAB图像与视频处理实用案例详解
- Fisherface的原始论文和完整的源代码
- 基于matlab的人脸识别含源程序.pdf
- MATLAB神经网络30个案例分析_全书[PDF
- 光伏电源仿真,光伏MPPT控制,光伏逆
- 数字通信同步技术的MATLAB与FPGA实现—
- MATLAB神经网络30个案例分析 电子书和
评论
共有 条评论