-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathfeatures2d.cc
164 lines (141 loc) · 6.29 KB
/
features2d.cc
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
#include "features2d.h"
#include "utils.h"
extern "C" {
void* cv_mser_new(int delta,
int min_area,
int max_area,
double max_variation,
double min_diversity,
int max_evolution,
double area_threshold,
double min_margin,
int edge_blur_size) {
cv::Ptr<cv::MSER> result = cv::MSER::create(delta,
min_area,
max_area,
max_variation,
min_diversity,
max_evolution,
area_threshold,
min_margin,
edge_blur_size);
return new cv::Ptr<cv::MSER>(result);
}
void cv_mser_drop(cv::Ptr<cv::MSER>* detector) {
delete detector;
detector = nullptr;
}
void cv_mser_detect_regions(cv::Ptr<cv::MSER>* detector,
cv::Mat* image,
CVec<CVec<Point2i>>* msers,
CVec<Rect>* bboxes) {
std::vector<std::vector<cv::Point>> msers_vector;
std::vector<cv::Rect> bboxes_vector;
detector->get()->detectRegions(*image, msers_vector, bboxes_vector);
cv_to_ffi(msers_vector, msers);
cv_to_ffi(bboxes_vector, bboxes);
}
void cv_mser_detect_and_compute(cv::Ptr<cv::MSER>* detector,
cv::Mat* image,
cv::Mat* mask,
CVec<KeyPoint>* keypoints,
cv::Mat* descriptors,
bool useProvidedKeypoints) {
std::vector<cv::KeyPoint> keypoints_vector;
detector->get()->detectAndCompute(*image, *mask, keypoints_vector, *descriptors, useProvidedKeypoints);
cv_to_ffi(keypoints_vector, keypoints);
}
void* cv_surf_new(double hessianThreshold, int nOctaves, int nOctaveLayers, bool extended, bool upright) {
auto result = cv::xfeatures2d::SURF::create(hessianThreshold, nOctaves, nOctaveLayers, extended, upright);
return new cv::Ptr<cv::xfeatures2d::SURF>(result);
}
void cv_surf_drop(cv::Ptr<cv::xfeatures2d::SURF>* detector) {
delete detector;
detector = nullptr;
}
void cv_surf_detect_and_compute(cv::Ptr<cv::xfeatures2d::SURF>* detector,
cv::Mat* image,
cv::Mat* mask,
CVec<KeyPoint>* keypoints,
cv::Mat* descriptors,
bool useProvidedKeypoints) {
std::vector<cv::KeyPoint> keypoints_vector;
detector->get()->detectAndCompute(*image, *mask, keypoints_vector, *descriptors, useProvidedKeypoints);
cv_to_ffi(keypoints_vector, keypoints);
}
void* cv_sift_new(int nfeatures, int nOctaveLayers, double contrastThreshold, double edgeThreshold, double sigma) {
auto result = cv::xfeatures2d::SIFT::create(nfeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma);
return new cv::Ptr<cv::xfeatures2d::SIFT>(result);
}
void cv_sift_drop(cv::Ptr<cv::xfeatures2d::SIFT>* detector) {
delete detector;
detector = nullptr;
}
void cv_sift_detect_and_compute(cv::Ptr<cv::xfeatures2d::SIFT>* detector,
cv::Mat* image,
cv::Mat* mask,
CVec<KeyPoint>* keypoints,
cv::Mat* descriptors,
bool useProvidedKeypoints) {
std::vector<cv::KeyPoint> keypoints_vector;
detector->get()->detectAndCompute(*image, *mask, keypoints_vector, *descriptors, useProvidedKeypoints);
cv_to_ffi(keypoints_vector, keypoints);
}
void* cv_matcher_new(const char* descriptorMatcherType) {
auto result = cv::DescriptorMatcher::create(descriptorMatcherType);
return new cv::Ptr<cv::DescriptorMatcher>(result);
}
void cv_matcher_drop(cv::Ptr<cv::DescriptorMatcher>* descriptorMatcher) {
delete descriptorMatcher;
descriptorMatcher = nullptr;
}
void cv_matcher_add(cv::Ptr<cv::DescriptorMatcher>& descriptorMatcher, CVec<cv::Mat*>& descriptors) {
std::vector<cv::Mat> descriptors_vector;
ffi_to_cv(descriptors, &descriptors_vector);
descriptorMatcher.get()->add(descriptors_vector);
}
void cv_matcher_train(cv::Ptr<cv::DescriptorMatcher>& descriptorMatcher) {
descriptorMatcher.get()->train();
}
bool cv_matcher_is_empty(cv::Ptr<cv::DescriptorMatcher>& descriptorMatcher) {
return descriptorMatcher.get()->empty();
}
void cv_matcher_match(cv::Ptr<cv::DescriptorMatcher>& descriptorMatcher,
cv::Mat& queryDescriptors,
CVec<DMatch>* matches) {
std::vector<cv::DMatch> matches_vector;
descriptorMatcher.get()->match(queryDescriptors, matches_vector);
cv_to_ffi(matches_vector, matches);
}
void cv_matcher_match_two(cv::Ptr<cv::DescriptorMatcher>& descriptorMatcher,
cv::Mat& queryDescriptors,
cv::Mat& trainDescriptors,
CVec<DMatch>* matches) {
std::vector<cv::DMatch> matches_vector;
descriptorMatcher.get()->match(queryDescriptors, trainDescriptors, matches_vector);
cv_to_ffi(matches_vector, matches);
}
void cv_matcher_knn_match(cv::Ptr<cv::DescriptorMatcher>& descriptorMatcher,
cv::Mat& queryDescriptors,
int k,
CVec<CVec<DMatch>>* matches) {
std::vector<std::vector<cv::DMatch>> matches_vector;
descriptorMatcher.get()->knnMatch(queryDescriptors, matches_vector, k);
cv_to_ffi(matches_vector, matches);
}
void* cv_bow_trainer_new(int clusterCount, const cv::TermCriteria& termcrit, int attempts, int flags) {
return new cv::BOWKMeansTrainer(clusterCount, termcrit, attempts, flags);
}
void cv_bow_trainer_drop(cv::BOWKMeansTrainer* trainer) {
delete trainer;
trainer = nullptr;
}
void cv_bow_trainer_add(cv::BOWKMeansTrainer& trainer, cv::Mat& descriptors) {
trainer.add(descriptors);
}
void* cv_bow_trainer_cluster(cv::BOWKMeansTrainer& trainer) {
cv::Mat* mat = new cv::Mat();
*mat = trainer.cluster();
return (mat);
}
}