2011-09-05 09:57:18 +02:00
|
|
|
#include "opencv2/core/core.hpp"
|
|
|
|
#include "opencv2/highgui/highgui.hpp"
|
|
|
|
#include "opencv2/imgproc/imgproc.hpp"
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
|
2012-03-16 22:21:04 +01:00
|
|
|
int main(int, char* [])
|
2011-09-05 09:57:18 +02:00
|
|
|
{
|
|
|
|
VideoCapture video(0);
|
|
|
|
Mat frame, curr, prev, curr64f, prev64f, hann;
|
|
|
|
int key = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
video >> frame;
|
2013-04-06 16:16:51 +02:00
|
|
|
cvtColor(frame, curr, COLOR_RGB2GRAY);
|
2011-09-05 09:57:18 +02:00
|
|
|
|
|
|
|
if(prev.empty())
|
|
|
|
{
|
|
|
|
prev = curr.clone();
|
|
|
|
createHanningWindow(hann, curr.size(), CV_64F);
|
|
|
|
}
|
|
|
|
|
|
|
|
prev.convertTo(prev64f, CV_64F);
|
|
|
|
curr.convertTo(curr64f, CV_64F);
|
|
|
|
|
|
|
|
Point2d shift = phaseCorrelate(prev64f, curr64f, hann);
|
2013-02-24 17:14:01 +01:00
|
|
|
double radius = std::sqrt(shift.x*shift.x + shift.y*shift.y);
|
2011-09-05 09:57:18 +02:00
|
|
|
|
|
|
|
if(radius > 5)
|
|
|
|
{
|
|
|
|
// draw a circle and line indicating the shift direction...
|
|
|
|
Point center(curr.cols >> 1, curr.rows >> 1);
|
2013-04-07 20:45:38 +02:00
|
|
|
circle(frame, center, (int)radius, Scalar(0, 255, 0), 3, LINE_AA);
|
|
|
|
line(frame, center, Point(center.x + (int)shift.x, center.y + (int)shift.y), Scalar(0, 255, 0), 3, LINE_AA);
|
2011-09-05 09:57:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
imshow("phase shift", frame);
|
|
|
|
key = waitKey(2);
|
|
|
|
|
|
|
|
prev = curr.clone();
|
|
|
|
} while((char)key != 27); // Esc to exit...
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|