1.光流简单概述
Optical flow or optic flow is the pattern of apparent motion of objects, surfaces, and edges in a visual scene caused by the relative motion between an observer and a scene.
Sequences of ordered images allow the estimation of motion as either instantaneous image velocities or discrete image displacements.
图像序列允许使用图片(像素)速度或离散图片位置来估计光流。
2.opencv3.2可用的三种计算稠密特征的算法
2.0函数简介
- Lucas–Kanade算法在opencv3.2(calcOpticalFlowPyrLK)得到的就是离散的位置,也就是输出像素点。
- Gunnar Farneback(calcOpticalFlowFarneback)得到的是速度(个人认为),flow是像素点的差值。
- SimpleFlow(calcOpticalFlowSF)也得到的是速度
2.1函数API介绍
Lucas–Kanade, Gunnar Farneback属于 Object TrackingVideo Analysis模块docs.opencv
SimpleFlow属于 Optical Flow Algorithms模块docs.opencv2.2运行时间
SimpleFlow运行大概要10sec,处理475*402*3的图片。Lucas–Kanade,Gunnar Farneback,处理475*402*1,则不到1sec。
3.代码部分C++
参考博客参考这个博客的显示的方法,这个博客是将视频逐frame标出光流。
函数API见上文模块信息。
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stdlib.h>
#include <opencv2/opencv.hpp>
#include "opencv2/optflow.hpp"
#include "opencv2/highgu