main.cpp

An Tran, 2015-05-05 09:52 am

Download (1.2 kB)

 
1
#include <opencv2/cudaoptflow.hpp>
2
#include <opencv2/highgui.hpp>
3
#include <opencv2/imgproc.hpp>
4
#include <opencv2/optflow.hpp>
5
#include <iostream>
6
7
using namespace std;
8
using namespace cv;
9
10
int main(int argc, char** argv)
11
{
12
    cout << "OpenCV version: " << CV_VERSION << endl;
13
    VideoCapture capture;
14
    char* video = argv[1];
15
    capture.open(video);
16
17
    if(!capture.isOpened()) {
18
        fprintf(stderr, "Could not initialize capturing..\n");
19
        return -1;
20
    }
21
22
    Mat frame, prev_grey, grey, flow;
23
    int frame_num = 0;
24
    for(;;)
25
    {
26
        // get a new frame
27
        capture >> frame;
28
        if(frame.empty())
29
            break;
30
        frame_num++;
31
32
        if (frame_num == 1)
33
        {
34
            cvtColor(frame, prev_grey, CV_BGR2GRAY);
35
            continue;
36
        }
37
        cvtColor(frame, grey, CV_BGR2GRAY);
38
39
        // compute optical flow
40
        //cv::calcOpticalFlowFarneback(prev_grey, grey, flow, 0.5, 3, 15, 3, 7, 1.5, OPTFLOW_FARNEBACK_GAUSSIAN);
41
        Ptr<cuda::BroxOpticalFlow> broxFlow = cuda::BroxOpticalFlow::create();
42
        broxFlow->calc(prev_grey, grey, flow);
43
44
        // assign new img to old img
45
        prev_grey = grey;
46
    }
47
}