diff --git a/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp b/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp index 4eeba5ea5..8015850a2 100644 --- a/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp +++ b/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp @@ -84,10 +84,9 @@ class CV_EXPORTS_W FREAK : public Feature2D { public: - enum - { - NB_SCALES = 64, NB_PAIRS = 512, NB_ORIENPAIRS = 45 - }; + static const int NB_SCALES = 64; + static const int NB_PAIRS = 512; + static const int NB_ORIENPAIRS = 45; /** @param orientationNormalized Enable orientation normalization. diff --git a/modules/xfeatures2d/src/freak.cpp b/modules/xfeatures2d/src/freak.cpp index 384ad08a4..5567b3ae0 100644 --- a/modules/xfeatures2d/src/freak.cpp +++ b/modules/xfeatures2d/src/freak.cpp @@ -138,14 +138,10 @@ protected: OrientationPair orientationPairs[NB_ORIENPAIRS]; }; - static const double FREAK_LOG2 = 0.693147180559945; static const int FREAK_NB_ORIENTATION = 256; static const int FREAK_NB_POINTS = 43; static const int FREAK_SMALLEST_KP_SIZE = 7; // smallest size of keypoints -static const int FREAK_NB_SCALES = FREAK::NB_SCALES; -static const int FREAK_NB_PAIRS = FREAK::NB_PAIRS; -static const int FREAK_NB_ORIENPAIRS = FREAK::NB_ORIENPAIRS; // default pairs static const int FREAK_DEF_PAIRS[FREAK_Impl::NB_PAIRS] = @@ -209,8 +205,8 @@ void FREAK_Impl::buildPattern() nOctaves0 = nOctaves; patternScale0 = patternScale; - patternLookup.resize(FREAK_NB_SCALES*FREAK_NB_ORIENTATION*FREAK_NB_POINTS); - double scaleStep = std::pow(2.0, (double)(nOctaves)/FREAK_NB_SCALES ); // 2 ^ ( (nOctaves-1) /nbScales) + patternLookup.resize(FREAK::NB_SCALES*FREAK_NB_ORIENTATION*FREAK_NB_POINTS); + double scaleStep = std::pow(2.0, (double)(nOctaves)/FREAK::NB_SCALES ); // 2 ^ ( (nOctaves-1) /nbScales) double scalingFactor, alpha, beta, theta = 0; // pattern definition, radius normalized to 1.0 (outer point position+sigma=1.0) @@ -226,7 +222,7 @@ void FREAK_Impl::buildPattern() radius[6]/2.0, radius[6]/2.0 }; // fill the lookup table - for( int scaleIdx=0; scaleIdx < FREAK_NB_SCALES; ++scaleIdx ) + for( int scaleIdx=0; scaleIdx < FREAK::NB_SCALES; ++scaleIdx ) { patternSizes[scaleIdx] = 0; // proper initialization scalingFactor = std::pow(scaleStep,scaleIdx); //scale of the pattern, scaleStep ^ scaleIdx @@ -282,7 +278,7 @@ void FREAK_Impl::buildPattern() orientationPairs[39].i=30; orientationPairs[39].j=33; orientationPairs[40].i=31; orientationPairs[40].j=34; orientationPairs[41].i=32; orientationPairs[41].j=35; orientationPairs[42].i=36; orientationPairs[42].j=39; orientationPairs[43].i=37; orientationPairs[43].j=40; orientationPairs[44].i=38; orientationPairs[44].j=41; - for( unsigned m = FREAK_NB_ORIENPAIRS; m--; ) + for( unsigned m = FREAK::NB_ORIENPAIRS; m--; ) { const float dx = patternLookup[orientationPairs[m].i].x-patternLookup[orientationPairs[m].j].x; const float dy = patternLookup[orientationPairs[m].i].y-patternLookup[orientationPairs[m].j].y; @@ -305,9 +301,9 @@ void FREAK_Impl::buildPattern() // Input vector provided if( !selectedPairs0.empty() ) { - if( (int)selectedPairs0.size() == FREAK_NB_PAIRS ) + if( (int)selectedPairs0.size() == FREAK::NB_PAIRS ) { - for( int i = 0; i < FREAK_NB_PAIRS; ++i ) + for( int i = 0; i < FREAK::NB_PAIRS; ++i ) descriptionPairs[i] = allPairs[selectedPairs0.at(i)]; } else @@ -317,7 +313,7 @@ void FREAK_Impl::buildPattern() } else // default selected pairs { - for( int i = 0; i < FREAK_NB_PAIRS; ++i ) + for( int i = 0; i < FREAK::NB_PAIRS; ++i ) descriptionPairs[i] = allPairs[FREAK_DEF_PAIRS[i]]; } } @@ -370,11 +366,11 @@ void FREAK_Impl::compute( InputArray _image, std::vector& keypoints, O template void FREAK_Impl::extractDescriptor(srcMatType *pointsValue, void ** ptr) { - std::bitset** ptrScalar = (std::bitset**) ptr; + std::bitset** ptrScalar = (std::bitset**) ptr; // extracting descriptor preserving the order of SSE version int cnt = 0; - for( int n = 7; n < FREAK_NB_PAIRS; n += 128) + for( int n = 7; n < FREAK::NB_PAIRS; n += 128) { for( int m = 8; m--; ) { @@ -396,7 +392,7 @@ void FREAK_Impl::extractDescriptor(uchar *pointsValue, void ** ptr) // note that comparisons order is modified in each block (but first 128 comparisons remain globally the same-->does not affect the 128,384 bits segmanted matching strategy) int cnt = 0; - for( int n = FREAK_NB_PAIRS/128; n-- ; ) + for( int n = FREAK::NB_PAIRS/128; n-- ; ) { __m128i result128 = _mm_setzero_si128(); for( int m = 128/16; m--; cnt += 16 ) @@ -457,7 +453,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector& k std::vector kpScaleIdx(keypoints.size()); // used to save pattern scale index corresponding to each keypoints const std::vector::iterator ScaleIdxBegin = kpScaleIdx.begin(); // used in std::vector erase function const std::vector::iterator kpBegin = keypoints.begin(); // used in std::vector erase function - const float sizeCst = static_cast(FREAK_NB_SCALES/(FREAK_LOG2* nOctaves)); + const float sizeCst = static_cast(FREAK::NB_SCALES/(FREAK_LOG2* nOctaves)); srcMatType pointsValue[FREAK_NB_POINTS]; int thetaIdx = 0; int direction0; @@ -470,8 +466,8 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector& k { //Is k non-zero? If so, decrement it and continue" kpScaleIdx[k] = std::max( (int)(std::log(keypoints[k].size/FREAK_SMALLEST_KP_SIZE)*sizeCst+0.5) ,0); - if( kpScaleIdx[k] >= FREAK_NB_SCALES ) - kpScaleIdx[k] = FREAK_NB_SCALES-1; + if( kpScaleIdx[k] >= FREAK::NB_SCALES ) + kpScaleIdx[k] = FREAK::NB_SCALES-1; if( keypoints[k].pt.x <= patternSizes[kpScaleIdx[k]] || //check if the description at this specific position and scale fits inside the image keypoints[k].pt.y <= patternSizes[kpScaleIdx[k]] || @@ -490,9 +486,9 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector& k for( size_t k = keypoints.size(); k--; ) { kpScaleIdx[k] = scIdx; // equivalent to the formule when the scale is normalized with a constant size of keypoints[k].size=3*SMALLEST_KP_SIZE - if( kpScaleIdx[k] >= FREAK_NB_SCALES ) + if( kpScaleIdx[k] >= FREAK::NB_SCALES ) { - kpScaleIdx[k] = FREAK_NB_SCALES-1; + kpScaleIdx[k] = FREAK::NB_SCALES-1; } if( keypoints[k].pt.x <= patternSizes[kpScaleIdx[k]] || keypoints[k].pt.y <= patternSizes[kpScaleIdx[k]] || @@ -510,7 +506,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector& k if( !extAll ) { // extract the best comparisons only - _descriptors.create((int)keypoints.size(), FREAK_NB_PAIRS/8, CV_8U); + _descriptors.create((int)keypoints.size(), FREAK::NB_PAIRS/8, CV_8U); _descriptors.setTo(Scalar::all(0)); Mat descriptors = _descriptors.getMat(); @@ -773,9 +769,9 @@ std::vector FREAK_Impl::selectPairs(const std::vector& images } std::vector idxBestPairs; - if( (int)bestPairs.size() >= FREAK_NB_PAIRS ) + if( (int)bestPairs.size() >= FREAK::NB_PAIRS ) { - for( int i = 0; i < FREAK_NB_PAIRS; ++i ) + for( int i = 0; i < FREAK::NB_PAIRS; ++i ) idxBestPairs.push_back(bestPairs[i].idx); } else @@ -827,7 +823,7 @@ FREAK_Impl::~FREAK_Impl() int FREAK_Impl::descriptorSize() const { - return FREAK_NB_PAIRS / 8; // descriptor length in bytes + return FREAK::NB_PAIRS / 8; // descriptor length in bytes } int FREAK_Impl::descriptorType() const