forked from BloodAxe/OpenCV-Features-Comparison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageTransformation.hpp
163 lines (112 loc) · 4.29 KB
/
ImageTransformation.hpp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef ImageTransformation_hpp
#define ImageTransformation_hpp
#include <opencv2/opencv.hpp>
typedef std::vector<cv::KeyPoint> Keypoints;
typedef cv::Mat Descriptors;
typedef std::vector<cv::DMatch> Matches;
class ImageTransformation
{
public:
std::string name;
virtual std::vector<float> getX() const = 0;
virtual void transform(float t, const cv::Mat& source, cv::Mat& result) const = 0;
virtual bool canTransformKeypoints() const;
virtual void transform(float t, const Keypoints& source, Keypoints& result) const;
virtual cv::Mat getHomography(float t, const cv::Mat& source) const;
virtual ~ImageTransformation();
static bool findHomography( const Keypoints& source, const Keypoints& result, const Matches& input, Matches& inliers, cv::Mat& homography);
protected:
ImageTransformation(const std::string& transformationName)
: name(transformationName)
{
}
};
class ImageRotationTransformation : public ImageTransformation
{
public:
ImageRotationTransformation(float startAngleInDeg, float endAngleInDeg, float step, cv::Point2f rotationCenterInUnitSpace);
virtual std::vector<float> getX() const;
virtual void transform(float t, const cv::Mat& source, cv::Mat& result)const ;
virtual cv::Mat getHomography(float t, const cv::Mat& source) const;
private:
float m_startAngleInDeg;
float m_endAngleInDeg;
float m_step;
cv::Point2f m_rotationCenterInUnitSpace;
std::vector<float> m_args;
};
class ImageScalingTransformation : public ImageTransformation
{
public:
ImageScalingTransformation(float minScale, float maxScale, float step);
virtual std::vector<float> getX() const;
virtual void transform(float t, const cv::Mat& source, cv::Mat& result)const ;
virtual cv::Mat getHomography(float t, const cv::Mat& source) const;
private:
float m_minScale;
float m_maxScale;
float m_step;
std::vector<float> m_args;
};
class GaussianBlurTransform : public ImageTransformation
{
public:
GaussianBlurTransform(int maxKernelSize);
virtual std::vector<float> getX() const;
virtual void transform(float t, const cv::Mat& source, cv::Mat& result)const ;
private:
int m_maxKernelSize;
std::vector<float> m_args;
};
class BrightnessImageTransform : public ImageTransformation
{
public:
BrightnessImageTransform(int min, int max, int step);
virtual std::vector<float> getX() const;
virtual void transform(float t, const cv::Mat& source, cv::Mat& result)const ;
private:
int m_min;
int m_max;
int m_step;
std::vector<float> m_args;
};
class CombinedTransform : public ImageTransformation
{
public:
typedef enum
{
// Generate resulting X vector as list of all possible combinations of first and second args
Full,
// Largest argument vector used as is, the values for other vector is copied
Extrapolate,
// Smallest argument vector used as is, the values for other vector is interpolated from other
Interpolate
} ParamCombinationType;
CombinedTransform(cv::Ptr<ImageTransformation> first, cv::Ptr<ImageTransformation> second, ParamCombinationType type = Extrapolate);
virtual std::vector<float> getX() const ;
virtual void transform(float t, const cv::Mat& source, cv::Mat& result) const ;
virtual bool canTransformKeypoints() const;
virtual void transform(float t, const Keypoints& source, Keypoints& result) const;
virtual cv::Mat getHomography(float t, const cv::Mat& source) const;
private:
std::vector< float > m_x;
std::vector< std::pair<float, float> > m_params;
cv::Ptr<ImageTransformation> m_first;
cv::Ptr<ImageTransformation> m_second;
};
class PerspectiveTransform : public ImageTransformation
{
public:
PerspectiveTransform(int count);
virtual std::vector<float> getX() const;
virtual void transform(float t, const cv::Mat& source, cv::Mat& result) const;
virtual cv::Mat getHomography(float t, const cv::Mat& source) const;
private:
static cv::Mat warpPerspectiveRand( cv::RNG& rng );
float m_min;
float m_max;
float m_step;
std::vector<float> m_args;
std::vector<cv::Mat> m_homographies;
};
#endif