replaced SIFT implementation (Some default parameters can be changed in the near future)
This commit is contained in:
parent
8c0c773bf2
commit
035fd0019b
@ -269,7 +269,7 @@ CV_EXPORTS void read(const FileNode& node, CV_OUT vector<KeyPoint>& keypoints);
|
|||||||
/*
|
/*
|
||||||
* A class filters a vector of keypoints.
|
* 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,
|
* Because now it is difficult to provide a convenient interface for all usage scenarios of the keypoints filter class,
|
||||||
* it has only 3 needed by now static methods.
|
* it has only 4 needed by now static methods.
|
||||||
*/
|
*/
|
||||||
class CV_EXPORTS KeyPointsFilter
|
class CV_EXPORTS KeyPointsFilter
|
||||||
{
|
{
|
||||||
@ -288,6 +288,10 @@ public:
|
|||||||
* Remove keypoints from some image by mask for pixels of this image.
|
* Remove keypoints from some image by mask for pixels of this image.
|
||||||
*/
|
*/
|
||||||
static void runByPixelsMask( vector<KeyPoint>& keypoints, const Mat& mask );
|
static void runByPixelsMask( vector<KeyPoint>& keypoints, const Mat& mask );
|
||||||
|
/*
|
||||||
|
* Remove duplicated keypoints.
|
||||||
|
*/
|
||||||
|
static void removeDuplicated( vector<KeyPoint>& keypoints );
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -295,6 +299,7 @@ public:
|
|||||||
|
|
||||||
The class implements SIFT algorithm by D. Lowe.
|
The class implements SIFT algorithm by D. Lowe.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CV_EXPORTS SIFT
|
class CV_EXPORTS SIFT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -306,14 +311,15 @@ public:
|
|||||||
enum { FIRST_ANGLE = 0, AVERAGE_ANGLE = 1 };
|
enum { FIRST_ANGLE = 0, AVERAGE_ANGLE = 1 };
|
||||||
|
|
||||||
CommonParams();
|
CommonParams();
|
||||||
CommonParams( int _nOctaves, int _nOctaveLayers, int _firstOctave, int _angleMode );
|
CommonParams( int _nOctaves, int _nOctaveLayers, int /*_firstOctave*/, int /*_angleMode*/ );
|
||||||
int nOctaves, nOctaveLayers, firstOctave;
|
int nOctaves, nOctaveLayers;
|
||||||
int angleMode;
|
int firstOctave; // it is not used now (firstOctave == 0 always)
|
||||||
|
int angleMode; // it is not used now
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CV_EXPORTS DetectorParams
|
struct CV_EXPORTS DetectorParams
|
||||||
{
|
{
|
||||||
static double GET_DEFAULT_THRESHOLD() { return 0.04 / SIFT::CommonParams::DEFAULT_NOCTAVE_LAYERS / 2.0; }
|
static double GET_DEFAULT_THRESHOLD() { return 0.04; }
|
||||||
static double GET_DEFAULT_EDGE_THRESHOLD() { return 10.0; }
|
static double GET_DEFAULT_EDGE_THRESHOLD() { return 10.0; }
|
||||||
|
|
||||||
DetectorParams();
|
DetectorParams();
|
||||||
@ -328,9 +334,10 @@ public:
|
|||||||
static const int DESCRIPTOR_SIZE = 128;
|
static const int DESCRIPTOR_SIZE = 128;
|
||||||
|
|
||||||
DescriptorParams();
|
DescriptorParams();
|
||||||
DescriptorParams( double _magnification, bool _isNormalize, bool _recalculateAngles );
|
DescriptorParams( double _magnification, bool /*_isNormalize*/, bool _recalculateAngles );
|
||||||
|
DescriptorParams( bool _recalculateAngles );
|
||||||
double magnification;
|
double magnification;
|
||||||
bool isNormalize;
|
bool isNormalize; // it is not used now (true always)
|
||||||
bool recalculateAngles;
|
bool recalculateAngles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -234,4 +234,65 @@ void KeyPointsFilter::runByPixelsMask( vector<KeyPoint>& keypoints, const Mat& m
|
|||||||
keypoints.erase(remove_if(keypoints.begin(), keypoints.end(), MaskPredicate(mask)), keypoints.end());
|
keypoints.erase(remove_if(keypoints.begin(), keypoints.end(), MaskPredicate(mask)), keypoints.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct KeyPoint_LessThan
|
||||||
|
{
|
||||||
|
KeyPoint_LessThan(const vector<KeyPoint>& _kp) : kp(&_kp) {}
|
||||||
|
bool operator()(int i, int j) const
|
||||||
|
{
|
||||||
|
const KeyPoint& kp1 = (*kp)[i];
|
||||||
|
const KeyPoint& kp2 = (*kp)[j];
|
||||||
|
if( kp1.pt.x != kp2.pt.x )
|
||||||
|
return kp1.pt.x < kp2.pt.x;
|
||||||
|
if( kp1.pt.y != kp2.pt.y )
|
||||||
|
return kp1.pt.y < kp2.pt.y;
|
||||||
|
if( kp1.size != kp2.size )
|
||||||
|
return kp1.size > kp2.size;
|
||||||
|
if( kp1.size != kp2.size )
|
||||||
|
return kp1.size > kp2.size;
|
||||||
|
if( kp1.angle != kp2.angle )
|
||||||
|
return kp1.angle < kp2.angle;
|
||||||
|
if( kp1.response != kp2.response )
|
||||||
|
return kp1.response > kp2.response;
|
||||||
|
if( kp1.octave != kp2.octave )
|
||||||
|
return kp1.octave > kp2.octave;
|
||||||
|
if( kp1.class_id != kp2.class_id )
|
||||||
|
return kp1.class_id > kp2.class_id;
|
||||||
|
|
||||||
|
return i < j;
|
||||||
|
}
|
||||||
|
const vector<KeyPoint>* kp;
|
||||||
|
};
|
||||||
|
|
||||||
|
void KeyPointsFilter::removeDuplicated( vector<KeyPoint>& keypoints )
|
||||||
|
{
|
||||||
|
int i, j, n = (int)keypoints.size();
|
||||||
|
vector<int> kpidx(n);
|
||||||
|
vector<uchar> mask(n, (uchar)1);
|
||||||
|
|
||||||
|
for( i = 0; i < n; i++ )
|
||||||
|
kpidx[i] = i;
|
||||||
|
std::sort(kpidx.begin(), kpidx.end(), KeyPoint_LessThan(keypoints));
|
||||||
|
for( i = 1, j = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
KeyPoint& kp1 = keypoints[kpidx[i]];
|
||||||
|
KeyPoint& kp2 = keypoints[kpidx[j]];
|
||||||
|
if( kp1.pt.x != kp2.pt.x || kp1.pt.y != kp2.pt.y ||
|
||||||
|
kp1.size != kp2.size || kp1.angle != kp2.angle )
|
||||||
|
j = i;
|
||||||
|
else
|
||||||
|
mask[kpidx[i]] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( i = j = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
if( mask[i] )
|
||||||
|
{
|
||||||
|
if( i != j )
|
||||||
|
keypoints[j] = keypoints[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keypoints.resize(j);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user