-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Expand file tree
/
Copy pathfeatures2d.hpp
More file actions
1611 lines (1305 loc) · 71.8 KB
/
features2d.hpp
File metadata and controls
1611 lines (1305 loc) · 71.8 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_FEATURES_2D_HPP
#define OPENCV_FEATURES_2D_HPP
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core.hpp"
#ifdef HAVE_OPENCV_FLANN
#include "opencv2/flann/miniflann.hpp"
#endif
/**
@defgroup features2d 2D Features Framework
@{
@defgroup features2d_main Feature Detection and Description
@defgroup features2d_match Descriptor Matchers
Matchers of keypoint descriptors in OpenCV have wrappers with a common interface that enables
you to easily switch between different algorithms solving the same problem. This section is
devoted to matching descriptors that are represented as vectors in a multidimensional space.
All objects that implement vector descriptor matchers inherit the DescriptorMatcher interface.
@defgroup features2d_draw Drawing Function of Keypoints and Matches
@defgroup features2d_category Object Categorization
This section describes approaches based on local 2D features and used to categorize objects.
@defgroup feature2d_hal Hardware Acceleration Layer
@{
@defgroup features2d_hal_interface Interface
@}
@}
*/
namespace cv
{
//! @addtogroup features2d_main
//! @{
// //! writes vector of keypoints to the file storage
// CV_EXPORTS void write(FileStorage& fs, const String& name, const std::vector<KeyPoint>& keypoints);
// //! reads vector of keypoints from the specified file storage node
// CV_EXPORTS void read(const FileNode& node, CV_OUT std::vector<KeyPoint>& keypoints);
/** @brief A class filters a vector of keypoints.
Because now it is difficult to provide a convenient interface for all usage scenarios of the
keypoints filter class, it has only several needed by now static methods.
*/
class CV_EXPORTS KeyPointsFilter
{
public:
KeyPointsFilter(){}
/*
* Remove keypoints within borderPixels of an image edge.
*/
static void runByImageBorder( std::vector<KeyPoint>& keypoints, Size imageSize, int borderSize );
/*
* Remove keypoints of sizes out of range.
*/
static void runByKeypointSize( std::vector<KeyPoint>& keypoints, float minSize,
float maxSize=FLT_MAX );
/*
* Remove keypoints from some image by mask for pixels of this image.
*/
static void runByPixelsMask( std::vector<KeyPoint>& keypoints, const Mat& mask );
/*
* Remove objects from some image and a vector of points by mask for pixels of this image
*/
static void runByPixelsMask2VectorPoint(std::vector<KeyPoint> &keypoints, std::vector<std::vector<Point> > &removeFrom, const Mat &mask);
/*
* Remove duplicated keypoints.
*/
static void removeDuplicated( std::vector<KeyPoint>& keypoints );
/*
* Remove duplicated keypoints and sort the remaining keypoints
*/
static void removeDuplicatedSorted( std::vector<KeyPoint>& keypoints );
/*
* Retain the specified number of the best keypoints (according to the response)
*/
static void retainBest( std::vector<KeyPoint>& keypoints, int npoints );
};
/************************************ Base Classes ************************************/
/** @brief Abstract base class for 2D image feature detectors and descriptor extractors
*/
#ifdef __EMSCRIPTEN__
class CV_EXPORTS_W Feature2D : public Algorithm
#else
class CV_EXPORTS_W Feature2D : public virtual Algorithm
#endif
{
public:
virtual ~Feature2D();
/** @brief Detects keypoints in an image (first variant) or image set (second variant).
@param image Image.
@param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set
of keypoints detected in images[i] .
@param mask Mask specifying where to look for keypoints (optional). It must be a 8-bit integer
matrix with non-zero values in the region of interest.
*/
CV_WRAP virtual void detect( InputArray image,
CV_OUT std::vector<KeyPoint>& keypoints,
InputArray mask=noArray() );
/** @overload
@param images Image set.
@param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set
of keypoints detected in images[i] .
@param masks Masks for each input image specifying where to look for keypoints (optional).
masks[i] is a mask for images[i].
*/
CV_WRAP virtual void detect( InputArrayOfArrays images,
CV_OUT std::vector<std::vector<KeyPoint> >& keypoints,
InputArrayOfArrays masks=noArray() );
/** @brief Computes the descriptors for a set of keypoints detected in an image (first variant) or image set
(second variant).
@param image Image.
@param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be
computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint
with several dominant orientations (for each orientation).
@param descriptors Computed descriptors. In the second variant of the method descriptors[i] are
descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the
descriptor for keypoint j-th keypoint.
*/
CV_WRAP virtual void compute( InputArray image,
CV_OUT CV_IN_OUT std::vector<KeyPoint>& keypoints,
OutputArray descriptors );
/** @overload
@param images Image set.
@param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be
computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint
with several dominant orientations (for each orientation).
@param descriptors Computed descriptors. In the second variant of the method descriptors[i] are
descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the
descriptor for keypoint j-th keypoint.
*/
CV_WRAP virtual void compute( InputArrayOfArrays images,
CV_OUT CV_IN_OUT std::vector<std::vector<KeyPoint> >& keypoints,
OutputArrayOfArrays descriptors );
/** Detects keypoints and computes the descriptors */
CV_WRAP virtual void detectAndCompute( InputArray image, InputArray mask,
CV_OUT std::vector<KeyPoint>& keypoints,
OutputArray descriptors,
bool useProvidedKeypoints=false );
CV_WRAP virtual int descriptorSize() const;
CV_WRAP virtual int descriptorType() const;
CV_WRAP virtual int defaultNorm() const;
CV_WRAP void write( const String& fileName ) const;
CV_WRAP void read( const String& fileName );
virtual void write( FileStorage&) const CV_OVERRIDE;
// see corresponding cv::Algorithm method
CV_WRAP virtual void read( const FileNode&) CV_OVERRIDE;
//! Return true if detector object is empty
CV_WRAP virtual bool empty() const CV_OVERRIDE;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
// see corresponding cv::Algorithm method
CV_WRAP inline void write(FileStorage& fs, const String& name) const { Algorithm::write(fs, name); }
#if CV_VERSION_MAJOR < 5
inline void write(const Ptr<FileStorage>& fs, const String& name) const { CV_Assert(fs); Algorithm::write(*fs, name); }
#endif
};
/** Feature detectors in OpenCV have wrappers with a common interface that enables you to easily switch
between different algorithms solving the same problem. All objects that implement keypoint detectors
inherit the FeatureDetector interface. */
typedef Feature2D FeatureDetector;
/** Extractors of keypoint descriptors in OpenCV have wrappers with a common interface that enables you
to easily switch between different algorithms solving the same problem. This section is devoted to
computing descriptors represented as vectors in a multidimensional space. All objects that implement
the vector descriptor extractors inherit the DescriptorExtractor interface.
*/
typedef Feature2D DescriptorExtractor;
/** @brief Class for implementing the wrapper which makes detectors and extractors to be affine invariant,
described as ASIFT in @cite YM11 .
*/
class CV_EXPORTS_W AffineFeature : public Feature2D
{
public:
/**
@param backend The detector/extractor you want to use as backend.
@param maxTilt The highest power index of tilt factor. 5 is used in the paper as tilt sampling range n.
@param minTilt The lowest power index of tilt factor. 0 is used in the paper.
@param tiltStep Tilt sampling step \f$\delta_t\f$ in Algorithm 1 in the paper.
@param rotateStepBase Rotation sampling step factor b in Algorithm 1 in the paper.
*/
CV_WRAP static Ptr<AffineFeature> create(const Ptr<Feature2D>& backend,
int maxTilt = 5, int minTilt = 0, float tiltStep = 1.4142135623730951f, float rotateStepBase = 72);
CV_WRAP virtual void setViewParams(const std::vector<float>& tilts, const std::vector<float>& rolls) = 0;
CV_WRAP virtual void getViewParams(std::vector<float>& tilts, std::vector<float>& rolls) const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
};
typedef AffineFeature AffineFeatureDetector;
typedef AffineFeature AffineDescriptorExtractor;
/** @brief Class for extracting keypoints and computing descriptors using the Scale Invariant Feature Transform
(SIFT) algorithm by D. Lowe @cite Lowe04 .
*/
class CV_EXPORTS_W SIFT : public Feature2D
{
public:
/**
@param nfeatures The number of best features to retain. The features are ranked by their scores
(measured in SIFT algorithm as the local contrast)
@param nOctaveLayers The number of layers in each octave. 3 is the value used in D. Lowe paper. The
number of octaves is computed automatically from the image resolution.
@param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform
(low-contrast) regions. The larger the threshold, the less features are produced by the detector.
@note The contrast threshold will be divided by nOctaveLayers when the filtering is applied. When
nOctaveLayers is set to default and if you want to use the value used in D. Lowe paper, 0.03, set
this argument to 0.09.
@param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning
is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are
filtered out (more features are retained).
@param sigma The sigma of the Gaussian applied to the input image at the octave \#0. If your image
is captured with a weak camera with soft lenses, you might want to reduce the number.
@param enable_precise_upscale Whether to enable precise upscaling in the scale pyramid, which maps
index \f$\texttt{x}\f$ to \f$\texttt{2x}\f$. This prevents localization bias. The option
is disabled by default.
*/
CV_WRAP static Ptr<SIFT> create(int nfeatures = 0, int nOctaveLayers = 3,
double contrastThreshold = 0.04, double edgeThreshold = 10,
double sigma = 1.6, bool enable_precise_upscale = false);
/** @brief Create SIFT with specified descriptorType.
@param nfeatures The number of best features to retain. The features are ranked by their scores
(measured in SIFT algorithm as the local contrast)
@param nOctaveLayers The number of layers in each octave. 3 is the value used in D. Lowe paper. The
number of octaves is computed automatically from the image resolution.
@param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform
(low-contrast) regions. The larger the threshold, the less features are produced by the detector.
@note The contrast threshold will be divided by nOctaveLayers when the filtering is applied. When
nOctaveLayers is set to default and if you want to use the value used in D. Lowe paper, 0.03, set
this argument to 0.09.
@param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning
is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are
filtered out (more features are retained).
@param sigma The sigma of the Gaussian applied to the input image at the octave \#0. If your image
is captured with a weak camera with soft lenses, you might want to reduce the number.
@param descriptorType The type of descriptors. Only CV_32F and CV_8U are supported.
@param enable_precise_upscale Whether to enable precise upscaling in the scale pyramid, which maps
index \f$\texttt{x}\f$ to \f$\texttt{2x}\f$. This prevents localization bias. The option
is disabled by default.
*/
CV_WRAP static Ptr<SIFT> create(int nfeatures, int nOctaveLayers,
double contrastThreshold, double edgeThreshold,
double sigma, int descriptorType, bool enable_precise_upscale = false);
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
CV_WRAP virtual void setNFeatures(int maxFeatures) = 0;
CV_WRAP virtual int getNFeatures() const = 0;
CV_WRAP virtual void setNOctaveLayers(int nOctaveLayers) = 0;
CV_WRAP virtual int getNOctaveLayers() const = 0;
CV_WRAP virtual void setContrastThreshold(double contrastThreshold) = 0;
CV_WRAP virtual double getContrastThreshold() const = 0;
CV_WRAP virtual void setEdgeThreshold(double edgeThreshold) = 0;
CV_WRAP virtual double getEdgeThreshold() const = 0;
CV_WRAP virtual void setSigma(double sigma) = 0;
CV_WRAP virtual double getSigma() const = 0;
};
typedef SIFT SiftFeatureDetector;
typedef SIFT SiftDescriptorExtractor;
/** @brief Class implementing the BRISK keypoint detector and descriptor extractor, described in @cite LCS11 .
*/
class CV_EXPORTS_W BRISK : public Feature2D
{
public:
/** @brief The BRISK constructor
@param thresh AGAST detection threshold score.
@param octaves detection octaves. Use 0 to do single scale.
@param patternScale apply this scale to the pattern used for sampling the neighbourhood of a
keypoint.
*/
CV_WRAP static Ptr<BRISK> create(int thresh=30, int octaves=3, float patternScale=1.0f);
/** @brief The BRISK constructor for a custom pattern
@param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for
keypoint scale 1).
@param numberList defines the number of sampling points on the sampling circle. Must be the same
size as radiusList..
@param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint
scale 1).
@param dMin threshold for the long pairings used for orientation determination (in pixels for
keypoint scale 1).
@param indexChange index remapping of the bits. */
CV_WRAP static Ptr<BRISK> create(const std::vector<float> &radiusList, const std::vector<int> &numberList,
float dMax=5.85f, float dMin=8.2f, const std::vector<int>& indexChange=std::vector<int>());
/** @brief The BRISK constructor for a custom pattern, detection threshold and octaves
@param thresh AGAST detection threshold score.
@param octaves detection octaves. Use 0 to do single scale.
@param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for
keypoint scale 1).
@param numberList defines the number of sampling points on the sampling circle. Must be the same
size as radiusList..
@param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint
scale 1).
@param dMin threshold for the long pairings used for orientation determination (in pixels for
keypoint scale 1).
@param indexChange index remapping of the bits. */
CV_WRAP static Ptr<BRISK> create(int thresh, int octaves, const std::vector<float> &radiusList,
const std::vector<int> &numberList, float dMax=5.85f, float dMin=8.2f,
const std::vector<int>& indexChange=std::vector<int>());
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
/** @brief Set detection threshold.
@param threshold AGAST detection threshold score.
*/
CV_WRAP virtual void setThreshold(int threshold) = 0;
CV_WRAP virtual int getThreshold() const = 0;
/** @brief Set detection octaves.
@param octaves detection octaves. Use 0 to do single scale.
*/
CV_WRAP virtual void setOctaves(int octaves) = 0;
CV_WRAP virtual int getOctaves() const = 0;
/** @brief Set detection patternScale.
@param patternScale apply this scale to the pattern used for sampling the neighbourhood of a
keypoint.
*/
CV_WRAP virtual void setPatternScale(float patternScale) = 0;
CV_WRAP virtual float getPatternScale() const = 0;
};
/** @brief Class implementing the ORB (*oriented BRIEF*) keypoint detector and descriptor extractor
described in @cite RRKB11 . The algorithm uses FAST in pyramids to detect stable keypoints, selects
the strongest features using FAST or Harris response, finds their orientation using first-order
moments and computes the descriptors using BRIEF (where the coordinates of random point pairs (or
k-tuples) are rotated according to the measured orientation).
*/
class CV_EXPORTS_W ORB : public Feature2D
{
public:
enum ScoreType { HARRIS_SCORE=0, FAST_SCORE=1 };
static const int kBytes = 32;
/** @brief The ORB constructor
@param nfeatures The maximum number of features to retain.
@param scaleFactor Pyramid decimation ratio, greater than 1. scaleFactor==2 means the classical
pyramid, where each next level has 4x less pixels than the previous, but such a big scale factor
will degrade feature matching scores dramatically. On the other hand, too close to 1 scale factor
will mean that to cover certain scale range you will need more pyramid levels and so the speed
will suffer.
@param nlevels The number of pyramid levels. The smallest level will have linear size equal to
input_image_linear_size/pow(scaleFactor, nlevels - firstLevel).
@param edgeThreshold This is size of the border where the features are not detected. It should
roughly match the patchSize parameter.
@param firstLevel The level of pyramid to put source image to. Previous layers are filled
with upscaled source image.
@param WTA_K The number of points that produce each element of the oriented BRIEF descriptor. The
default value 2 means the BRIEF where we take a random point pair and compare their brightnesses,
so we get 0/1 response. Other possible values are 3 and 4. For example, 3 means that we take 3
random points (of course, those point coordinates are random, but they are generated from the
pre-defined seed, so each element of BRIEF descriptor is computed deterministically from the pixel
rectangle), find point of maximum brightness and output index of the winner (0, 1 or 2). Such
output will occupy 2 bits, and therefore it will need a special variant of Hamming distance,
denoted as NORM_HAMMING2 (2 bits per bin). When WTA_K=4, we take 4 random points to compute each
bin (that will also occupy 2 bits with possible values 0, 1, 2 or 3).
@param scoreType The default HARRIS_SCORE means that Harris algorithm is used to rank features
(the score is written to KeyPoint::score and is used to retain best nfeatures features);
FAST_SCORE is alternative value of the parameter that produces slightly less stable keypoints,
but it is a little faster to compute.
@param patchSize size of the patch used by the oriented BRIEF descriptor. Of course, on smaller
pyramid layers the perceived image area covered by a feature will be larger.
@param fastThreshold the fast threshold
*/
CV_WRAP static Ptr<ORB> create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31,
int firstLevel=0, int WTA_K=2, ORB::ScoreType scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20);
CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
CV_WRAP virtual int getMaxFeatures() const = 0;
CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0;
CV_WRAP virtual double getScaleFactor() const = 0;
CV_WRAP virtual void setNLevels(int nlevels) = 0;
CV_WRAP virtual int getNLevels() const = 0;
CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0;
CV_WRAP virtual int getEdgeThreshold() const = 0;
CV_WRAP virtual void setFirstLevel(int firstLevel) = 0;
CV_WRAP virtual int getFirstLevel() const = 0;
CV_WRAP virtual void setWTA_K(int wta_k) = 0;
CV_WRAP virtual int getWTA_K() const = 0;
CV_WRAP virtual void setScoreType(ORB::ScoreType scoreType) = 0;
CV_WRAP virtual ORB::ScoreType getScoreType() const = 0;
CV_WRAP virtual void setPatchSize(int patchSize) = 0;
CV_WRAP virtual int getPatchSize() const = 0;
CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0;
CV_WRAP virtual int getFastThreshold() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
};
/** @brief Maximally stable extremal region extractor
The class encapsulates all the parameters of the %MSER extraction algorithm (see [wiki
article](http://en.wikipedia.org/wiki/Maximally_stable_extremal_regions)).
- there are two different implementation of %MSER: one for grey image, one for color image
- the grey image algorithm is taken from: @cite nister2008linear ; the paper claims to be faster
than union-find method; it actually get 1.5~2m/s on my centrino L7200 1.2GHz laptop.
- the color image algorithm is taken from: @cite forssen2007maximally ; it should be much slower
than grey image method ( 3~4 times )
- (Python) A complete example showing the use of the %MSER detector can be found at samples/python/mser.py
*/
class CV_EXPORTS_W MSER : public Feature2D
{
public:
/** @brief Full constructor for %MSER detector
@param delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$
@param min_area prune the area which smaller than minArea
@param max_area prune the area which bigger than maxArea
@param max_variation prune the area have similar size to its children
@param min_diversity for color image, trace back to cut off mser with diversity less than min_diversity
@param max_evolution for color image, the evolution steps
@param area_threshold for color image, the area threshold to cause re-initialize
@param min_margin for color image, ignore too small margin
@param edge_blur_size for color image, the aperture size for edge blur
*/
CV_WRAP static Ptr<MSER> create( int delta=5, int min_area=60, int max_area=14400,
double max_variation=0.25, double min_diversity=.2,
int max_evolution=200, double area_threshold=1.01,
double min_margin=0.003, int edge_blur_size=5 );
/** @brief Detect %MSER regions
@param image input image (8UC1, 8UC3 or 8UC4, must be greater or equal than 3x3)
@param msers resulting list of point sets
@param bboxes resulting bounding boxes
*/
CV_WRAP virtual void detectRegions( InputArray image,
CV_OUT std::vector<std::vector<Point> >& msers,
CV_OUT std::vector<Rect>& bboxes ) = 0;
CV_WRAP virtual void setDelta(int delta) = 0;
CV_WRAP virtual int getDelta() const = 0;
CV_WRAP virtual void setMinArea(int minArea) = 0;
CV_WRAP virtual int getMinArea() const = 0;
CV_WRAP virtual void setMaxArea(int maxArea) = 0;
CV_WRAP virtual int getMaxArea() const = 0;
CV_WRAP virtual void setMaxVariation(double maxVariation) = 0;
CV_WRAP virtual double getMaxVariation() const = 0;
CV_WRAP virtual void setMinDiversity(double minDiversity) = 0;
CV_WRAP virtual double getMinDiversity() const = 0;
CV_WRAP virtual void setMaxEvolution(int maxEvolution) = 0;
CV_WRAP virtual int getMaxEvolution() const = 0;
CV_WRAP virtual void setAreaThreshold(double areaThreshold) = 0;
CV_WRAP virtual double getAreaThreshold() const = 0;
CV_WRAP virtual void setMinMargin(double min_margin) = 0;
CV_WRAP virtual double getMinMargin() const = 0;
CV_WRAP virtual void setEdgeBlurSize(int edge_blur_size) = 0;
CV_WRAP virtual int getEdgeBlurSize() const = 0;
CV_WRAP virtual void setPass2Only(bool f) = 0;
CV_WRAP virtual bool getPass2Only() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
};
/** @brief Wrapping class for feature detection using the FAST method. :
*/
class CV_EXPORTS_W FastFeatureDetector : public Feature2D
{
public:
enum DetectorType
{
TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2
};
enum
{
THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002
};
CV_WRAP static Ptr<FastFeatureDetector> create( int threshold=10,
bool nonmaxSuppression=true,
FastFeatureDetector::DetectorType type=FastFeatureDetector::TYPE_9_16 );
CV_WRAP virtual void setThreshold(int threshold) = 0;
CV_WRAP virtual int getThreshold() const = 0;
CV_WRAP virtual void setNonmaxSuppression(bool f) = 0;
CV_WRAP virtual bool getNonmaxSuppression() const = 0;
CV_WRAP virtual void setType(FastFeatureDetector::DetectorType type) = 0;
CV_WRAP virtual FastFeatureDetector::DetectorType getType() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
};
/** @overload */
CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
int threshold, bool nonmaxSuppression=true );
/** @brief Detects corners using the FAST algorithm
@param image grayscale image where keypoints (corners) are detected.
@param keypoints keypoints detected on the image.
@param threshold threshold on difference between intensity of the central pixel and pixels of a
circle around this pixel.
@param nonmaxSuppression if true, non-maximum suppression is applied to detected corners
(keypoints).
@param type one of the three neighborhoods as defined in the paper:
FastFeatureDetector::TYPE_9_16, FastFeatureDetector::TYPE_7_12,
FastFeatureDetector::TYPE_5_8
Detects corners using the FAST algorithm by @cite Rosten06 .
@note In Python API, types are given as cv.FAST_FEATURE_DETECTOR_TYPE_5_8,
cv.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv.FAST_FEATURE_DETECTOR_TYPE_9_16. For corner
detection, use cv.FAST.detect() method.
*/
CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
int threshold, bool nonmaxSuppression, FastFeatureDetector::DetectorType type );
/** @brief Wrapping class for feature detection using the AGAST method. :
*/
class CV_EXPORTS_W AgastFeatureDetector : public Feature2D
{
public:
enum DetectorType
{
AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3,
};
enum
{
THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001,
};
CV_WRAP static Ptr<AgastFeatureDetector> create( int threshold=10,
bool nonmaxSuppression=true,
AgastFeatureDetector::DetectorType type = AgastFeatureDetector::OAST_9_16);
CV_WRAP virtual void setThreshold(int threshold) = 0;
CV_WRAP virtual int getThreshold() const = 0;
CV_WRAP virtual void setNonmaxSuppression(bool f) = 0;
CV_WRAP virtual bool getNonmaxSuppression() const = 0;
CV_WRAP virtual void setType(AgastFeatureDetector::DetectorType type) = 0;
CV_WRAP virtual AgastFeatureDetector::DetectorType getType() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
};
/** @overload */
CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
int threshold, bool nonmaxSuppression=true );
/** @brief Detects corners using the AGAST algorithm
@param image grayscale image where keypoints (corners) are detected.
@param keypoints keypoints detected on the image.
@param threshold threshold on difference between intensity of the central pixel and pixels of a
circle around this pixel.
@param nonmaxSuppression if true, non-maximum suppression is applied to detected corners
(keypoints).
@param type one of the four neighborhoods as defined in the paper:
AgastFeatureDetector::AGAST_5_8, AgastFeatureDetector::AGAST_7_12d,
AgastFeatureDetector::AGAST_7_12s, AgastFeatureDetector::OAST_9_16
For non-Intel platforms, there is a tree optimised variant of AGAST with same numerical results.
The 32-bit binary tree tables were generated automatically from original code using perl script.
The perl script and examples of tree generation are placed in features2d/doc folder.
Detects corners using the AGAST algorithm by @cite mair2010_agast .
*/
CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
int threshold, bool nonmaxSuppression, AgastFeatureDetector::DetectorType type );
/** @brief Wrapping class for feature detection using the goodFeaturesToTrack function. :
*/
class CV_EXPORTS_W GFTTDetector : public Feature2D
{
public:
CV_WRAP static Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,
int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
CV_WRAP static Ptr<GFTTDetector> create( int maxCorners, double qualityLevel, double minDistance,
int blockSize, int gradientSize, bool useHarrisDetector=false, double k=0.04 );
CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
CV_WRAP virtual int getMaxFeatures() const = 0;
CV_WRAP virtual void setQualityLevel(double qlevel) = 0;
CV_WRAP virtual double getQualityLevel() const = 0;
CV_WRAP virtual void setMinDistance(double minDistance) = 0;
CV_WRAP virtual double getMinDistance() const = 0;
CV_WRAP virtual void setBlockSize(int blockSize) = 0;
CV_WRAP virtual int getBlockSize() const = 0;
CV_WRAP virtual void setGradientSize(int gradientSize_) = 0;
CV_WRAP virtual int getGradientSize() = 0;
CV_WRAP virtual void setHarrisDetector(bool val) = 0;
CV_WRAP virtual bool getHarrisDetector() const = 0;
CV_WRAP virtual void setK(double k) = 0;
CV_WRAP virtual double getK() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
};
/** @brief Class for extracting blobs from an image. :
The class implements a simple algorithm for extracting blobs from an image:
1. Convert the source image to binary images by applying thresholding with several thresholds from
minThreshold (inclusive) to maxThreshold (exclusive) with distance thresholdStep between
neighboring thresholds.
2. Extract connected components from every binary image by findContours and calculate their
centers.
3. Group centers from several binary images by their coordinates. Close centers form one group that
corresponds to one blob, which is controlled by the minDistBetweenBlobs parameter.
4. From the groups, estimate final centers of blobs and their radiuses and return as locations and
sizes of keypoints.
This class performs several filtrations of returned blobs. You should set filterBy\* to true/false
to turn on/off corresponding filtration. Available filtrations:
- **By color**. This filter compares the intensity of a binary image at the center of a blob to
blobColor. If they differ, the blob is filtered out. Use blobColor = 0 to extract dark blobs
and blobColor = 255 to extract light blobs.
- **By area**. Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive).
- **By circularity**. Extracted blobs have circularity
(\f$\frac{4*\pi*Area}{perimeter * perimeter}\f$) between minCircularity (inclusive) and
maxCircularity (exclusive).
- **By ratio of the minimum inertia to maximum inertia**. Extracted blobs have this ratio
between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive).
- **By convexity**. Extracted blobs have convexity (area / area of blob convex hull) between
minConvexity (inclusive) and maxConvexity (exclusive).
Default values of parameters are tuned to extract dark circular blobs.
*/
class CV_EXPORTS_W SimpleBlobDetector : public Feature2D
{
public:
struct CV_EXPORTS_W_SIMPLE Params
{
CV_WRAP Params();
CV_PROP_RW float thresholdStep;
CV_PROP_RW float minThreshold;
CV_PROP_RW float maxThreshold;
CV_PROP_RW size_t minRepeatability;
CV_PROP_RW float minDistBetweenBlobs;
CV_PROP_RW bool filterByColor;
CV_PROP_RW uchar blobColor;
CV_PROP_RW bool filterByArea;
CV_PROP_RW float minArea, maxArea;
CV_PROP_RW bool filterByCircularity;
CV_PROP_RW float minCircularity, maxCircularity;
CV_PROP_RW bool filterByInertia;
CV_PROP_RW float minInertiaRatio, maxInertiaRatio;
CV_PROP_RW bool filterByConvexity;
CV_PROP_RW float minConvexity, maxConvexity;
/** @brief Flag to enable contour collection.
If set to true, the detector will store the contours of the detected blobs in memory,
which can be retrieved after the detect() call using getBlobContours().
@note Default value is false.
*/
CV_PROP_RW bool collectContours;
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
};
CV_WRAP static Ptr<SimpleBlobDetector>
create(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params());
CV_WRAP virtual void setParams(const SimpleBlobDetector::Params& params ) = 0;
CV_WRAP virtual SimpleBlobDetector::Params getParams() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
/** @brief Returns the contours of the blobs detected during the last call to detect().
@note The @ref Params::collectContours parameter must be set to true before calling
detect() for this method to return any data.
*/
CV_WRAP virtual const std::vector<std::vector<cv::Point> >& getBlobContours() const;
};
/** @brief Class implementing the KAZE keypoint detector and descriptor extractor, described in @cite ABD12 .
@note AKAZE descriptor can only be used with KAZE or AKAZE keypoints .. [ABD12] KAZE Features. Pablo
F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. In European Conference on Computer Vision
(ECCV), Fiorenze, Italy, October 2012.
*/
class CV_EXPORTS_W KAZE : public Feature2D
{
public:
enum DiffusivityType
{
DIFF_PM_G1 = 0,
DIFF_PM_G2 = 1,
DIFF_WEICKERT = 2,
DIFF_CHARBONNIER = 3
};
/** @brief The KAZE constructor
@param extended Set to enable extraction of extended (128-byte) descriptor.
@param upright Set to enable use of upright descriptors (non rotation-invariant).
@param threshold Detector response threshold to accept point
@param nOctaves Maximum octave evolution of the image
@param nOctaveLayers Default number of sublevels per scale level
@param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or
DIFF_CHARBONNIER
*/
CV_WRAP static Ptr<KAZE> create(bool extended=false, bool upright=false,
float threshold = 0.001f,
int nOctaves = 4, int nOctaveLayers = 4,
KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2);
CV_WRAP virtual void setExtended(bool extended) = 0;
CV_WRAP virtual bool getExtended() const = 0;
CV_WRAP virtual void setUpright(bool upright) = 0;
CV_WRAP virtual bool getUpright() const = 0;
CV_WRAP virtual void setThreshold(double threshold) = 0;
CV_WRAP virtual double getThreshold() const = 0;
CV_WRAP virtual void setNOctaves(int octaves) = 0;
CV_WRAP virtual int getNOctaves() const = 0;
CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
CV_WRAP virtual int getNOctaveLayers() const = 0;
CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0;
CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
};
/** @brief Class implementing the AKAZE keypoint detector and descriptor extractor, described in @cite ANB13.
@details AKAZE descriptors can only be used with KAZE or AKAZE keypoints. This class is thread-safe.
@note When you need descriptors use Feature2D::detectAndCompute, which
provides better performance. When using Feature2D::detect followed by
Feature2D::compute scale space pyramid is computed twice.
@note AKAZE implements T-API. When image is passed as UMat some parts of the algorithm
will use OpenCL.
@note [ANB13] Fast Explicit Diffusion for Accelerated Features in Nonlinear
Scale Spaces. Pablo F. Alcantarilla, Jesús Nuevo and Adrien Bartoli. In
British Machine Vision Conference (BMVC), Bristol, UK, September 2013.
*/
class CV_EXPORTS_W AKAZE : public Feature2D
{
public:
// AKAZE descriptor type
enum DescriptorType
{
DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation
DESCRIPTOR_KAZE = 3,
DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation
DESCRIPTOR_MLDB = 5
};
/** @brief The AKAZE constructor
@param descriptor_type Type of the extracted descriptor: DESCRIPTOR_KAZE,
DESCRIPTOR_KAZE_UPRIGHT, DESCRIPTOR_MLDB or DESCRIPTOR_MLDB_UPRIGHT.
@param descriptor_size Size of the descriptor in bits. 0 -\> Full size
@param descriptor_channels Number of channels in the descriptor (1, 2, 3)
@param threshold Detector response threshold to accept point
@param nOctaves Maximum octave evolution of the image
@param nOctaveLayers Default number of sublevels per scale level
@param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or
DIFF_CHARBONNIER
@param max_points Maximum amount of returned points. In case if image contains
more features, then the features with highest response are returned.
Negative value means no limitation.
*/
CV_WRAP static Ptr<AKAZE> create(AKAZE::DescriptorType descriptor_type = AKAZE::DESCRIPTOR_MLDB,
int descriptor_size = 0, int descriptor_channels = 3,
float threshold = 0.001f, int nOctaves = 4,
int nOctaveLayers = 4, KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2,
int max_points = -1);
CV_WRAP virtual void setDescriptorType(AKAZE::DescriptorType dtype) = 0;
CV_WRAP virtual AKAZE::DescriptorType getDescriptorType() const = 0;
CV_WRAP virtual void setDescriptorSize(int dsize) = 0;
CV_WRAP virtual int getDescriptorSize() const = 0;
CV_WRAP virtual void setDescriptorChannels(int dch) = 0;
CV_WRAP virtual int getDescriptorChannels() const = 0;
CV_WRAP virtual void setThreshold(double threshold) = 0;
CV_WRAP virtual double getThreshold() const = 0;
CV_WRAP virtual void setNOctaves(int octaves) = 0;
CV_WRAP virtual int getNOctaves() const = 0;
CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
CV_WRAP virtual int getNOctaveLayers() const = 0;
CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0;
CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0;
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
CV_WRAP virtual void setMaxPoints(int max_points) = 0;
CV_WRAP virtual int getMaxPoints() const = 0;
};
/****************************************************************************************\
* Distance *
\****************************************************************************************/
template<typename T>
struct CV_EXPORTS Accumulator
{
typedef T Type;
};
template<> struct Accumulator<unsigned char> { typedef float Type; };
template<> struct Accumulator<unsigned short> { typedef float Type; };
template<> struct Accumulator<char> { typedef float Type; };
template<> struct Accumulator<short> { typedef float Type; };
/*
* Squared Euclidean distance functor
*/
template<class T>
struct CV_EXPORTS SL2
{
static const NormTypes normType = NORM_L2SQR;
typedef T ValueType;
typedef typename Accumulator<T>::Type ResultType;
ResultType operator()( const T* a, const T* b, int size ) const
{
return normL2Sqr<ValueType, ResultType>(a, b, size);
}
};
/*
* Euclidean distance functor
*/
template<class T>
struct L2
{
static const NormTypes normType = NORM_L2;
typedef T ValueType;
typedef typename Accumulator<T>::Type ResultType;
ResultType operator()( const T* a, const T* b, int size ) const
{
return (ResultType)std::sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size));
}
};
/*
* Manhattan distance (city block distance) functor
*/
template<class T>
struct L1
{
static const NormTypes normType = NORM_L1;
typedef T ValueType;
typedef typename Accumulator<T>::Type ResultType;
ResultType operator()( const T* a, const T* b, int size ) const
{
return normL1<ValueType, ResultType>(a, b, size);
}
};
//! @} features2d_main
/****************************************************************************************\
* DescriptorMatcher *
\****************************************************************************************/
//! @addtogroup features2d_match
//! @{
/** @brief Abstract base class for matching keypoint descriptors.
It has two groups of match methods: for matching descriptors of an image with another image or with