|
|
|
@ -1,9 +1,9 @@ |
|
|
|
|
/*
|
|
|
|
|
* video_homography.cpp |
|
|
|
|
* |
|
|
|
|
* Created on: Oct 18, 2010 |
|
|
|
|
* Author: erublee |
|
|
|
|
*/ |
|
|
|
|
* video_homography.cpp |
|
|
|
|
* |
|
|
|
|
* Created on: Oct 18, 2010 |
|
|
|
|
* Author: erublee |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <opencv2/calib3d/calib3d.hpp> |
|
|
|
|
#include <opencv2/highgui/highgui.hpp> |
|
|
|
@ -29,10 +29,10 @@ void help(char **av) |
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
|
{ |
|
|
|
|
void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, |
|
|
|
|
void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& query, |
|
|
|
|
std::vector<cv::DMatch>& matches, Mat& img, const vector<unsigned char>& mask = vector< |
|
|
|
|
unsigned char> ()) |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < (int)matches.size(); i++) |
|
|
|
|
{ |
|
|
|
|
if (mask.empty() || mask[i]) |
|
|
|
@ -46,46 +46,46 @@ void drawMatchesRelative(const vector<KeyPoint>& train, const vector<KeyPoint>& |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Takes a descriptor and turns it into an xy point
|
|
|
|
|
void keypoints2points(const vector<KeyPoint>& in, vector<Point2f>& out) |
|
|
|
|
{ |
|
|
|
|
//Takes a descriptor and turns it into an xy point
|
|
|
|
|
void keypoints2points(const vector<KeyPoint>& in, vector<Point2f>& out) |
|
|
|
|
{ |
|
|
|
|
out.clear(); |
|
|
|
|
out.reserve(in.size()); |
|
|
|
|
for (size_t i = 0; i < in.size(); ++i) |
|
|
|
|
{ |
|
|
|
|
out.push_back(in[i].pt); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Takes an xy point and appends that to a keypoint structure
|
|
|
|
|
void points2keypoints(const vector<Point2f>& in, vector<KeyPoint>& out) |
|
|
|
|
{ |
|
|
|
|
//Takes an xy point and appends that to a keypoint structure
|
|
|
|
|
void points2keypoints(const vector<Point2f>& in, vector<KeyPoint>& out) |
|
|
|
|
{ |
|
|
|
|
out.clear(); |
|
|
|
|
out.reserve(in.size()); |
|
|
|
|
for (size_t i = 0; i < in.size(); ++i) |
|
|
|
|
{ |
|
|
|
|
out.push_back(KeyPoint(in[i], 1)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Uses computed homography H to warp original input points to new planar position
|
|
|
|
|
void warpKeypoints(const Mat& H, const vector<KeyPoint>& in, vector<KeyPoint>& out) |
|
|
|
|
{ |
|
|
|
|
//Uses computed homography H to warp original input points to new planar position
|
|
|
|
|
void warpKeypoints(const Mat& H, const vector<KeyPoint>& in, vector<KeyPoint>& out) |
|
|
|
|
{ |
|
|
|
|
vector<Point2f> pts; |
|
|
|
|
keypoints2points(in, pts); |
|
|
|
|
vector<Point2f> pts_w(pts.size()); |
|
|
|
|
Mat m_pts_w(pts_w); |
|
|
|
|
perspectiveTransform(Mat(pts), m_pts_w, H); |
|
|
|
|
points2keypoints(pts_w, out); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Converts matching indices to xy points
|
|
|
|
|
void matches2points(const vector<KeyPoint>& train, const vector<KeyPoint>& query, |
|
|
|
|
//Converts matching indices to xy points
|
|
|
|
|
void matches2points(const vector<KeyPoint>& train, const vector<KeyPoint>& query, |
|
|
|
|
const std::vector<cv::DMatch>& matches, std::vector<cv::Point2f>& pts_train, |
|
|
|
|
std::vector<Point2f>& pts_query) |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
pts_train.clear(); |
|
|
|
|
pts_query.clear(); |
|
|
|
@ -104,12 +104,12 @@ void matches2points(const vector<KeyPoint>& train, const vector<KeyPoint>& query |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void resetH(Mat&H) |
|
|
|
|
{ |
|
|
|
|
void resetH(Mat&H) |
|
|
|
|
{ |
|
|
|
|
H = Mat::eye(3, 3, CV_32FC1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int ac, char ** av) |
|
|
|
@ -210,7 +210,7 @@ int main(int ac, char ** av) |
|
|
|
|
train_kpts = query_kpts; |
|
|
|
|
query_desc.copyTo(train_desc); |
|
|
|
|
} |
|
|
|
|
char key = waitKey(2); |
|
|
|
|
char key = (char)waitKey(2); |
|
|
|
|
switch (key) |
|
|
|
|
{ |
|
|
|
|
case 'l': |
|
|
|
|