trecvidDateMaker.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" // Farneback dense optical flow calculate and show in Munsell system of colors // Author : Zouxy // Date : 2013-3-15 // HomePage : https://blog.csdn.net/zouxy09 // Email : [email protected] // API calcOpticalFlowFarneback() comes from OpenCV, and this // 2D dense optical flow algorithm from the following paper: // Gunnar Farneback. "Two-Frame Motion Estimation Based on Polynomial Expansion". // And the OpenCV source code locate in ..\opencv2.4.3\modules\video\src\optflowgf.cpp #include <iostream> #include "opencv2/opencv.hpp" #include "motionToColor.h" using namespace cv; using namespace std; // Color encoding of flow vectors from: // https://members.shaw.ca/quadibloc/other/colint.htm // This code is modified from: // https://vision.middlebury.edu/flow/data/ int main(int, char**) { VideoCapture cap; cap.open(0); cap.open("G:\TrecvidData\08\DEV\LGW_20071101_E1_CAM2.mpg"); ///if( !cap.isOpened() ) /// return -1; IplImage* start_img=cvLoadImage("C:\Users\Dell\Desktop\output\0450.bmp",CV_LOAD_IMAGE_GRAYSCALE); IplImage* later_img=cvLoadImage("C:\Users\Dell\Desktop\output\0455.bmp",CV_LOAD_IMAGE_ANYCOLOR); IplImage* temp_save= NULL; Mat prevgray,gray,flow, cflow, frame; //Mat prevgray(imgA); //Mat gray(imgB); namedWindow("flow", 1); Mat motion2color; for(;;) { double t = (double)cvGetTickCount(); cap >> frame; frame=later_img; //cvWaitKey(); cvtColor(frame, gray, CV_BGR2GRAY); imshow("original", frame); //cvWaitKey(); //std::swap(prevgray, gray); prevgray=start_img; if( prevgray.data ) { calcOpticalFlowFarneback(prevgray, gray, flow, 0.8, 5, 15, 3, 5, 1.2, 0); motionToColor(flow, motion2color); imshow("flow", motion2color); IplImage temp=motion2color; //IplImage* img = cvCreateImage(cvGetSize(motion2color),8,3); //cvGetImage(matI,img); //cvSaveImage("rice1.bmp",img); //temp_save=motion2color; cvSaveImage("C:\Users\Dell\Desktop\output1.bmp", &temp); } if(waitKey(10)>=0) break; t = (double)cvGetTickCount() - t; cout << "cost time: " << t / ((double)cvGetTickFrequency()*1000.) << endl; break; } cvWaitKey(); return 0; }trecvidDateMaker.cpp : 定义控制台应用程序的入口点。 // #incl