-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_interest_points.h
244 lines (187 loc) · 6.48 KB
/
image_interest_points.h
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#pragma once
#include "opcvwrapper.h"
#include "savekernel.h"
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <memory>
#include <limits.h>
struct ComponentsDescriptor
{
std::vector<cv::Point> region;
cv::Moments momInertia;
bool convex = false;
ComponentsDescriptor() {};
ComponentsDescriptor(const ComponentsDescriptor& rhs)
{
region = rhs.region;
momInertia = rhs.momInertia;
convex = rhs.convex;
}
ComponentsDescriptor(ComponentsDescriptor&& rhs) noexcept
{
this->region = rhs.region;
this->momInertia = rhs.momInertia;
this->convex = rhs.convex;
rhs.region.clear();
cv::Moments empty;
rhs.momInertia = empty;
}
ComponentsDescriptor& operator=( const ComponentsDescriptor& rhs)
{
region = rhs.region;
momInertia = rhs.momInertia;
convex = rhs.convex;
return *this;
}
ComponentsDescriptor& operator=(ComponentsDescriptor&& rhs) noexcept
{
this->region = rhs.region;
this->momInertia = rhs.momInertia;
this->convex = rhs.convex;
rhs.region.clear();
cv::Moments empty;
rhs.momInertia = empty;
return *this;
}
};
struct ImageDescriptors
{
std::pair<int, int> centroid;
double Area;
double perimeter;
double r_factor;
double orientation;
bool convex;
double HuMoments[7];
friend bool operator==(const ImageDescriptors& lhs, const ImageDescriptors& rhs)
{
return (lhs.centroid == rhs.centroid) &&
(lhs.Area == rhs.Area) &&
(lhs.perimeter == rhs.perimeter) &&
(lhs.orientation == rhs.orientation) &&
(lhs.convex == rhs.convex);
}
friend bool operator>(const ImageDescriptors& lhs, const ImageDescriptors& rhs)
{
return (lhs.Area > rhs.Area);
}
friend bool operator<(const ImageDescriptors& lhs, const ImageDescriptors& rhs)
{
return (lhs.Area < rhs.Area);
}
friend std::ostream& operator<<(std::ostream& os, const ImageDescriptors& d)
{
os << "--------------------------------------------------------------------------------" << std::endl;
os << "\t\tArea: " << d.Area << std::endl;
os << "\t\tPerimeter: " << d.perimeter << std::endl;
os << "\t\tRoundness: " << d.r_factor << std::endl;
os << "\t\tOrientation: " << d.orientation << std::endl;
os << "\t\tCentroid: " << "[" << d.centroid.first << "," << d.centroid.second << "]" << std::endl;
std::string convexHull = d.convex ? "convex" : "not Convex";
os << "\t\t" << "The region is " << convexHull << std::endl;
os << "--------------------------------------------------------------------------------" << std::endl;
return os;
}
};
using ObjectsCollection = std::vector< ComponentsDescriptor>;
using RegionPoints = std::vector<std::vector<Point> >;
using Descriptors = std::deque< ImageDescriptors >;
class CImageComponentsDescriptorBase
{
public:
CImageComponentsDescriptorBase(const Mat& img) :original_image(img) {};
~CImageComponentsDescriptorBase() { original_image.deallocate(); };
void detectRegions(int mode1 = RETR_CCOMP, int mode2 = CHAIN_APPROX_NONE);
ObjectsCollection getImageFullInformation()const { return Objects; };
// implement for each type of contour you are using
virtual void getObjectsInfo() = 0;
RegionPoints getraw_contourns() { return raw_contourns; };
protected:
CImageComponentsDescriptorBase(CImageComponentsDescriptorBase&) = delete;
CImageComponentsDescriptorBase& operator=(CImageComponentsDescriptorBase&) = delete;
ComponentsDescriptor ImageComponentsDescriptor;
ObjectsCollection Objects;
RegionPoints raw_contourns;
Mat original_image;
};
class CImageComponentsDescriptorNormal : public CImageComponentsDescriptorBase
{
public:
CImageComponentsDescriptorNormal(const Mat& img) :CImageComponentsDescriptorBase(img) {};
virtual void getObjectsInfo() override;
};
class CImageComponentsDescriptorHull : public CImageComponentsDescriptorBase
{
public:
CImageComponentsDescriptorHull(const Mat& img) :CImageComponentsDescriptorBase(img) {};
virtual void getObjectsInfo() override;
};
class CImageComponentsDescriptorAprox : public CImageComponentsDescriptorBase
{
public:
CImageComponentsDescriptorAprox(const Mat& img) :CImageComponentsDescriptorBase(img) {};
virtual void getObjectsInfo() override;
};
namespace image_info
{
std::string getHuhMomentsLine(Mat& img);
std::pair<int, int> getCentroid(cv::Moments& momInertia);
std::string convertWxStringToString(const wxString wsx);
double getArea(std::vector<cv::Point>& region);
double getPerimeter(std::vector<cv::Point>& region, bool closed);
double getRoundNess(std::vector<cv::Point>& region);
double getOrientation(cv::Moments& momInertia);
void getHuMoments(std::vector<cv::Point>& region, double* huh);
std::string getHuhMomentsLine(Mat& img);
std::string loadDescriptorFile();
int readCSV2( std::vector<std::vector<double>>& obs,
int nfields,
bool ignoreheader,
std::string& filename);
ObjectsCollection getContournInfo(const Mat& img);
}
namespace fast_algo
{
void ApplyAndCompareFAST(std::vector<Mat>& images,
std::vector<std::string>& filenames);
std::vector < cv::KeyPoint > ApplyFAST(const Mat& img);
}
namespace sift_algo
{
/*
* Creates a csv file with with sif descriptors called somewhere
* else
*/
void createCSV(std::vector < cv::KeyPoint >& descriptors, std::string fname);
Mat ApplyAndCompareSIFT(std::vector<Mat>& images,
std::vector<std::string>& filenames);
std::vector < cv::KeyPoint > ApplySift(const Mat& img, Mat& descriptors);
Mat getMatchedImage( Mat& descriptor1,
Mat& descriptor2,
std::vector < cv::KeyPoint >& kp1,
std::vector < cv::KeyPoint >& kp2,
Mat& img1,
Mat& img2,
int option = 0);
}
namespace template_matching
{
std::pair<Mat, Mat> ApplyTemplateMatching(const Mat&, Mat&);
template<typename F, typename...Args>
Mat ApplyTemplateMatchingFull( const Mat& BigImage,
std::vector<Mat>& templ,
int mode,
F& f,
Args&&... args);
namespace canny_matching
{
Mat ApplyTemplateMatchingFull_TM_SQDIFF(const Mat& BigImage, std::vector<Mat>& templ,int t1, int t2);
Mat ApplyTemplateMatchingFull_TM_SQDIFF_NORMED(const Mat& BigImage, std::vector<Mat>& templ, int t1, int t2);
Mat ApplyTemplateMatchingFull_TM_CCORR(const Mat& BigImage, std::vector<Mat>& templ, int t1, int t2);
Mat ApplyTemplateMatchingFull_TM_CCORR_NORMED(const Mat& BigImage, std::vector<Mat>& templ, int t1, int t2);
Mat ApplyTemplateMatchingFull_TM_CCOEFF(const Mat& BigImage, std::vector<Mat>& templ, int t1, int t2);
Mat ApplyTemplateMatchingFull_TM_CCOEFF_NORMED(const Mat& BigImage, std::vector<Mat>& templ, int t1, int t2);
}
}