-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHomAdapter.h
More file actions
144 lines (115 loc) · 4.45 KB
/
HomAdapter.h
File metadata and controls
144 lines (115 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// HomAdapter.h
// RANSAC_AR
//
// Created by Michael Hotan on 5/12/12.
// Copyright (c) 2012 University of Washington. All rights reserved.
//
#ifndef RANSAC_AR_HomAdapter_h
#define RANSAC_AR_HomAdapter_h
#include <iostream>
#include <exception>
#include <string>
#include <cstdlib>
#include <vector>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
/*
Represents a
*/
class HomAdapter {
public:
/*
Wrapper class to hold the homography of between two objects. Homography is
determined by the list of corresponding points.
If point list are to large then the largest list is trimmed off until is equal to the smallest
Excess points are discarded
Arguments
m1- Vector of first set of correspondence points that should be correlated with image 1
m2- Vector of Second set of correspondence points that should be correlated with image 2
threshold- threshold for homographic correspondence
*/
HomAdapter(vector<Point2f> m1, vector<Point2f> m2, double threshold) : matchedPts1_(m1) , matchedPts2_(m2) {
while (matchedPts1_.size() > matchedPts2_.size()){
matchedPts1_.pop_back();
}
while (matchedPts2_.size() > matchedPts1_.size()){
matchedPts2_.pop_back();
}
Homography_ = findHomography(matchedPts1_, matchedPts2_, CV_RANSAC, threshold);
}
HomAdapter(vector<CvPoint2D32f> m1, vector<CvPoint2D32f> m2, double threshold) {
int size = (m1.size() < m2.size()) ? m1.size(): m2.size();
int i;
for(i = 0; i < size; ++i){
Point2f temp1, temp2;
temp1.x = m1[i].x;
temp1.y = m1[i].y;
temp2.x = m2[i].x;
temp2.y = m2[i].y;
matchedPts1_.push_back(temp1);
matchedPts2_.push_back(temp2);
}
Homography_ = findHomography(matchedPts1_, matchedPts2_, CV_RANSAC, threshold);
}
/*
Returns the Homography Matrix of Corresponding points
*/
cv::Mat GetHomography() const;
/*
Returns the Inverse Homography Matrix of Corresponding points
*/
cv::Mat GetInverseHomography() const;
/*
Returns the projected points from a list of points stored in ptList.
image_num represents
*/
cv::Mat GetProjectedPoints(const vector<CvPoint2D32f> &ptList, int image_num) const;
/*
Returns the projected points from a list of points stored in ptList.
image_num represents
*/
cv::Mat GetProjectedPoints(const vector<Point2f> &ptList, int image_num) const;
/*
Returns copy of first set of correspeondence points
*/
vector<Point2f> GetMatchedPts1() const {return matchedPts1_;}
/*
Returns copy of second set of correspondence points
*/
vector<Point2f> GetMatchedPts2() const {return matchedPts2_;}
/*
Returns the projected image based off the image number
if the image number is one. It projects img2 onto Image one
Arguments:
img1- First image with respect to finding the homography.
img1 correlates to the first vector of matched points
img2- second image with respect to finding the homography,
img2 correlates to the second vector of matched points
image_num - defines which image to project onto which Has to be 1 or 2;
Returns
Image of the the new projection
*/
cv::Mat GetProjectedWarpImage(const cv::Mat &img1, const cv::Mat &img2, int image_num);
/*
Returns the image of original points and the projections of the other images key points.
Circles represent the original points while the Xs represent the projection mapped abck to the original
image.
Arguments:
img1- First image with respect to finding the homography.
img1 correlates to the first vector of matched points
img2- second image with respect to finding the homography,
img2 correlates to the second vector of matched points
image_num - defines which image to project onto which, Has to be 1 or 2;
Return:
Images with projected points of image other then image_num onto image numbered with image_num
*/
cv::Mat GetProjectedPoints(const cv::Mat &img1, const cv::Mat &img2, int image_num);
void PrintCorrespondingPoints();
private:
vector<Point2f> matchedPts1_;
vector<Point2f> matchedPts2_;
cv::Mat Homography_;
};
#endif