~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/samples/cpp/phase_corr.cpp

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "opencv2/core/core.hpp"
 
2
#include "opencv2/videoio/videoio.hpp"
 
3
#include "opencv2/highgui/highgui.hpp"
 
4
#include "opencv2/imgproc/imgproc.hpp"
 
5
 
 
6
using namespace cv;
 
7
 
 
8
int main(int, char* [])
 
9
{
 
10
    VideoCapture video(0);
 
11
    Mat frame, curr, prev, curr64f, prev64f, hann;
 
12
    int key = 0;
 
13
 
 
14
    do
 
15
    {
 
16
        video >> frame;
 
17
        cvtColor(frame, curr, COLOR_RGB2GRAY);
 
18
 
 
19
        if(prev.empty())
 
20
        {
 
21
            prev = curr.clone();
 
22
            createHanningWindow(hann, curr.size(), CV_64F);
 
23
        }
 
24
 
 
25
        prev.convertTo(prev64f, CV_64F);
 
26
        curr.convertTo(curr64f, CV_64F);
 
27
 
 
28
        Point2d shift = phaseCorrelate(prev64f, curr64f, hann);
 
29
        double radius = std::sqrt(shift.x*shift.x + shift.y*shift.y);
 
30
 
 
31
        if(radius > 5)
 
32
        {
 
33
            // draw a circle and line indicating the shift direction...
 
34
            Point center(curr.cols >> 1, curr.rows >> 1);
 
35
            circle(frame, center, (int)radius, Scalar(0, 255, 0), 3, LINE_AA);
 
36
            line(frame, center, Point(center.x + (int)shift.x, center.y + (int)shift.y), Scalar(0, 255, 0), 3, LINE_AA);
 
37
        }
 
38
 
 
39
        imshow("phase shift", frame);
 
40
        key = waitKey(2);
 
41
 
 
42
        prev = curr.clone();
 
43
    } while((char)key != 27); // Esc to exit...
 
44
 
 
45
    return 0;
 
46
}