OpenCV 4.5.3(日本語機械翻訳)
features2d.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #ifndef OPENCV_FEATURES_2D_HPP
44 #define OPENCV_FEATURES_2D_HPP
45
46 #include "opencv2/opencv_modules.hpp"
47 #include "opencv2/core.hpp"
48
49 #ifdef HAVE_OPENCV_FLANN
50 #include "opencv2/flann/miniflann.hpp"
51 #endif
52
76 namespace cv
77{
78
81
82 // //! writes vector of keypoints to the file storage
83 // CV_EXPORTS void write(FileStorage& fs, const String& name, const std::vector<KeyPoint>& keypoints);
84 // //! reads vector of keypoints from the specified file storage node
85 // CV_EXPORTS void read(const FileNode& node, CV_OUT std::vector<KeyPoint>& keypoints);
86
92 class CV_EXPORTS KeyPointsFilter
93{
94 public:
96
97 /*
98 * Remove keypoints within borderPixels of an image edge.
99 */
100 static void runByImageBorder( std::vector<KeyPoint>& keypoints, Size imageSize, int borderSize );
101 /*
102 * Remove keypoints of sizes out of range.
103 */
104 static void runByKeypointSize( std::vector<KeyPoint>& keypoints, float minSize,
105 float maxSize=FLT_MAX );
106 /*
107 * Remove keypoints from some image by mask for pixels of this image.
108 */
109 static void runByPixelsMask( std::vector<KeyPoint>& keypoints, const Mat& mask );
110 /*
111 * Remove duplicated keypoints.
112 */
113 static void removeDuplicated( std::vector<KeyPoint>& keypoints );
114 /*
115 * Remove duplicated keypoints and sort the remaining keypoints
116 */
117 static void removeDuplicatedSorted( std::vector<KeyPoint>& keypoints );
118
119 /*
120 * Retain the specified number of the best keypoints (according to the response)
121 */
122 static void retainBest( std::vector<KeyPoint>& keypoints, int npoints );
123};
124
125
126 /************************************ Base Classes ************************************/
127
130 #ifdef __EMSCRIPTEN__
131 class CV_EXPORTS_W Feature2D : public Algorithm
132 #else
133 class CV_EXPORTS_W Feature2D : public virtual Algorithm
134 #endif
135{
136 public:
137 virtual ~Feature2D();
138
147 CV_WRAP virtual void detect( InputArray image,
148 CV_OUT std::vector<KeyPoint>& keypoints,
149 InputArray mask=noArray() );
150
158 CV_WRAP virtual void detect( InputArrayOfArrays images,
159 CV_OUT std::vector<std::vector<KeyPoint> >& keypoints,
160 InputArrayOfArrays masks=noArray() );
161
173 CV_WRAP virtual void compute( InputArray image,
174 CV_OUT CV_IN_OUT std::vector<KeyPoint>& keypoints,
175 OutputArray descriptors );
176
187 CV_WRAP virtual void compute( InputArrayOfArrays images,
188 CV_OUT CV_IN_OUT std::vector<std::vector<KeyPoint> >& keypoints,
189 OutputArrayOfArrays descriptors );
190
192 CV_WRAP virtual void detectAndCompute( InputArray image, InputArray mask,
193 CV_OUT std::vector<KeyPoint>& keypoints,
194 OutputArray descriptors,
195 bool useProvidedKeypoints=false );
196
197 CV_WRAP virtual int descriptorSize() const;
198 CV_WRAP virtual int descriptorType() const;
199 CV_WRAP virtual int defaultNorm() const;
200
201 CV_WRAP void write( const String& fileName ) const;
202
203 CV_WRAP void read( const String& fileName );
204
205 virtual void write( FileStorage&) const CV_OVERRIDE;
206
207 // see corresponding cv::Algorithm method
208 CV_WRAP virtual void read( const FileNode&) CV_OVERRIDE;
209
211 CV_WRAP virtual bool empty() const CV_OVERRIDE;
212 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
213
214 // see corresponding cv::Algorithm method
215 CV_WRAP inline void write(const Ptr<FileStorage>& fs, const String& name = String()) const { Algorithm::write(fs, name); }
216};
217
222
229
230
234 class CV_EXPORTS_W AffineFeature : public Feature2D
235{
236 public:
244 CV_WRAP static Ptr<AffineFeature> create(const Ptr<Feature2D>& backend,
245 int maxTilt = 5, int minTilt = 0, float tiltStep = 1.4142135623730951f, float rotateStepBase = 72);
246
247 CV_WRAP virtual void setViewParams(const std::vector<float>& tilts, const std::vector<float>& rolls) = 0;
248 CV_WRAP virtual void getViewParams(std::vector<float>& tilts, std::vector<float>& rolls) const = 0;
249 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
250};
251
254
255
259 class CV_EXPORTS_W SIFT : public Feature2D
260{
261 public:
283 CV_WRAP static Ptr<SIFT> create(int nfeatures = 0, int nOctaveLayers = 3,
284 double contrastThreshold = 0.04, double edgeThreshold = 10,
285 double sigma = 1.6);
286
310 CV_WRAP static Ptr<SIFT> create(int nfeatures, int nOctaveLayers,
311 double contrastThreshold, double edgeThreshold,
312 double sigma, int descriptorType);
313
314 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
315};
316
319
320
323 class CV_EXPORTS_W BRISK : public Feature2D
324{
325 public:
333 CV_WRAP static Ptr<BRISK> create(int thresh=30, int octaves=3, float patternScale=1.0f);
334
346 CV_WRAP static Ptr<BRISK> create(const std::vector<float> &radiusList, const std::vector<int> &numberList,
347 float dMax=5.85f, float dMin=8.2f, const std::vector<int>& indexChange=std::vector<int>());
348
362 CV_WRAP static Ptr<BRISK> create(int thresh, int octaves, const std::vector<float> &radiusList,
363 const std::vector<int> &numberList, float dMax=5.85f, float dMin=8.2f,
364 const std::vector<int>& indexChange=std::vector<int>());
365 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
366
370 CV_WRAP virtual void setThreshold(int threshold) { CV_UNUSED(threshold); return; }
371 CV_WRAP virtual int getThreshold() const { return -1; }
372
376 CV_WRAP virtual void setOctaves(int octaves) { CV_UNUSED(octaves); return; }
377 CV_WRAP virtual int getOctaves() const { return -1; }
378};
379
387 class CV_EXPORTS_W ORB : public Feature2D
388{
389 public:
390 enum ScoreType { HARRIS_SCORE=0, FAST_SCORE=1 };
391 static const int kBytes = 32;
392
424 CV_WRAP static Ptr<ORB> create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31,
425 int firstLevel=0, int WTA_K=2, ORB::ScoreType scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20);
426
427 CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
428 CV_WRAP virtual int getMaxFeatures() const = 0;
429
430 CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0;
431 CV_WRAP virtual double getScaleFactor() const = 0;
432
433 CV_WRAP virtual void setNLevels(int nlevels) = 0;
434 CV_WRAP virtual int getNLevels() const = 0;
435
436 CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0;
437 CV_WRAP virtual int getEdgeThreshold() const = 0;
438
439 CV_WRAP virtual void setFirstLevel(int firstLevel) = 0;
440 CV_WRAP virtual int getFirstLevel() const = 0;
441
442 CV_WRAP virtual void setWTA_K(int wta_k) = 0;
443 CV_WRAP virtual int getWTA_K() const = 0;
444
445 CV_WRAP virtual void setScoreType(ORB::ScoreType scoreType) = 0;
446 CV_WRAP virtual ORB::ScoreType getScoreType() const = 0;
447
448 CV_WRAP virtual void setPatchSize(int patchSize) = 0;
449 CV_WRAP virtual int getPatchSize() const = 0;
450
451 CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0;
452 CV_WRAP virtual int getFastThreshold() const = 0;
453 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
454};
455
471 class CV_EXPORTS_W MSER : public Feature2D
472{
473 public:
486 CV_WRAP static Ptr<MSER> create( int delta=5, int min_area=60, int max_area=14400,
487 double max_variation=0.25, double min_diversity=.2,
488 int max_evolution=200, double area_threshold=1.01,
489 double min_margin=0.003, int edge_blur_size=5 );
490
497 CV_WRAP virtual void detectRegions( InputArray image,
498 CV_OUT std::vector<std::vector<Point> >& msers,
499 CV_OUT std::vector<Rect>& bboxes ) = 0;
500
501 CV_WRAP virtual void setDelta(int delta) = 0;
502 CV_WRAP virtual int getDelta() const = 0;
503
504 CV_WRAP virtual void setMinArea(int minArea) = 0;
505 CV_WRAP virtual int getMinArea() const = 0;
506
507 CV_WRAP virtual void setMaxArea(int maxArea) = 0;
508 CV_WRAP virtual int getMaxArea() const = 0;
509
510 CV_WRAP virtual void setPass2Only(bool f) = 0;
511 CV_WRAP virtual bool getPass2Only() const = 0;
512 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
513};
514
516
519
522 class CV_EXPORTS_W FastFeatureDetector : public Feature2D
523{
524 public:
525 enum DetectorType
526 {
527 TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2
528 };
529 enum
530 {
531 THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002
532 };
533
534
535 CV_WRAP static Ptr<FastFeatureDetector> create( int threshold=10,
536 bool nonmaxSuppression=true,
537 FastFeatureDetector::DetectorType type=FastFeatureDetector::TYPE_9_16 );
538
539 CV_WRAP virtual void setThreshold(int threshold) = 0;
540 CV_WRAP virtual int getThreshold() const = 0;
541
542 CV_WRAP virtual void setNonmaxSuppression(bool f) = 0;
543 CV_WRAP virtual bool getNonmaxSuppression() const = 0;
544
545 CV_WRAP virtual void setType(FastFeatureDetector::DetectorType type) = 0;
546 CV_WRAP virtual FastFeatureDetector::DetectorType getType() const = 0;
547 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
548};
549
551 CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
552 int threshold, bool nonmaxSuppression=true );
553
572 CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
573 int threshold, bool nonmaxSuppression, FastFeatureDetector::DetectorType type );
574
576
579
582 class CV_EXPORTS_W AgastFeatureDetector : public Feature2D
583{
584 public:
585 enum DetectorType
586 {
587 AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3,
588 };
589
590 enum
591 {
592 THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001,
593 };
594
595 CV_WRAP static Ptr<AgastFeatureDetector> create( int threshold=10,
596 bool nonmaxSuppression=true,
597 AgastFeatureDetector::DetectorType type = AgastFeatureDetector::OAST_9_16);
598
599 CV_WRAP virtual void setThreshold(int threshold) = 0;
600 CV_WRAP virtual int getThreshold() const = 0;
601
602 CV_WRAP virtual void setNonmaxSuppression(bool f) = 0;
603 CV_WRAP virtual bool getNonmaxSuppression() const = 0;
604
605 CV_WRAP virtual void setType(AgastFeatureDetector::DetectorType type) = 0;
606 CV_WRAP virtual AgastFeatureDetector::DetectorType getType() const = 0;
607 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
608};
609
611 CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
612 int threshold, bool nonmaxSuppression=true );
613
632 CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
633 int threshold, bool nonmaxSuppression, AgastFeatureDetector::DetectorType type );
634
637 class CV_EXPORTS_W GFTTDetector : public Feature2D
638{
639 public:
640 CV_WRAP static Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,
641 int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
642 CV_WRAP static Ptr<GFTTDetector> create( int maxCorners, double qualityLevel, double minDistance,
643 int blockSize, int gradiantSize, bool useHarrisDetector=false, double k=0.04 );
644 CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
645 CV_WRAP virtual int getMaxFeatures() const = 0;
646
647 CV_WRAP virtual void setQualityLevel(double qlevel) = 0;
648 CV_WRAP virtual double getQualityLevel() const = 0;
649
650 CV_WRAP virtual void setMinDistance(double minDistance) = 0;
651 CV_WRAP virtual double getMinDistance() const = 0;
652
653 CV_WRAP virtual void setBlockSize(int blockSize) = 0;
654 CV_WRAP virtual int getBlockSize() const = 0;
655
656 CV_WRAP virtual void setHarrisDetector(bool val) = 0;
657 CV_WRAP virtual bool getHarrisDetector() const = 0;
658
659 CV_WRAP virtual void setK(double k) = 0;
660 CV_WRAP virtual double getK() const = 0;
661 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
662};
663
695 class CV_EXPORTS_W SimpleBlobDetector : public Feature2D
696{
697 public:
698 struct CV_EXPORTS_W_SIMPLE Params
699 {
700 CV_WRAP Params();
701 CV_PROP_RW float thresholdStep;
702 CV_PROP_RW float minThreshold;
703 CV_PROP_RW float maxThreshold;
704 CV_PROP_RW size_t minRepeatability;
705 CV_PROP_RW float minDistBetweenBlobs;
706
707 CV_PROP_RW bool filterByColor;
708 CV_PROP_RW uchar blobColor;
709
710 CV_PROP_RW bool filterByArea;
711 CV_PROP_RW float minArea, maxArea;
712
713 CV_PROP_RW bool filterByCircularity;
714 CV_PROP_RW float minCircularity, maxCircularity;
715
716 CV_PROP_RW bool filterByInertia;
717 CV_PROP_RW float minInertiaRatio, maxInertiaRatio;
718
719 CV_PROP_RW bool filterByConvexity;
720 CV_PROP_RW float minConvexity, maxConvexity;
721
722 void read( const FileNode& fn );
723 void write( FileStorage& fs ) const;
724 };
725
726 CV_WRAP static Ptr<SimpleBlobDetector>
727 create(const SimpleBlobDetector::Params &parameters = SimpleBlobDetector::Params());
728 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
729};
730
732
735
742 class CV_EXPORTS_W KAZE : public Feature2D
743{
744 public:
745 enum DiffusivityType
746 {
747 DIFF_PM_G1 = 0,
748 DIFF_PM_G2 = 1,
749 DIFF_WEICKERT = 2,
750 DIFF_CHARBONNIER = 3
751 };
752
763 CV_WRAP static Ptr<KAZE> create(bool extended=false, bool upright=false,
764 float threshold = 0.001f,
765 int nOctaves = 4, int nOctaveLayers = 4,
766 KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2);
767
768 CV_WRAP virtual void setExtended(bool extended) = 0;
769 CV_WRAP virtual bool getExtended() const = 0;
770
771 CV_WRAP virtual void setUpright(bool upright) = 0;
772 CV_WRAP virtual bool getUpright() const = 0;
773
774 CV_WRAP virtual void setThreshold(double threshold) = 0;
775 CV_WRAP virtual double getThreshold() const = 0;
776
777 CV_WRAP virtual void setNOctaves(int octaves) = 0;
778 CV_WRAP virtual int getNOctaves() const = 0;
779
780 CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
781 CV_WRAP virtual int getNOctaveLayers() const = 0;
782
783 CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0;
784 CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0;
785 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
786};
787
804 class CV_EXPORTS_W AKAZE : public Feature2D
805{
806 public:
807 // AKAZE descriptor type
809 {
810 DESCRIPTOR_KAZE_UPRIGHT = 2,
811 DESCRIPTOR_KAZE = 3,
812 DESCRIPTOR_MLDB_UPRIGHT = 4,
813 DESCRIPTOR_MLDB = 5
814 };
815
828 CV_WRAP static Ptr<AKAZE> create(AKAZE::DescriptorType descriptor_type = AKAZE::DESCRIPTOR_MLDB,
829 int descriptor_size = 0, int descriptor_channels = 3,
830 float threshold = 0.001f, int nOctaves = 4,
831 int nOctaveLayers = 4, KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2);
832
833 CV_WRAP virtual void setDescriptorType(AKAZE::DescriptorType dtype) = 0;
834 CV_WRAP virtual AKAZE::DescriptorType getDescriptorType() const = 0;
835
836 CV_WRAP virtual void setDescriptorSize(int dsize) = 0;
837 CV_WRAP virtual int getDescriptorSize() const = 0;
838
839 CV_WRAP virtual void setDescriptorChannels(int dch) = 0;
840 CV_WRAP virtual int getDescriptorChannels() const = 0;
841
842 CV_WRAP virtual void setThreshold(double threshold) = 0;
843 CV_WRAP virtual double getThreshold() const = 0;
844
845 CV_WRAP virtual void setNOctaves(int octaves) = 0;
846 CV_WRAP virtual int getNOctaves() const = 0;
847
848 CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
849 CV_WRAP virtual int getNOctaveLayers() const = 0;
850
851 CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0;
852 CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0;
853 CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
854};
855
857
858 /****************************************************************************************\
859 * Distance *
860 \****************************************************************************************/
861
862template<typename T>
863 struct CV_EXPORTS Accumulator
864{
865 typedef T Type;
866};
867
868 template<> struct Accumulator<unsigned char> { typedef float Type; };
869 template<> struct Accumulator<unsigned short> { typedef float Type; };
870 template<> struct Accumulator<char> { typedef float Type; };
871 template<> struct Accumulator<short> { typedef float Type; };
872
873 /*
874 * Squared Euclidean distance functor
875 */
876 template<class T>
877 struct CV_EXPORTS SL2
878{
879 static const NormTypes normType = NORM_L2SQR;
880 typedef T ValueType;
881 typedef typename Accumulator<T>::Type ResultType;
882
883 ResultType operator()( const T* a, const T* b, int size ) const
884 {
885 return normL2Sqr<ValueType, ResultType>(a, b, size);
886 }
887};
888
889 /*
890 * Euclidean distance functor
891 */
892 template<class T>
893 struct L2
894{
895 static const NormTypes normType = NORM_L2;
896 typedef T ValueType;
897 typedef typename Accumulator<T>::Type ResultType;
898
899 ResultType operator()( const T* a, const T* b, int size ) const
900 {
901 return (ResultType)std::sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size));
902 }
903};
904
905 /*
906 * Manhattan distance (city block distance) functor
907 */
908 template<class T>
909 struct L1
910{
911 static const NormTypes normType = NORM_L1;
912 typedef T ValueType;
913 typedef typename Accumulator<T>::Type ResultType;
914
915 ResultType operator()( const T* a, const T* b, int size ) const
916 {
917 return normL1<ValueType, ResultType>(a, b, size);
918 }
919};
920
921 /****************************************************************************************\
922 * DescriptorMatcher *
923 \****************************************************************************************/
924
927
933 class CV_EXPORTS_W DescriptorMatcher : public Algorithm
934{
935 public:
936 enum MatcherType
937 {
938 FLANNBASED = 1,
939 BRUTEFORCE = 2,
940 BRUTEFORCE_L1 = 3,
941 BRUTEFORCE_HAMMING = 4,
942 BRUTEFORCE_HAMMINGLUT = 5,
943 BRUTEFORCE_SL2 = 6
944 };
945
946 virtual ~DescriptorMatcher();
947
956 CV_WRAP virtual void add( InputArrayOfArrays descriptors );
957
960 CV_WRAP const std::vector<Mat>& getTrainDescriptors() const;
961
964 CV_WRAP virtual void clear() CV_OVERRIDE;
965
968 CV_WRAP virtual bool empty() const CV_OVERRIDE;
969
972 CV_WRAP virtual bool isMaskSupported() const = 0;
973
981 CV_WRAP virtual void train();
982
999 CV_WRAP void match( InputArray queryDescriptors, InputArray trainDescriptors,
1000 CV_OUT std::vector<DMatch>& matches, InputArray mask=noArray() ) const;
1001
1020 CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors,
1021 CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
1022 InputArray mask=noArray(), bool compactResult=false ) const;
1023
1043 CV_WRAP void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors,
1044 CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance,
1045 InputArray mask=noArray(), bool compactResult=false ) const;
1046
1054 CV_WRAP void match( InputArray queryDescriptors, CV_OUT std::vector<DMatch>& matches,
1055 InputArrayOfArrays masks=noArray() );
1067 CV_WRAP void knnMatch( InputArray queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
1068 InputArrayOfArrays masks=noArray(), bool compactResult=false );
1081 CV_WRAP void radiusMatch( InputArray queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, float maxDistance,
1082 InputArrayOfArrays masks=noArray(), bool compactResult=false );
1083
1084
1085 CV_WRAP void write( const String& fileName ) const
1086 {
1087 FileStorage fs(fileName, FileStorage::WRITE);
1088 write(fs);
1089 }
1090
1091 CV_WRAP void read( const String& fileName )
1092 {
1093 FileStorage fs(fileName, FileStorage::READ);
1094 read(fs.root());
1095 }
1096 // Reads matcher object from a file node
1097 // see corresponding cv::Algorithm method
1098 CV_WRAP virtual void read( const FileNode& ) CV_OVERRIDE;
1099 // Writes matcher object to a file storage
1100 virtual void write( FileStorage& ) const CV_OVERRIDE;
1101
1108 CV_WRAP virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const = 0;
1109
1121 CV_WRAP static Ptr<DescriptorMatcher> create( const String& descriptorMatcherType );
1122
1123 CV_WRAP static Ptr<DescriptorMatcher> create( const DescriptorMatcher::MatcherType& matcherType );
1124
1125
1126 // see corresponding cv::Algorithm method
1127 CV_WRAP inline void write(const Ptr<FileStorage>& fs, const String& name = String()) const { Algorithm::write(fs, name); }
1128
1129 protected:
1134 class CV_EXPORTS DescriptorCollection
1135 {
1136 public:
1138 DescriptorCollection( const DescriptorCollection& collection );
1139 virtual ~DescriptorCollection();
1140
1141 // Vector of matrices "descriptors" will be merged to one matrix "mergedDescriptors" here.
1142 void set( const std::vector<Mat>& descriptors );
1143 virtual void clear();
1144
1145 const Mat& getDescriptors() const;
1146 const Mat getDescriptor( int imgIdx, int localDescIdx ) const;
1147 const Mat getDescriptor( int globalDescIdx ) const;
1148 void getLocalIdx( int globalDescIdx, int& imgIdx, int& localDescIdx ) const;
1149
1150 int size() const;
1151
1152 protected:
1153 Mat mergedDescriptors;
1154 std::vector<int> startIdxs;
1155 };
1156
1160 virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
1161 InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
1162 virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
1163 InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
1164
1165 static bool isPossibleMatch( InputArray mask, int queryIdx, int trainIdx );
1166 static bool isMaskedOut( InputArrayOfArrays masks, int queryIdx );
1167
1168 static Mat clone_op( Mat m ) { return m.clone(); }
1169 void checkMasks( InputArrayOfArrays masks, int queryDescriptorsCount ) const;
1170
1172 std::vector<Mat> trainDescCollection;
1173 std::vector<UMat> utrainDescCollection;
1174};
1175
1182 class CV_EXPORTS_W BFMatcher : public DescriptorMatcher
1183{
1184 public:
1189 CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false );
1190
1191 virtual ~BFMatcher() {}
1192
1193 virtual bool isMaskSupported() const CV_OVERRIDE { return true; }
1194
1207 CV_WRAP static Ptr<BFMatcher> create( int normType=NORM_L2, bool crossCheck=false ) ;
1208
1209 virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const CV_OVERRIDE;
1210protected:
1211 virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
1212 InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE;
1213 virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
1214 InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE;
1215
1216 int normType;
1217 bool crossCheck;
1218};
1219
1220 #if defined(HAVE_OPENCV_FLANN) || defined(CV_DOXYGEN)
1221
1229 class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
1230{
1231 public:
1232 CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(),
1233 const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() );
1234
1235 virtual void add( InputArrayOfArrays descriptors ) CV_OVERRIDE;
1236 virtual void clear() CV_OVERRIDE;
1237
1238 // Reads matcher object from a file node
1239 virtual void read( const FileNode& ) CV_OVERRIDE;
1240 // Writes matcher object to a file storage
1241 virtual void write( FileStorage& ) const CV_OVERRIDE;
1242
1243 virtual void train() CV_OVERRIDE;
1244 virtual bool isMaskSupported() const CV_OVERRIDE;
1245
1246 CV_WRAP static Ptr<FlannBasedMatcher> create();
1247
1248 virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const CV_OVERRIDE;
1249 protected:
1250 static void convertToDMatches( const DescriptorCollection& descriptors,
1251 const Mat& indices, const Mat& distances,
1252 std::vector<std::vector<DMatch> >& matches );
1253
1254 virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
1255 InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE;
1256 virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
1257 InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE;
1258
1259 Ptr<flann::IndexParams> indexParams;
1260 Ptr<flann::SearchParams> searchParams;
1261 Ptr<flann::Index> flannIndex;
1262
1263 DescriptorCollection mergedDescriptors;
1264 int addedDescCount;
1265};
1266
1267 #endif
1268
1270
1271 /****************************************************************************************\
1272 * Drawing functions *
1273 \****************************************************************************************/
1274
1277
1278 enum struct DrawMatchesFlags
1279{
1280 DEFAULT = 0,
1285 DRAW_OVER_OUTIMG = 1,
1290};
1291CV_ENUM_FLAGS(DrawMatchesFlags)
1292
1293
1308 CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage,
1309 const Scalar& color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT );
1310
1333 CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1,
1334 InputArray img2, const std::vector<KeyPoint>& keypoints2,
1335 const std::vector<DMatch>& matches1to2, InputOutputArray outImg,
1336 const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
1337 const std::vector<char>& matchesMask=std::vector<char>(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT );
1338
1340 CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1,
1341 InputArray img2, const std::vector<KeyPoint>& keypoints2,
1342 const std::vector<DMatch>& matches1to2, InputOutputArray outImg,
1343 const int matchesThickness, const Scalar& matchColor=Scalar::all(-1),
1344 const Scalar& singlePointColor=Scalar::all(-1), const std::vector<char>& matchesMask=std::vector<char>(),
1345 DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT );
1346
1347 CV_EXPORTS_AS(drawMatchesKnn) void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1,
1348 InputArray img2, const std::vector<KeyPoint>& keypoints2,
1349 const std::vector<std::vector<DMatch> >& matches1to2, InputOutputArray outImg,
1350 const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
1351 const std::vector<std::vector<char> >& matchesMask=std::vector<std::vector<char> >(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT );
1352
1354
1355 /****************************************************************************************\
1356 * Functions to evaluate the feature detectors and [generic] descriptor extractors *
1357 \****************************************************************************************/
1358
1359CV_EXPORTS void evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H1to2,
1360 std::vector<KeyPoint>* keypoints1, std::vector<KeyPoint>* keypoints2,
1361 float& repeatability, int& correspCount,
1362 const Ptr<FeatureDetector>& fdetector=Ptr<FeatureDetector>() );
1363
1364CV_EXPORTS void computeRecallPrecisionCurve( const std::vector<std::vector<DMatch> >& matches1to2,
1365 const std::vector<std::vector<uchar> >& correctMatches1to2Mask,
1366 std::vector<Point2f>& recallPrecisionCurve );
1367
1368CV_EXPORTS float getRecall( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
1369CV_EXPORTS int getNearestPoint( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
1370
1371 /****************************************************************************************\
1372 * Bag of visual words *
1373 \****************************************************************************************/
1374
1377
1383 class CV_EXPORTS_W BOWTrainer
1384{
1385 public:
1386 BOWTrainer();
1387 virtual ~BOWTrainer();
1388
1396 CV_WRAP void add( const Mat& descriptors );
1397
1400 CV_WRAP const std::vector<Mat>& getDescriptors() const;
1401
1404 CV_WRAP int descriptorsCount() const;
1405
1406 CV_WRAP virtual void clear();
1407
1409 CV_WRAP virtual Mat cluster() const = 0;
1410
1420 CV_WRAP virtual Mat cluster( const Mat& descriptors ) const = 0;
1421
1422 protected:
1423 std::vector<Mat> descriptors;
1424 int size;
1425};
1426
1429 class CV_EXPORTS_W BOWKMeansTrainer : public BOWTrainer
1430{
1431 public:
1436 CV_WRAP BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(),
1437 int attempts=3, int flags=KMEANS_PP_CENTERS );
1438 virtual ~BOWKMeansTrainer();
1439
1440 // Returns trained vocabulary (i.e. cluster centers).
1441 CV_WRAP virtual Mat cluster() const CV_OVERRIDE;
1442 CV_WRAP virtual Mat cluster( const Mat& descriptors ) const CV_OVERRIDE;
1443
1444protected:
1445
1446 int clusterCount;
1447 TermCriteria termcrit;
1448 int attempts;
1449 int flags;
1450};
1451
1462 class CV_EXPORTS_W BOWImgDescriptorExtractor
1463{
1464 public:
1473 const Ptr<DescriptorMatcher>& dmatcher );
1477
1483 CV_WRAP void setVocabulary( const Mat& vocabulary );
1484
1487 CV_WRAP const Mat& getVocabulary() const;
1488
1499 void compute( InputArray image, std::vector<KeyPoint>& keypoints, OutputArray imgDescriptor,
1500 std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
1508 void compute( InputArray keypointDescriptors, OutputArray imgDescriptor,
1509 std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
1510 // compute() is not constant because DescriptorMatcher::match is not constant
1511
1512 CV_WRAP_AS(compute) void compute2( const Mat& image, std::vector<KeyPoint>& keypoints, CV_OUT Mat& imgDescriptor )
1513 { compute(image,keypoints,imgDescriptor); }
1514
1517 CV_WRAP int descriptorSize() const;
1518
1521 CV_WRAP int descriptorType() const;
1522
1523 protected:
1524 Mat vocabulary;
1525 Ptr<DescriptorExtractor> dextractor;
1526 Ptr<DescriptorMatcher> dmatcher;
1527};
1528
1530
1532
1533} /* namespace cv */
1534
1535 #endif
Definition: mat.hpp:386
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
Class implementing the AKAZE keypoint detector and descriptor extractor, described in .
Definition: features2d.hpp:805
DescriptorType
Definition: features2d.hpp:809
Class for implementing the wrapper which makes detectors and extractors to be affine invariant,...
Definition: features2d.hpp:235
Wrapping class for feature detection using the AGAST method. :
Definition: features2d.hpp:583
This is a base class for all more or less complex algorithms in OpenCV
Definition: core.hpp:3091
virtual void write(FileStorage &fs) const
Stores algorithm parameters in a file storage
Definition: core.hpp:3102
Brute-force descriptor matcher.
Definition: features2d.hpp:1183
virtual Ptr< DescriptorMatcher > clone(bool emptyTrainData=false) const CV_OVERRIDE
Clones the matcher.
virtual bool isMaskSupported() const CV_OVERRIDE
Returns true if the descriptor matcher supports masking permissible matches.
Definition: features2d.hpp:1193
Class to compute an image descriptor using the bag of visual words.
Definition: features2d.hpp:1463
BOWImgDescriptorExtractor(const Ptr< DescriptorMatcher > &dmatcher)
void compute(InputArray image, std::vector< KeyPoint > &keypoints, OutputArray imgDescriptor, std::vector< std::vector< int > > *pointIdxsOfClusters=0, Mat *descriptors=0)
Computes an image descriptor using the set visual vocabulary.
void compute(InputArray keypointDescriptors, OutputArray imgDescriptor, std::vector< std::vector< int > > *pointIdxsOfClusters=0)
kmeans -based class to train visual vocabulary using the bag of visual words approach....
Definition: features2d.hpp:1430
Abstract base class for training the bag of visual words vocabulary from a set of descriptors.
Definition: features2d.hpp:1384
Class implementing the BRISK keypoint detector and descriptor extractor, described in .
Definition: features2d.hpp:324
Class for matching keypoint descriptors
Definition: core/types.hpp:809
Definition: features2d.hpp:1135
Abstract base class for matching keypoint descriptors.
Definition: features2d.hpp:934
virtual void knnMatchImpl(InputArray queryDescriptors, std::vector< std::vector< DMatch > > &matches, int k, InputArrayOfArrays masks=noArray(), bool compactResult=false)=0
std::vector< Mat > trainDescCollection
Collection of descriptors from train images.
Definition: features2d.hpp:1172
virtual void write(FileStorage &) const CV_OVERRIDE
Stores algorithm parameters in a file storage
Wrapping class for feature detection using the FAST method. :
Definition: features2d.hpp:523
Abstract base class for 2D image feature detectors and descriptor extractors
Definition: features2d.hpp:135
virtual void write(FileStorage &) const CV_OVERRIDE
Stores algorithm parameters in a file storage
File Storage Node class.
Definition: persistence.hpp:482
XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or readi...
Definition: persistence.hpp:304
@ WRITE
value, open the file for writing
Definition: persistence.hpp:310
@ READ
value, open the file for reading
Definition: persistence.hpp:309
Wrapping class for feature detection using the goodFeaturesToTrack function. :
Definition: features2d.hpp:638
Class implementing the KAZE keypoint detector and descriptor extractor, described in .
Definition: features2d.hpp:743
Data structure for salient point detectors.
Definition: core/types.hpp:712
A class filters a vector of keypoints.
Definition: features2d.hpp:93
Maximally stable extremal region extractor
Definition: features2d.hpp:472
n-dimensional dense array class
Definition: mat.hpp:802
Mat clone() const CV_NODISCARD
Creates a full copy of the array and the underlying data.
Class implementing the ORB (oriented BRIEF) keypoint detector and descriptor extractor
Definition: features2d.hpp:388
Class for extracting keypoints and computing descriptors using the Scale Invariant Feature Transform ...
Definition: features2d.hpp:260
Class for extracting blobs from an image. :
Definition: features2d.hpp:696
Template class for specifying the size of an image or rectangle.
Definition: core/types.hpp:316
The class defining termination criteria for iterative algorithms.
Definition: core/types.hpp:853
CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera(InputArrayOfArrays objectPoints
Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern.
CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst)
Calculates a square root of array elements.
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1)
Calculates the per-element sum of two arrays or an array and a scalar.
NormTypes
Definition: base.hpp:159
@ NORM_L2
Definition: base.hpp:185
@ NORM_L1
Definition: base.hpp:176
@ NORM_L2SQR
Definition: base.hpp:194
@ KMEANS_PP_CENTERS
Definition: core.hpp:217
CV_EXPORTS_W void drawMatches(InputArray img1, const std::vector< KeyPoint > &keypoints1, InputArray img2, const std::vector< KeyPoint > &keypoints2, const std::vector< DMatch > &matches1to2, InputOutputArray outImg, const Scalar &matchColor=Scalar::all(-1), const Scalar &singlePointColor=Scalar::all(-1), const std::vector< char > &matchesMask=std::vector< char >(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT)
Draws the found matches of keypoints from two images.
DrawMatchesFlags
Definition: features2d.hpp:1279
CV_EXPORTS_W void drawKeypoints(InputArray image, const std::vector< KeyPoint > &keypoints, InputOutputArray outImage, const Scalar &color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT)
Draws keypoints.
@ NOT_DRAW_SINGLE_POINTS
Single keypoints will not be drawn.
Feature2D FeatureDetector
Definition: features2d.hpp:221
CV_EXPORTS void FAST(InputArray image, CV_OUT std::vector< KeyPoint > &keypoints, int threshold, bool nonmaxSuppression=true)
CV_EXPORTS void AGAST(InputArray image, CV_OUT std::vector< KeyPoint > &keypoints, int threshold, bool nonmaxSuppression=true)
Feature2D DescriptorExtractor
Definition: features2d.hpp:228
CV_EXPORTS CV_WRAP_AS(goodFeaturesToTrackWithQuality) void goodFeaturesToTrack(InputArray image
Same as above, but returns also quality measure of the detected corners.
CV_EXPORTS_W double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
Applies a fixed-level threshold to each array element.
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: features2d.hpp:864
Definition: features2d.hpp:910
Definition: features2d.hpp:894
Definition: cvstd_wrapper.hpp:74
Definition: features2d.hpp:878
Definition: features2d.hpp:699