/* * video_homography.cpp * * Created on: Oct 18, 2010 * Author: erublee */ #include #include #include #include using namespace std; using namespace cv; namespace { void drawMatchesRelative(const vector& train, const vector& query, std::vector& matches, Mat& img, const vector& mask = vector< unsigned char> ()) { for (int i = 0; i < (int)matches.size(); i++) { if (mask.empty() || mask[i]) { Point2f pt_new = query[matches[i].queryIdx].pt; Point2f pt_old = train[matches[i].trainIdx].pt; Point2f dist = pt_new - pt_old; cv::line(img, pt_new, pt_old, Scalar(125, 255, 125), 1); cv::circle(img, pt_new, 2, Scalar(255, 0, 125), 1); } } } void keypoints2points(const vector& in, vector& out) { out.clear(); out.reserve(in.size()); for (size_t i = 0; i < in.size(); ++i) { out.push_back(in[i].pt); } } void points2keypoints(const vector& in, vector& out) { out.clear(); out.reserve(in.size()); for (size_t i = 0; i < in.size(); ++i) { out.push_back(KeyPoint(in[i], 1)); } } void warpKeypoints(const Mat& H, const vector& in, vector& out) { vector pts; keypoints2points(in, pts); vector pts_w(pts.size()); Mat m_pts_w(pts_w); perspectiveTransform(Mat(pts), m_pts_w, H); points2keypoints(pts_w, out); } void matches2points(const vector& train, const vector& query, const std::vector& matches, std::vector& pts_train, std::vector& pts_query) { pts_train.clear(); pts_query.clear(); pts_train.reserve(matches.size()); pts_query.reserve(matches.size()); size_t i = 0; for (; i < matches.size(); i++) { const DMatch & dmatch = matches[i]; pts_query.push_back(query[dmatch.queryIdx].pt); pts_train.push_back(train[dmatch.trainIdx].pt); } } void resetH(Mat&H) { H = Mat::eye(3, 3, CV_32FC1); } } int main(int ac, char ** av) { if (ac != 2) { cout << "usage: " << av[0] << "