2016-02-15 21:37:29 +08:00
|
|
|
#include "opencv2/core.hpp"
|
|
|
|
#include "opencv2/videoio.hpp"
|
|
|
|
#include "opencv2/highgui.hpp"
|
|
|
|
#include "opencv2/imgproc.hpp"
|
2011-09-05 15:57:18 +08:00
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
|
2012-03-17 05:21:04 +08:00
|
|
|
int main(int, char* [])
|
2011-09-05 15:57:18 +08:00
|
|
|
{
|
|
|
|
VideoCapture video(0);
|
|
|
|
Mat frame, curr, prev, curr64f, prev64f, hann;
|
|
|
|
int key = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
video >> frame;
|
2013-04-06 22:16:51 +08:00
|
|
|
cvtColor(frame, curr, COLOR_RGB2GRAY);
|
2011-09-05 15:57:18 +08: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-25 00:14:01 +08:00
|
|
|
double radius = std::sqrt(shift.x*shift.x + shift.y*shift.y);
|
2011-09-05 15:57:18 +08:00
|
|
|
|
|
|
|
if(radius > 5)
|
|
|
|
{
|
|
|
|
// draw a circle and line indicating the shift direction...
|
|
|
|
Point center(curr.cols >> 1, curr.rows >> 1);
|
2013-04-08 02:45:38 +08: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 15:57:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
imshow("phase shift", frame);
|
|
|
|
key = waitKey(2);
|
|
|
|
|
|
|
|
prev = curr.clone();
|
|
|
|
} while((char)key != 27); // Esc to exit...
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|