1 #ifndef __OPENCV_FEATURES_2D_MANUAL_HPP__
2 #define __OPENCV_FEATURES_2D_MANUAL_HPP__
3
4 #include "opencv2/opencv_modules.hpp"
5
6 #ifdef HAVE_OPENCV_FEATURES2D
7 #include "opencv2/features2d.hpp"
8 #include "features2d_converters.hpp"
9
10 #undef SIMPLEBLOB // to solve conflict with wincrypt.h on windows
11
12 namespace cv
13 {
14
CV_EXPORTS_AS(FeatureDetector)15 class CV_EXPORTS_AS(FeatureDetector) javaFeatureDetector
16 {
17 public:
18 CV_WRAP void detect( const Mat& image, CV_OUT std::vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const
19 { return wrapped->detect(image, keypoints, mask); }
20
21 CV_WRAP void detect( const std::vector<Mat>& images, CV_OUT std::vector<std::vector<KeyPoint> >& keypoints, const std::vector<Mat>& masks=std::vector<Mat>() ) const
22 { return wrapped->detect(images, keypoints, masks); }
23
24 CV_WRAP bool empty() const
25 { return wrapped->empty(); }
26
27 enum
28 {
29 FAST = 1,
30 STAR = 2,
31 SIFT = 3,
32 SURF = 4,
33 ORB = 5,
34 MSER = 6,
35 GFTT = 7,
36 HARRIS = 8,
37 SIMPLEBLOB = 9,
38 DENSE = 10,
39 BRISK = 11,
40 AKAZE = 12,
41
42
43 GRIDDETECTOR = 1000,
44
45 GRID_FAST = GRIDDETECTOR + FAST,
46 GRID_STAR = GRIDDETECTOR + STAR,
47 GRID_SIFT = GRIDDETECTOR + SIFT,
48 GRID_SURF = GRIDDETECTOR + SURF,
49 GRID_ORB = GRIDDETECTOR + ORB,
50 GRID_MSER = GRIDDETECTOR + MSER,
51 GRID_GFTT = GRIDDETECTOR + GFTT,
52 GRID_HARRIS = GRIDDETECTOR + HARRIS,
53 GRID_SIMPLEBLOB = GRIDDETECTOR + SIMPLEBLOB,
54 GRID_DENSE = GRIDDETECTOR + DENSE,
55 GRID_BRISK = GRIDDETECTOR + BRISK,
56 GRID_AKAZE = GRIDDETECTOR + AKAZE,
57
58
59 PYRAMIDDETECTOR = 2000,
60
61 PYRAMID_FAST = PYRAMIDDETECTOR + FAST,
62 PYRAMID_STAR = PYRAMIDDETECTOR + STAR,
63 PYRAMID_SIFT = PYRAMIDDETECTOR + SIFT,
64 PYRAMID_SURF = PYRAMIDDETECTOR + SURF,
65 PYRAMID_ORB = PYRAMIDDETECTOR + ORB,
66 PYRAMID_MSER = PYRAMIDDETECTOR + MSER,
67 PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT,
68 PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS,
69 PYRAMID_SIMPLEBLOB = PYRAMIDDETECTOR + SIMPLEBLOB,
70 PYRAMID_DENSE = PYRAMIDDETECTOR + DENSE,
71 PYRAMID_BRISK = PYRAMIDDETECTOR + BRISK,
72 PYRAMID_AKAZE = PYRAMIDDETECTOR + AKAZE,
73
74 DYNAMICDETECTOR = 3000,
75
76 DYNAMIC_FAST = DYNAMICDETECTOR + FAST,
77 DYNAMIC_STAR = DYNAMICDETECTOR + STAR,
78 DYNAMIC_SIFT = DYNAMICDETECTOR + SIFT,
79 DYNAMIC_SURF = DYNAMICDETECTOR + SURF,
80 DYNAMIC_ORB = DYNAMICDETECTOR + ORB,
81 DYNAMIC_MSER = DYNAMICDETECTOR + MSER,
82 DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT,
83 DYNAMIC_HARRIS = DYNAMICDETECTOR + HARRIS,
84 DYNAMIC_SIMPLEBLOB = DYNAMICDETECTOR + SIMPLEBLOB,
85 DYNAMIC_DENSE = DYNAMICDETECTOR + DENSE,
86 DYNAMIC_BRISK = DYNAMICDETECTOR + BRISK,
87 DYNAMIC_AKAZE = DYNAMICDETECTOR + AKAZE
88 };
89
90 //supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS BRISK AKAZE Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
91 //not supported: SimpleBlob, Dense
92 CV_WRAP static javaFeatureDetector* create( int detectorType )
93 {
94 //String name;
95 if (detectorType > DYNAMICDETECTOR)
96 {
97 //name = "Dynamic";
98 detectorType -= DYNAMICDETECTOR;
99 }
100 if (detectorType > PYRAMIDDETECTOR)
101 {
102 //name = "Pyramid";
103 detectorType -= PYRAMIDDETECTOR;
104 }
105 if (detectorType > GRIDDETECTOR)
106 {
107 //name = "Grid";
108 detectorType -= GRIDDETECTOR;
109 }
110
111 Ptr<FeatureDetector> fd;
112 switch(detectorType)
113 {
114 case FAST:
115 fd = FastFeatureDetector::create();
116 break;
117 //case STAR:
118 // fd = xfeatures2d::StarDetector::create();
119 // break;
120 //case SIFT:
121 // name = name + "SIFT";
122 // break;
123 //case SURF:
124 // name = name + "SURF";
125 // break;
126 case ORB:
127 fd = ORB::create();
128 break;
129 case MSER:
130 fd = MSER::create();
131 break;
132 case GFTT:
133 fd = GFTTDetector::create();
134 break;
135 case HARRIS:
136 {
137 Ptr<GFTTDetector> gftt = GFTTDetector::create();
138 gftt->setHarrisDetector(true);
139 fd = gftt;
140 }
141 break;
142 case SIMPLEBLOB:
143 fd = SimpleBlobDetector::create();
144 break;
145 //case DENSE:
146 // name = name + "Dense";
147 // break;
148 case BRISK:
149 fd = BRISK::create();
150 break;
151 case AKAZE:
152 fd = AKAZE::create();
153 break;
154 default:
155 CV_Error( Error::StsBadArg, "Specified feature detector type is not supported." );
156 break;
157 }
158
159 return new javaFeatureDetector(fd);
160 }
161
162 CV_WRAP void write( const String& fileName ) const
163 {
164 FileStorage fs(fileName, FileStorage::WRITE);
165 wrapped->write(fs);
166 }
167
168 CV_WRAP void read( const String& fileName )
169 {
170 FileStorage fs(fileName, FileStorage::READ);
171 wrapped->read(fs.root());
172 }
173
174 private:
175 javaFeatureDetector(Ptr<FeatureDetector> _wrapped) : wrapped(_wrapped)
176 {}
177
178 Ptr<FeatureDetector> wrapped;
179 };
180
181 class CV_EXPORTS_AS(DescriptorMatcher) javaDescriptorMatcher
182 {
183 public:
184 CV_WRAP bool isMaskSupported() const
185 { return wrapped->isMaskSupported(); }
186
187 CV_WRAP void add( const std::vector<Mat>& descriptors )
188 { return wrapped->add(descriptors); }
189
190 CV_WRAP const std::vector<Mat>& getTrainDescriptors() const
191 { return wrapped->getTrainDescriptors(); }
192
193 CV_WRAP void clear()
194 { return wrapped->clear(); }
195
196 CV_WRAP bool empty() const
197 { return wrapped->empty(); }
198
199 CV_WRAP void train()
200 { return wrapped->train(); }
201
202 CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
203 CV_OUT std::vector<DMatch>& matches, const Mat& mask=Mat() ) const
204 { return wrapped->match(queryDescriptors, trainDescriptors, matches, mask); }
205
206 CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
207 CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
208 const Mat& mask=Mat(), bool compactResult=false ) const
209 { return wrapped->knnMatch(queryDescriptors, trainDescriptors, matches, k, mask, compactResult); }
210
211 CV_WRAP void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
212 CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance,
213 const Mat& mask=Mat(), bool compactResult=false ) const
214 { return wrapped->radiusMatch(queryDescriptors, trainDescriptors, matches, maxDistance, mask, compactResult); }
215
216 CV_WRAP void match( const Mat& queryDescriptors, CV_OUT std::vector<DMatch>& matches,
217 const std::vector<Mat>& masks=std::vector<Mat>() )
218 { return wrapped->match(queryDescriptors, matches, masks); }
219
220 CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
221 const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false )
222 { return wrapped->knnMatch(queryDescriptors, matches, k, masks, compactResult); }
223
224 CV_WRAP void radiusMatch( const Mat& queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance,
225 const std::vector<Mat>& masks=std::vector<Mat>(), bool compactResult=false )
226 { return wrapped->radiusMatch(queryDescriptors, matches, maxDistance, masks, compactResult); }
227
228 enum
229 {
230 FLANNBASED = 1,
231 BRUTEFORCE = 2,
232 BRUTEFORCE_L1 = 3,
233 BRUTEFORCE_HAMMING = 4,
234 BRUTEFORCE_HAMMINGLUT = 5,
235 BRUTEFORCE_SL2 = 6
236 };
237
238 CV_WRAP_AS(clone) javaDescriptorMatcher* jclone( bool emptyTrainData=false ) const
239 {
240 return new javaDescriptorMatcher(wrapped->clone(emptyTrainData));
241 }
242
243 //supported: FlannBased, BruteForce, BruteForce-L1, BruteForce-Hamming, BruteForce-HammingLUT
244 CV_WRAP static javaDescriptorMatcher* create( int matcherType )
245 {
246 String name;
247
248 switch(matcherType)
249 {
250 case FLANNBASED:
251 name = "FlannBased";
252 break;
253 case BRUTEFORCE:
254 name = "BruteForce";
255 break;
256 case BRUTEFORCE_L1:
257 name = "BruteForce-L1";
258 break;
259 case BRUTEFORCE_HAMMING:
260 name = "BruteForce-Hamming";
261 break;
262 case BRUTEFORCE_HAMMINGLUT:
263 name = "BruteForce-HammingLUT";
264 break;
265 case BRUTEFORCE_SL2:
266 name = "BruteForce-SL2";
267 break;
268 default:
269 CV_Error( Error::StsBadArg, "Specified descriptor matcher type is not supported." );
270 break;
271 }
272
273 return new javaDescriptorMatcher(DescriptorMatcher::create(name));
274 }
275
276 CV_WRAP void write( const String& fileName ) const
277 {
278 FileStorage fs(fileName, FileStorage::WRITE);
279 wrapped->write(fs);
280 }
281
282 CV_WRAP void read( const String& fileName )
283 {
284 FileStorage fs(fileName, FileStorage::READ);
285 wrapped->read(fs.root());
286 }
287
288 private:
289 javaDescriptorMatcher(Ptr<DescriptorMatcher> _wrapped) : wrapped(_wrapped)
290 {}
291
292 Ptr<DescriptorMatcher> wrapped;
293 };
294
295 class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor
296 {
297 public:
298 CV_WRAP void compute( const Mat& image, CV_IN_OUT std::vector<KeyPoint>& keypoints, Mat& descriptors ) const
299 { return wrapped->compute(image, keypoints, descriptors); }
300
301 CV_WRAP void compute( const std::vector<Mat>& images, CV_IN_OUT std::vector<std::vector<KeyPoint> >& keypoints, CV_OUT std::vector<Mat>& descriptors ) const
302 { return wrapped->compute(images, keypoints, descriptors); }
303
304 CV_WRAP int descriptorSize() const
305 { return wrapped->descriptorSize(); }
306
307 CV_WRAP int descriptorType() const
308 { return wrapped->descriptorType(); }
309
310 CV_WRAP bool empty() const
311 { return wrapped->empty(); }
312
313 enum
314 {
315 SIFT = 1,
316 SURF = 2,
317 ORB = 3,
318 BRIEF = 4,
319 BRISK = 5,
320 FREAK = 6,
321 AKAZE = 7,
322
323
324 OPPONENTEXTRACTOR = 1000,
325
326
327
328 OPPONENT_SIFT = OPPONENTEXTRACTOR + SIFT,
329 OPPONENT_SURF = OPPONENTEXTRACTOR + SURF,
330 OPPONENT_ORB = OPPONENTEXTRACTOR + ORB,
331 OPPONENT_BRIEF = OPPONENTEXTRACTOR + BRIEF,
332 OPPONENT_BRISK = OPPONENTEXTRACTOR + BRISK,
333 OPPONENT_FREAK = OPPONENTEXTRACTOR + FREAK,
334 OPPONENT_AKAZE = OPPONENTEXTRACTOR + AKAZE
335 };
336
337 //supported SIFT, SURF, ORB, BRIEF, BRISK, FREAK, AKAZE, Opponent(XXXX)
338 //not supported: Calonder
339 CV_WRAP static javaDescriptorExtractor* create( int extractorType )
340 {
341 //String name;
342
343 if (extractorType > OPPONENTEXTRACTOR)
344 {
345 //name = "Opponent";
346 extractorType -= OPPONENTEXTRACTOR;
347 }
348
349 Ptr<DescriptorExtractor> de;
350 switch(extractorType)
351 {
352 //case SIFT:
353 // name = name + "SIFT";
354 // break;
355 //case SURF:
356 // name = name + "SURF";
357 // break;
358 case ORB:
359 de = ORB::create();
360 break;
361 //case BRIEF:
362 // name = name + "BRIEF";
363 // break;
364 case BRISK:
365 de = BRISK::create();
366 break;
367 //case FREAK:
368 // name = name + "FREAK";
369 // break;
370 case AKAZE:
371 de = AKAZE::create();
372 break;
373 default:
374 CV_Error( Error::StsBadArg, "Specified descriptor extractor type is not supported." );
375 break;
376 }
377
378 return new javaDescriptorExtractor(de);
379 }
380
381 CV_WRAP void write( const String& fileName ) const
382 {
383 FileStorage fs(fileName, FileStorage::WRITE);
384 wrapped->write(fs);
385 }
386
387 CV_WRAP void read( const String& fileName )
388 {
389 FileStorage fs(fileName, FileStorage::READ);
390 wrapped->read(fs.root());
391 }
392
393 private:
394 javaDescriptorExtractor(Ptr<DescriptorExtractor> _wrapped) : wrapped(_wrapped)
395 {}
396
397 Ptr<DescriptorExtractor> wrapped;
398 };
399
400 #if 0
401 //DO NOT REMOVE! The block is required for sources parser
402 enum
403 {
404 DRAW_OVER_OUTIMG = 1, // Output image matrix will not be created (Mat::create).
405 // Matches will be drawn on existing content of output image.
406 NOT_DRAW_SINGLE_POINTS = 2, // Single keypoints will not be drawn.
407 DRAW_RICH_KEYPOINTS = 4 // For each keypoint the circle around keypoint with keypoint size and
408 // orientation will be drawn.
409 };
410
411 // Draw keypoints.
412 CV_EXPORTS_W void drawKeypoints( const Mat& image, const std::vector<KeyPoint>& keypoints, Mat& outImage,
413 const Scalar& color=Scalar::all(-1), int flags=0 );
414
415 // Draws matches of keypints from two images on output image.
416 CV_EXPORTS_W void drawMatches( const Mat& img1, const std::vector<KeyPoint>& keypoints1,
417 const Mat& img2, const std::vector<KeyPoint>& keypoints2,
418 const std::vector<DMatch>& matches1to2, Mat& outImg,
419 const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
420 const std::vector<char>& matchesMask=std::vector<char>(), int flags=0 );
421
422 CV_EXPORTS_AS(drawMatches2) void drawMatches( const Mat& img1, const std::vector<KeyPoint>& keypoints1,
423 const Mat& img2, const std::vector<KeyPoint>& keypoints2,
424 const std::vector<std::vector<DMatch> >& matches1to2, Mat& outImg,
425 const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
426 const std::vector<std::vector<char> >& matchesMask=std::vector<std::vector<char> >(), int flags=0);
427
428 #endif
429
430 } //cv
431
432 #endif // HAVE_OPENCV_FEATURES2D
433
434 #endif // __OPENCV_FEATURES_2D_MANUAL_HPP__
435