calcOpticalFlowFarneback

来源:互联网 发布:apache calcite 编辑:程序博客网 时间:2024/05/01 11:02

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;}


0 0
原创粉丝点击