Commit bcf8f15a authored by Hamdi Sahloul's avatar Hamdi Sahloul

Convert unnamed FREAK enum to static const

parent f182eddb
...@@ -84,10 +84,9 @@ class CV_EXPORTS_W FREAK : public Feature2D ...@@ -84,10 +84,9 @@ class CV_EXPORTS_W FREAK : public Feature2D
{ {
public: public:
enum static const int NB_SCALES = 64;
{ static const int NB_PAIRS = 512;
NB_SCALES = 64, NB_PAIRS = 512, NB_ORIENPAIRS = 45 static const int NB_ORIENPAIRS = 45;
};
/** /**
@param orientationNormalized Enable orientation normalization. @param orientationNormalized Enable orientation normalization.
......
...@@ -138,14 +138,10 @@ protected: ...@@ -138,14 +138,10 @@ protected:
OrientationPair orientationPairs[NB_ORIENPAIRS]; OrientationPair orientationPairs[NB_ORIENPAIRS];
}; };
static const double FREAK_LOG2 = 0.693147180559945; static const double FREAK_LOG2 = 0.693147180559945;
static const int FREAK_NB_ORIENTATION = 256; static const int FREAK_NB_ORIENTATION = 256;
static const int FREAK_NB_POINTS = 43; static const int FREAK_NB_POINTS = 43;
static const int FREAK_SMALLEST_KP_SIZE = 7; // smallest size of keypoints 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 // default pairs
static const int FREAK_DEF_PAIRS[FREAK_Impl::NB_PAIRS] = static const int FREAK_DEF_PAIRS[FREAK_Impl::NB_PAIRS] =
...@@ -209,8 +205,8 @@ void FREAK_Impl::buildPattern() ...@@ -209,8 +205,8 @@ void FREAK_Impl::buildPattern()
nOctaves0 = nOctaves; nOctaves0 = nOctaves;
patternScale0 = patternScale; patternScale0 = patternScale;
patternLookup.resize(FREAK_NB_SCALES*FREAK_NB_ORIENTATION*FREAK_NB_POINTS); 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 scaleStep = std::pow(2.0, (double)(nOctaves)/FREAK::NB_SCALES ); // 2 ^ ( (nOctaves-1) /nbScales)
double scalingFactor, alpha, beta, theta = 0; double scalingFactor, alpha, beta, theta = 0;
// pattern definition, radius normalized to 1.0 (outer point position+sigma=1.0) // pattern definition, radius normalized to 1.0 (outer point position+sigma=1.0)
...@@ -226,7 +222,7 @@ void FREAK_Impl::buildPattern() ...@@ -226,7 +222,7 @@ void FREAK_Impl::buildPattern()
radius[6]/2.0, radius[6]/2.0 radius[6]/2.0, radius[6]/2.0
}; };
// fill the lookup table // 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 patternSizes[scaleIdx] = 0; // proper initialization
scalingFactor = std::pow(scaleStep,scaleIdx); //scale of the pattern, scaleStep ^ scaleIdx scalingFactor = std::pow(scaleStep,scaleIdx); //scale of the pattern, scaleStep ^ scaleIdx
...@@ -282,7 +278,7 @@ void FREAK_Impl::buildPattern() ...@@ -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[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; 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 dx = patternLookup[orientationPairs[m].i].x-patternLookup[orientationPairs[m].j].x;
const float dy = patternLookup[orientationPairs[m].i].y-patternLookup[orientationPairs[m].j].y; const float dy = patternLookup[orientationPairs[m].i].y-patternLookup[orientationPairs[m].j].y;
...@@ -305,9 +301,9 @@ void FREAK_Impl::buildPattern() ...@@ -305,9 +301,9 @@ void FREAK_Impl::buildPattern()
// Input vector provided // Input vector provided
if( !selectedPairs0.empty() ) 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)]; descriptionPairs[i] = allPairs[selectedPairs0.at(i)];
} }
else else
...@@ -317,7 +313,7 @@ void FREAK_Impl::buildPattern() ...@@ -317,7 +313,7 @@ void FREAK_Impl::buildPattern()
} }
else // default selected pairs 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]]; descriptionPairs[i] = allPairs[FREAK_DEF_PAIRS[i]];
} }
} }
...@@ -370,11 +366,11 @@ void FREAK_Impl::compute( InputArray _image, std::vector<KeyPoint>& keypoints, O ...@@ -370,11 +366,11 @@ void FREAK_Impl::compute( InputArray _image, std::vector<KeyPoint>& keypoints, O
template <typename srcMatType> template <typename srcMatType>
void FREAK_Impl::extractDescriptor(srcMatType *pointsValue, void ** ptr) void FREAK_Impl::extractDescriptor(srcMatType *pointsValue, void ** ptr)
{ {
std::bitset<FREAK_NB_PAIRS>** ptrScalar = (std::bitset<FREAK_NB_PAIRS>**) ptr; std::bitset<FREAK::NB_PAIRS>** ptrScalar = (std::bitset<FREAK::NB_PAIRS>**) ptr;
// extracting descriptor preserving the order of SSE version // extracting descriptor preserving the order of SSE version
int cnt = 0; 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--; ) for( int m = 8; m--; )
{ {
...@@ -396,7 +392,7 @@ void FREAK_Impl::extractDescriptor(uchar *pointsValue, void ** ptr) ...@@ -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) // 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; int cnt = 0;
for( int n = FREAK_NB_PAIRS/128; n-- ; ) for( int n = FREAK::NB_PAIRS/128; n-- ; )
{ {
__m128i result128 = _mm_setzero_si128(); __m128i result128 = _mm_setzero_si128();
for( int m = 128/16; m--; cnt += 16 ) for( int m = 128/16; m--; cnt += 16 )
...@@ -457,7 +453,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k ...@@ -457,7 +453,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
std::vector<int> kpScaleIdx(keypoints.size()); // used to save pattern scale index corresponding to each keypoints std::vector<int> kpScaleIdx(keypoints.size()); // used to save pattern scale index corresponding to each keypoints
const std::vector<int>::iterator ScaleIdxBegin = kpScaleIdx.begin(); // used in std::vector erase function const std::vector<int>::iterator ScaleIdxBegin = kpScaleIdx.begin(); // used in std::vector erase function
const std::vector<cv::KeyPoint>::iterator kpBegin = keypoints.begin(); // used in std::vector erase function const std::vector<cv::KeyPoint>::iterator kpBegin = keypoints.begin(); // used in std::vector erase function
const float sizeCst = static_cast<float>(FREAK_NB_SCALES/(FREAK_LOG2* nOctaves)); const float sizeCst = static_cast<float>(FREAK::NB_SCALES/(FREAK_LOG2* nOctaves));
srcMatType pointsValue[FREAK_NB_POINTS]; srcMatType pointsValue[FREAK_NB_POINTS];
int thetaIdx = 0; int thetaIdx = 0;
int direction0; int direction0;
...@@ -470,8 +466,8 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k ...@@ -470,8 +466,8 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
{ {
//Is k non-zero? If so, decrement it and continue" //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); kpScaleIdx[k] = std::max( (int)(std::log(keypoints[k].size/FREAK_SMALLEST_KP_SIZE)*sizeCst+0.5) ,0);
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]] || //check if the description at this specific position and scale fits inside the image 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]] || keypoints[k].pt.y <= patternSizes[kpScaleIdx[k]] ||
...@@ -490,9 +486,9 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k ...@@ -490,9 +486,9 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
for( size_t k = keypoints.size(); 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 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]] || if( keypoints[k].pt.x <= patternSizes[kpScaleIdx[k]] ||
keypoints[k].pt.y <= patternSizes[kpScaleIdx[k]] || keypoints[k].pt.y <= patternSizes[kpScaleIdx[k]] ||
...@@ -510,7 +506,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k ...@@ -510,7 +506,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
if( !extAll ) if( !extAll )
{ {
// extract the best comparisons only // 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)); _descriptors.setTo(Scalar::all(0));
Mat descriptors = _descriptors.getMat(); Mat descriptors = _descriptors.getMat();
...@@ -773,9 +769,9 @@ std::vector<int> FREAK_Impl::selectPairs(const std::vector<Mat>& images ...@@ -773,9 +769,9 @@ std::vector<int> FREAK_Impl::selectPairs(const std::vector<Mat>& images
} }
std::vector<int> idxBestPairs; std::vector<int> 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); idxBestPairs.push_back(bestPairs[i].idx);
} }
else else
...@@ -827,7 +823,7 @@ FREAK_Impl::~FREAK_Impl() ...@@ -827,7 +823,7 @@ FREAK_Impl::~FREAK_Impl()
int FREAK_Impl::descriptorSize() const 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 int FREAK_Impl::descriptorType() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment