OpenCV 4.5.3(日本語機械翻訳)
line_descriptor/descriptor.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) 2014, Biagio Montesano, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
21 //
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
25 //
26 // * The name of the copyright holders may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #ifndef __OPENCV_DESCRIPTOR_HPP__
43 #define __OPENCV_DESCRIPTOR_HPP__
44
45 #include <map>
46 #include <vector>
47 #include <list>
48
49 #if defined _MSC_VER && _MSC_VER <= 1700
50 #include <stdint.h>
51 #else
52 #include <inttypes.h>
53 #endif
54
55 #include <stdio.h>
56 #include <iostream>
57
58 #include "opencv2/core/utility.hpp"
59 #include <opencv2/imgproc.hpp>
60 #include "opencv2/core.hpp"
61
62 /* define data types */
63 typedef uint64_t UINT64;
64 typedef uint32_t UINT32;
65 typedef uint16_t UINT16;
66 typedef uint8_t UINT8;
67
68 /* define constants */
69 #define UINT64_1 ((UINT64)0x01)
70 #define UINT32_1 ((UINT32)0x01)
71
72 namespace cv
73{
74 namespace line_descriptor
75{
76
79
102 struct CV_EXPORTS_W_SIMPLE KeyLine
103{
104 public:
106 CV_PROP_RW float angle;
107
109 CV_PROP_RW int class_id;
110
112 CV_PROP_RW int octave;
113
115 CV_PROP_RW Point2f pt;
116
120 CV_PROP_RW float response;
121
123 CV_PROP_RW float size;
124
126 CV_PROP_RW float startPointX;
127 CV_PROP_RW float startPointY;
128 CV_PROP_RW float endPointX;
129 CV_PROP_RW float endPointY;
130
132 CV_PROP_RW float sPointInOctaveX;
133 CV_PROP_RW float sPointInOctaveY;
134 CV_PROP_RW float ePointInOctaveX;
135 CV_PROP_RW float ePointInOctaveY;
136
138 CV_PROP_RW float lineLength;
139
141 CV_PROP_RW int numOfPixels;
142
144 CV_WRAP Point2f getStartPoint() const
145 {
146 return Point2f(startPointX, startPointY);
147 }
148
150 CV_WRAP Point2f getEndPoint() const
151 {
152 return Point2f(endPointX, endPointY);
153 }
154
156 CV_WRAP Point2f getStartPointInOctave() const
157 {
158 return Point2f(sPointInOctaveX, sPointInOctaveY);
159 }
160
162 CV_WRAP Point2f getEndPointInOctave() const
163 {
164 return Point2f(ePointInOctaveX, ePointInOctaveY);
165 }
166
168 CV_WRAP KeyLine()
169 {
170 }
171};
172
180 class CV_EXPORTS_W BinaryDescriptor : public Algorithm
181{
182
183 public:
186 struct CV_EXPORTS Params
187 {
188 /*CV_WRAP*/
189 Params();
190
194
198
201
202 int ksize_;
203
205 void read( const FileNode& fn );
206
208 void write( FileStorage& fs ) const;
209
210 };
211
220
224 CV_WRAP static Ptr<BinaryDescriptor> createBinaryDescriptor();
225 static Ptr<BinaryDescriptor> createBinaryDescriptor( Params parameters );
226
229
232 CV_WRAP int getNumOfOctaves();
236 CV_WRAP void setNumOfOctaves( int octaves );
239 CV_WRAP int getWidthOfBand();
243 CV_WRAP void setWidthOfBand( int width );
246 CV_WRAP int getReductionRatio();
250 CV_WRAP void setReductionRatio( int rRatio );
251
256 virtual void read( const cv::FileNode& fn ) CV_OVERRIDE;
257
262 virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE;
263
270 CV_WRAP void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, const Mat& mask = Mat() );
271
278 void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, const std::vector<Mat>& masks =
279 std::vector<Mat>() ) const;
280
288 CV_WRAP void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyLine>& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr = false ) const;
289
297 void compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors, bool returnFloatDescr =
298 false ) const;
299
302 int descriptorSize() const;
303
306 int descriptorType() const;
307
309 /*CV_WRAP*/
310 int defaultNorm() const;
311
324 virtual void operator()( InputArray image, InputArray mask, CV_OUT std::vector<KeyLine>& keylines, OutputArray descriptors,
325 bool useProvidedKeyLines = false, bool returnFloatDescr = false ) const;
326
327 protected:
329 virtual void detectImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, const Mat& mask = Mat() ) const;
330
332 virtual void computeImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, Mat& descriptors, bool returnFloatDescr,
333 bool useDetectionData ) const;
334
335 private:
337 struct OctaveLine
338 {
339 unsigned int octaveCount; //the octave which this line is detected
340 unsigned int lineIDInOctave; //the line ID in that octave image
341 unsigned int lineIDInScaleLineVec; //the line ID in Scale line vector
342 float lineLength; //the length of line in original image scale
343 };
344
345 // A 2D line (normal equation parameters).
346 struct SingleLine
347 {
348 //note: rho and theta are based on coordinate origin, i.e. the top-left corner of image
349 double rho; //unit: pixel length
350 double theta; //unit: rad
351 double linePointX; // = rho * cos(theta);
352 double linePointY; // = rho * sin(theta);
353 //for EndPoints, the coordinate origin is the top-left corner of image.
354 double startPointX;
355 double startPointY;
356 double endPointX;
357 double endPointY;
358 //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis.
359 double direction;
360 //mean gradient magnitude
361 double gradientMagnitude;
362 //mean gray value of pixels in dark side of line
363 double darkSideGrayValue;
364 //mean gray value of pixels in light side of line
365 double lightSideGrayValue;
366 //the length of line
367 double lineLength;
368 //the width of line;
369 double width;
370 //number of pixels
371 int numOfPixels;
372 //the decriptor of line
373 std::vector<double> descriptor;
374 };
375
376 // Specifies a vector of lines.
377 typedef std::vector<SingleLine> Lines_list;
378
379 struct OctaveSingleLine
380 {
381 /*endPoints, the coordinate origin is the top-left corner of the original image.
382 *startPointX = sPointInOctaveX * (factor)^octaveCount; */
383 float startPointX;
384 float startPointY;
385 float endPointX;
386 float endPointY;
387 //endPoints, the coordinate origin is the top-left corner of the octave image.
388 float sPointInOctaveX;
389 float sPointInOctaveY;
390 float ePointInOctaveX;
391 float ePointInOctaveY;
392 //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis.
393 float direction;
394 //the summation of gradient magnitudes of pixels on lines
395 float salience;
396 //the length of line
397 float lineLength;
398 //number of pixels
399 unsigned int numOfPixels;
400 //the octave which this line is detected
401 unsigned int octaveCount;
402 //the decriptor of line
403 std::vector<float> descriptor;
404
405 OctaveSingleLine() : startPointX(0), startPointY(0), endPointX(0), endPointY(0),
406 sPointInOctaveX(0), sPointInOctaveY(0), ePointInOctaveX(0), ePointInOctaveY(0),
407 direction(0), salience(0), lineLength(0), numOfPixels(0), octaveCount(0),
408 descriptor(std::vector<float>())
409 {}
410 };
411
412 struct Pixel
413 {
414 unsigned int x; //X coordinate
415 unsigned int y; //Y coordinate
416 };
417 struct EdgeChains
418 {
419 std::vector<unsigned int> xCors; //all the x coordinates of edge points
420 std::vector<unsigned int> yCors; //all the y coordinates of edge points
421 std::vector<unsigned int> sId; //the start index of each edge in the coordinate arrays
422 unsigned int numOfEdges; //the number of edges whose length are larger than minLineLen; numOfEdges < sId.size;
423 };
424
425 struct LineChains
426 {
427 std::vector<unsigned int> xCors; //all the x coordinates of line points
428 std::vector<unsigned int> yCors; //all the y coordinates of line points
429 std::vector<unsigned int> sId; //the start index of each line in the coordinate arrays
430 unsigned int numOfLines; //the number of lines whose length are larger than minLineLen; numOfLines < sId.size;
431 };
432
433 typedef std::list<Pixel> PixelChain; //each edge is a pixel chain
434
435 struct CV_EXPORTS_W_SIMPLE EDLineParam
436 {
437 CV_PROP_RW int ksize;
438 CV_PROP_RW float sigma;
439 CV_PROP_RW float gradientThreshold;
440 CV_PROP_RW float anchorThreshold;
441 CV_PROP_RW int scanIntervals;
442 CV_PROP_RW int minLineLen;
443 CV_PROP_RW double lineFitErrThreshold;
444 };
445
446 #define RELATIVE_ERROR_FACTOR 100.0
447 #define MLN10 2.30258509299404568402
448 #define log_gamma(x) ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x))
449
458 class CV_EXPORTS_W EDLineDetector
459 {
460 public:
461 CV_WRAP EDLineDetector();
462 CV_WRAP_AS(EDLineDetectorWithParams) EDLineDetector( EDLineParam param );
463 ~EDLineDetector();
464
467 CV_WRAP static Ptr<EDLineDetector> createEDLineDetector();
468
469
470 CV_WRAP_AS(createEDLineDetectorWithParams) static Ptr<EDLineDetector> createEDLineDetector(EDLineParam params);
471 /*extract edges from image
472 *image: In, gray image;
473 *edges: Out, store the edges, each edge is a pixel chain
474 *return -1: error happen
475 */
476 int EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains );
477
478 /*extract lines from image
479 *image: In, gray image;
480 *lines: Out, store the extracted lines,
481 *return -1: error happen
482 */
483 int EDline( cv::Mat &image, LineChains &lines );
484
486 CV_WRAP int EDline( cv::Mat &image );
487
488 cv::Mat dxImg_; //store the dxImg;
489
490 cv::Mat dyImg_; //store the dyImg;
491
492 cv::Mat gImgWO_; //store the gradient image without threshold;
493
494 LineChains lines_; //store the detected line chains;
495
496 //store the line Equation coefficients, vec3=[w1,w2,w3] for line w1*x + w2*y + w3=0;
497 std::vector<std::vector<double> > lineEquations_;
498
499 //store the line endpoints, [x1,y1,x2,y3]
500 std::vector<std::vector<float> > lineEndpoints_;
501
502 //store the line direction
503 std::vector<float> lineDirection_;
504
505 //store the line salience, which is the summation of gradients of pixels on line
506 std::vector<float> lineSalience_;
507
508 // image sizes
509 unsigned int imageWidth;
510 unsigned int imageHeight;
511
512 /*The threshold of line fit error;
513 *If lineFitErr is large than this threshold, then
514 *the pixel chain is not accepted as a single line segment.*/
515 double lineFitErrThreshold_;
516
517 /*the threshold of pixel gradient magnitude.
518 *Only those pixel whose gradient magnitude are larger than this threshold will be
519 *taken as possible edge points. Default value is 36*/
520 short gradienThreshold_;
521
522 /*If the pixel's gradient value is bigger than both of its neighbors by a
523 *certain threshold (ANCHOR_THRESHOLD), the pixel is marked to be an anchor.
524 *Default value is 8*/
525 unsigned char anchorThreshold_;
526
527 /*anchor testing can be performed at different scan intervals, i.e.,
528 *every row/column, every second row/column etc.
529 *Default value is 2*/
530 unsigned int scanIntervals_;
531
532 int minLineLen_; //minimal acceptable line length
533
534 private:
535 void InitEDLine_();
536
537 /*For an input edge chain, find the best fit line, the default chain length is minLineLen_
538 *xCors: In, pointer to the X coordinates of pixel chain;
539 *yCors: In, pointer to the Y coordinates of pixel chain;
540 *offsetS:In, start index of this chain in vector;
541 *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical);
542 *return: line fit error; -1:error happens;
543 */
544 double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, std::vector<double> &lineEquation );
545
546 /*For an input pixel chain, find the best fit line. Only do the update based on new points.
547 *For A*x=v, Least square estimation of x = Inv(A^T * A) * (A^T * v);
548 *If some new observations are added, i.e, [A; A'] * x = [v; v'],
549 *then x' = Inv(A^T * A + (A')^T * A') * (A^T * v + (A')^T * v');
550 *xCors: In, pointer to the X coordinates of pixel chain;
551 *yCors: In, pointer to the Y coordinates of pixel chain;
552 *offsetS:In, start index of this chain in vector;
553 *newOffsetS: In, start index of extended part;
554 *offsetE:In, end index of this chain in vector;
555 *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical);
556 *return: line fit error; -1:error happens;
557 */
558 double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int newOffsetS, unsigned int offsetE,
559 std::vector<double> &lineEquation );
560
565 bool LineValidation_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int offsetE, std::vector<double> &lineEquation,
566 float &direction );
567
568 bool bValidate_; //flag to decide whether line will be validated
569
570 int ksize_; //the size of Gaussian kernel: ksize X ksize, default value is 5.
571
572 float sigma_; //the sigma of Gaussian kernal, default value is 1.0.
573
574 /*For example, there two edges in the image:
575 *edge1 = [(7,4), (8,5), (9,6),| (10,7)|, (11, 8), (12,9)] and
576 *edge2 = [(14,9), (15,10), (16,11), (17,12),| (18, 13)|, (19,14)] ; then we store them as following:
577 *pFirstPartEdgeX_ = [10, 11, 12, 18, 19];//store the first part of each edge[from middle to end]
578 *pFirstPartEdgeY_ = [7, 8, 9, 13, 14];
579 *pFirstPartEdgeS_ = [0,3,5];// the index of start point of first part of each edge
580 *pSecondPartEdgeX_ = [10, 9, 8, 7, 18, 17, 16, 15, 14];//store the second part of each edge[from middle to front]
581 *pSecondPartEdgeY_ = [7, 6, 5, 4, 13, 12, 11, 10, 9];//anchor points(10, 7) and (18, 13) are stored again
582 *pSecondPartEdgeS_ = [0, 4, 9];// the index of start point of second part of each edge
583 *This type of storage order is because of the order of edge detection process.
584 *For each edge, start from one anchor point, first go right, then go left or first go down, then go up*/
585
586 //store the X coordinates of the first part of the pixels for chains
587 unsigned int *pFirstPartEdgeX_;
588
589 //store the Y coordinates of the first part of the pixels for chains
590 unsigned int *pFirstPartEdgeY_;
591
592 //store the start index of every edge chain in the first part arrays
593 unsigned int *pFirstPartEdgeS_;
594
595 //store the X coordinates of the second part of the pixels for chains
596 unsigned int *pSecondPartEdgeX_;
597
598 //store the Y coordinates of the second part of the pixels for chains
599 unsigned int *pSecondPartEdgeY_;
600
601 //store the start index of every edge chain in the second part arrays
602 unsigned int *pSecondPartEdgeS_;
603
604 //store the X coordinates of anchors
605 unsigned int *pAnchorX_;
606
607 //store the Y coordinates of anchors
608 unsigned int *pAnchorY_;
609
610 //edges
611 cv::Mat edgeImage_;
612
613 cv::Mat gImg_; //store the gradient image;
614
615 cv::Mat dirImg_; //store the direction image
616
617 double logNT_;
618
619 cv::Mat_<float> ATA; //the previous matrix of A^T * A;
620
621 cv::Mat_<float> ATV; //the previous vector of A^T * V;
622
623 cv::Mat_<float> fitMatT; //the matrix used in line fit function;
624
625 cv::Mat_<float> fitVec; //the vector used in line fit function;
626
627 cv::Mat_<float> tempMatLineFit; //the matrix used in line fit function;
628
629 cv::Mat_<float> tempVecLineFit; //the vector used in line fit function;
630
631};
632
633 // Specifies a vector of lines.
634 typedef std::vector<OctaveSingleLine> LinesVec;
635
636 // each element in ScaleLines is a vector of lines
637 // which corresponds the same line detected in different octave images.
638 typedef std::vector<LinesVec> ScaleLines;
639
640 /* compute Gaussian pyramids */
641 void computeGaussianPyramid( const Mat& image, const int numOctaves );
642
643 /* compute Sobel's derivatives */
644 void computeSobel( const Mat& image, const int numOctaves );
645
646 /* conversion of an LBD descriptor to its binary representation */
647 unsigned char binaryConversion( float* f1, float* f2 );
648
649 /* compute LBD descriptors using EDLine extractor */
650 int computeLBD( ScaleLines &keyLines, bool useDetectionData = false );
651
652 /* gathers lines in groups using EDLine extractor.
653 Each group contains the same line, detected in different octaves */
654 int OctaveKeyLines( cv::Mat& image, ScaleLines &keyLines );
655
656 /* the local gaussian coefficient applied to the orthogonal line direction within each band */
657std::vector<double> gaussCoefL_;
658
659 /* the global gaussian coefficient applied to each row within line support region */
660std::vector<double> gaussCoefG_;
661
662 /* descriptor parameters */
663Params params;
664
665 /* vector of sizes of downsampled and blurred images */
666std::vector<cv::Size> images_sizes;
667
668 /*For each octave of image, we define an EDLineDetector, because we can get gradient images (dxImg, dyImg, gImg)
669 *from the EDLineDetector class without extra computation cost. Another reason is that, if we use
670 *a single EDLineDetector to detect lines in different octave of images, then we need to allocate and release
671 *memory for gradient images (dxImg, dyImg, gImg) repeatedly for their varying size*/
672std::vector<Ptr<EDLineDetector> > edLineVec_;
673
674 /* Sobel's derivatives */
675std::vector<cv::Mat> dxImg_vector, dyImg_vector;
676
677 /* Gaussian pyramid */
678std::vector<cv::Mat> octaveImages;
679
680};
681
699 struct CV_EXPORTS_W_SIMPLE LSDParam
700{
701 CV_PROP_RW double scale ;
702 CV_PROP_RW double sigma_scale;
703 CV_PROP_RW double quant;
704 CV_PROP_RW double ang_th;
705 CV_PROP_RW double log_eps;
706 CV_PROP_RW double density_th ;
707 CV_PROP_RW int n_bins ;
708
709
710CV_WRAP LSDParam():scale(0.8),
711 sigma_scale(0.6),
712 quant(2.0),
713 ang_th(22.5),
714 log_eps(0),
715 density_th(0.7),
716 n_bins(1024){}
717
718};
719
720 class CV_EXPORTS_W LSDDetector : public Algorithm
721{
722 public:
723
724 /* constructor */
725CV_WRAP LSDDetector() : params()
726{
727}
728;
729
730 CV_WRAP_AS(LSDDetectorWithParams) LSDDetector(LSDParam _params) : params(_params)
731{
732}
733;
734
737 CV_WRAP static Ptr<LSDDetector> createLSDDetector();
738
739
740 CV_WRAP_AS(createLSDDetectorWithParams) static Ptr<LSDDetector> createLSDDetector(LSDParam params);
741
742
751 CV_WRAP void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, int scale, int numOctaves, const Mat& mask = Mat() );
752
760 CV_WRAP void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves,
761 const std::vector<Mat>& masks = std::vector<Mat>() ) const;
762
763 private:
764 /* compute Gaussian pyramid of input image */
765 void computeGaussianPyramid( const Mat& image, int numOctaves, int scale );
766
767 /* implementation of line detection */
768 void detectImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, int numOctaves, int scale, const Mat& mask ) const;
769
770 /* matrices for Gaussian pyramids */
771std::vector<cv::Mat> gaussianPyrs;
772
773 /* parameters */
774 LSDParam params;
775};
776
815 class CV_EXPORTS_W BinaryDescriptorMatcher : public Algorithm
816{
817
818 public:
827 CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector<DMatch>& matches, const Mat& mask = Mat() ) const;
828
836 CV_WRAP_AS(matchQuery) void match( const Mat& queryDescriptors, CV_OUT std::vector<DMatch>& matches, const std::vector<Mat>& masks = std::vector<Mat>() );
837
849 CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k, const Mat& mask = Mat(),
850 bool compactResult = false ) const;
851
862 CV_WRAP_AS(knnMatchQuery) void knnMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const std::vector<Mat>& masks = std::vector<Mat>(),
863 bool compactResult = false );
864
876 void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
877 const Mat& mask = Mat(), bool compactResult = false ) const;
878
889 void radiusMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, const std::vector<Mat>& masks =
890std::vector<Mat>(),
891 bool compactResult = false );
892
900 void add( const std::vector<Mat>& descriptors );
901
907 void train();
908
912
915 void clear() CV_OVERRIDE;
916
922
925{
926}
927
928 private:
929 class BucketGroup
930{
931
932 public:
934BucketGroup(bool needAllocateGroup = true);
935
937~BucketGroup();
938
940 void insert( int subindex, UINT32 data );
941
943UINT32* query( int subindex, int *size );
944
946 void insert_value( std::vector<uint32_t>& vec, int index, UINT32 data );
947 void push_value( std::vector<uint32_t>& vec, UINT32 Data );
948
950UINT32 empty;
951std::vector<uint32_t> group;
952
953
954};
955
956 class SparseHashtable
957{
958
959 private:
960
962 static const int MAX_B;
963
965std::vector<BucketGroup> table;
966
967 public:
968
970SparseHashtable();
971
973~SparseHashtable();
974
976 int init( int _b );
977
979 void insert( UINT64 index, UINT32 data );
980
982UINT32* query( UINT64 index, int* size );
983
985 int b;
986
988UINT64 size;
989
990};
991
993 class bitarray
994{
995
996 public:
998UINT32 *arr;
999UINT32 length;
1000
1002bitarray()
1003{
1004arr = NULL;
1005length = 0;
1006}
1007
1009bitarray( UINT64 _bits )
1010{
1011arr = NULL;
1012init( _bits );
1013}
1014
1016 void init( UINT64 _bits )
1017{
1018 if( arr )
1019 delete[] arr;
1020length = (UINT32) ceil( _bits / 32.00 );
1021arr = new UINT32[length];
1022erase();
1023}
1024
1026~bitarray()
1027{
1028 if( arr )
1029 delete[] arr;
1030}
1031
1032 inline void flip( UINT64 index )
1033{
1034arr[index >> 5] ^= ( (UINT32) 0x01 ) << ( index % 32 );
1035}
1036
1037 inline void set( UINT64 index )
1038{
1039arr[index >> 5] |= ( (UINT32) 0x01 ) << ( index % 32 );
1040}
1041
1042 inline UINT8 get( UINT64 index )
1043{
1044 return ( arr[index >> 5] & ( ( (UINT32) 0x01 ) << ( index % 32 ) ) ) != 0;
1045}
1046
1048 inline void erase()
1049{
1050memset( arr, 0, sizeof(UINT32) * length );
1051}
1052
1053};
1054
1055 class Mihasher
1056{
1057
1058 public:
1060 int B;
1061
1063 int B_over_8;
1064
1066 int b;
1067
1069 int m;
1070
1072 int mplus;
1073
1075 int D;
1076
1078 int d;
1079
1081 int K;
1082
1084UINT64 N;
1085
1087 cv::Mat codes;
1088
1090Ptr<bitarray> counter;
1091
1093std::vector<SparseHashtable> H;
1094
1096std::vector<UINT32> xornum;
1097
1099 int power[100];
1100
1102Mihasher();
1103
1105~Mihasher();
1106
1108Mihasher( int B, int m );
1109
1111 void setK( int K );
1112
1114 void populate( cv::Mat & codes, UINT32 N, int dim1codes );
1115
1117 void batchquery( UINT32 * results, UINT32 *numres/*, qstat *stats*/, const cv::Mat & q, UINT32 numq, int dim1queries );
1118
1119 private:
1120
1122 void query( UINT32 * results, UINT32* numres/*, qstat *stats*/, UINT8 *q, UINT64 * chunks, UINT32 * res );
1123};
1124
1126 void checkKDistances( UINT32 * numres, int k, std::vector<int>& k_distances, int row, int string_length ) const;
1127
1129Mat descriptorsMat;
1130
1132std::map<int, int> indexesMap;
1133
1135Ptr<Mihasher> dataset;
1136
1138 int nextAddedIndex;
1139
1141 int numImages;
1142
1144 int descrInDS;
1145
1146};
1147
1148 /* --------------------------------------------------------------------------------------------
1149 UTILITY FUNCTIONS
1150 -------------------------------------------------------------------------------------------- */
1151
1153 struct CV_EXPORTS_W_SIMPLE DrawLinesMatchesFlags
1154{
1155CV_PROP_RW enum
1156{
1157 DEFAULT = 0,
1161 DRAW_OVER_OUTIMG = 1,
1164NOT_DRAW_SINGLE_LINES = 2
1166};
1167
1184 CV_EXPORTS_W void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, const Mat& img2, const std::vector<KeyLine>& keylines2,
1185 const std::vector<DMatch>& matches1to2, CV_OUT Mat& outImg, const Scalar& matchColor = Scalar::all( -1 ),
1186 const Scalar& singleLineColor = Scalar::all( -1 ), const std::vector<char>& matchesMask = std::vector<char>(),
1187 int flags = DrawLinesMatchesFlags::DEFAULT );
1188
1197 CV_EXPORTS_W void drawKeylines( const Mat& image, const std::vector<KeyLine>& keylines, CV_OUT Mat& outImage, const Scalar& color = Scalar::all( -1 ),
1198 int flags = DrawLinesMatchesFlags::DEFAULT );
1199
1201
1202}
1203}
1204
1205 #endif
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
This is a base class for all more or less complex algorithms in OpenCV
Definition: core.hpp:3091
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
Template matrix class derived from Mat
Definition: mat.hpp:2199
n-dimensional dense array class
Definition: mat.hpp:802
static Scalar_< double > all(double v0)
returns a scalar with all elements set to v0
Class implements both functionalities for detection of lines and computation of their binary descript...
Definition: line_descriptor/descriptor.hpp:181
void detect(const std::vector< Mat > &images, std::vector< std::vector< KeyLine > > &keylines, const std::vector< Mat > &masks=std::vector< Mat >()) const
void compute(const std::vector< Mat > &images, std::vector< std::vector< KeyLine > > &keylines, std::vector< Mat > &descriptors, bool returnFloatDescr=false) const
int descriptorType() const
Return data type
virtual void detectImpl(const Mat &imageSrc, std::vector< KeyLine > &keylines, const Mat &mask=Mat()) const
virtual void write(cv::FileStorage &fs) const CV_OVERRIDE
Store parameters to a FileStorage object
virtual void computeImpl(const Mat &imageSrc, std::vector< KeyLine > &keylines, Mat &descriptors, bool returnFloatDescr, bool useDetectionData) const
virtual void read(const cv::FileNode &fn) CV_OVERRIDE
Read parameters from a FileNode object and store them
BinaryDescriptor(const BinaryDescriptor::Params &parameters=BinaryDescriptor::Params())
Constructor
int descriptorSize() const
Return descriptor size
virtual void operator()(InputArray image, InputArray mask, CV_OUT std::vector< KeyLine > &keylines, OutputArray descriptors, bool useProvidedKeyLines=false, bool returnFloatDescr=false) const
Define operator '()' to perform detection of KeyLines and computation of descriptors in a row.
furnishes all functionalities for querying a dataset provided by user or internal to class (that user...
Definition: line_descriptor/descriptor.hpp:816
void add(const std::vector< Mat > &descriptors)
Store locally new descriptors to be inserted in dataset, without updating dataset.
void clear() CV_OVERRIDE
Clear dataset and internal data
void train()
Update dataset by inserting into it all descriptors that were stored locally by add function.
CV_WRAP_AS(knnMatchQuery) void knnMatch(const Mat &queryDescriptors
void radiusMatch(const Mat &queryDescriptors, std::vector< std::vector< DMatch > > &matches, float maxDistance, const std::vector< Mat > &masks=std::vector< Mat >(), bool compactResult=false)
CV_WRAP_AS(matchQuery) void match(const Mat &queryDescriptors
static Ptr< BinaryDescriptorMatcher > createBinaryDescriptorMatcher()
Create a BinaryDescriptorMatcher object and return a smart pointer to it.
void radiusMatch(const Mat &queryDescriptors, const Mat &trainDescriptors, std::vector< std::vector< DMatch > > &matches, float maxDistance, const Mat &mask=Mat(), bool compactResult=false) const
For every input query descriptor, retrieve, from a dataset provided from user or from the one interna...
Definition: line_descriptor/descriptor.hpp:721
CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode)
Flips a 2D array around vertical, horizontal, or both axes.
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 void drawLineMatches(const Mat &img1, const std::vector< KeyLine > &keylines1, const Mat &img2, const std::vector< KeyLine > &keylines2, const std::vector< DMatch > &matches1to2, CV_OUT Mat &outImg, const Scalar &matchColor=Scalar::all(-1), const Scalar &singleLineColor=Scalar::all(-1), const std::vector< char > &matchesMask=std::vector< char >(), int flags=DrawLinesMatchesFlags::DEFAULT)
Draws the found matches of keylines from two images.
CV_EXPORTS_W void drawKeylines(const Mat &image, const std::vector< KeyLine > &keylines, CV_OUT Mat &outImage, const Scalar &color=Scalar::all(-1), int flags=DrawLinesMatchesFlags::DEFAULT)
Draws keylines.
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
DualQuat< T > power(const DualQuat< T > &dq, const T t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
Definition: dualquaternion.inl.hpp:358
Definition: cvstd_wrapper.hpp:74
List of BinaryDescriptor parameters:
Definition: line_descriptor/descriptor.hpp:187
int numOfOctave_
Definition: line_descriptor/descriptor.hpp:193
int reductionRatio
Definition: line_descriptor/descriptor.hpp:200
void write(FileStorage &fs) const
int widthOfBand_
Definition: line_descriptor/descriptor.hpp:197
Definition: line_descriptor/descriptor.hpp:1154
@ DEFAULT
Definition: line_descriptor/descriptor.hpp:1157
A class to represent a line
Definition: line_descriptor/descriptor.hpp:103
Definition: line_descriptor/descriptor.hpp:700