calcOpticalFlowFarneback

adsadsfssafd



#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{

VideoCapture capture("F:\\实验视频\\unwrap.avi");
 Mat prevgray, gray, flow, cflow, frame;
 do
 {
  capture>>frame;
  cvtColor(frame, gray, CV_RGB2GRAY);
  if (prevgray.data)
  {
   calcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3,15, 3, 5, 1.2, 0);
   cvtColor(gray, cflow, CV_GRAY2RGB);
   
   for (int y = 0; y < cflow.rows; y += 10 )
   {
    for (int x = 0; x < cflow.cols; x += 10)
    {
     Point2f fxy = flow.at<Point2f>(y, x);
     line(cflow, Point(x, y), Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), CV_RGB(0,255,0));
     circle(cflow, Point(x,y), 2, CV_RGB(255, 0, 0), -1);
    }
   }
   imshow("FLOW", cflow);
  }
  if (waitKey(100) >= 0)
  {
   break;
  }
 
  swap(prevgray, gray);
 } while (1);
return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值