Skip to content

Commit e70b75b

Browse files
committed
Merge pull request opencv#8820 from woodychow:multithread_sift_findScaleSpaceExtrema
2 parents 8755a19 + 5a4f2b5 commit e70b75b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

modules/features2d/include/opencv2/features2d.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class CV_EXPORTS KeyPointsFilter
117117
* Remove duplicated keypoints.
118118
*/
119119
static void removeDuplicated( std::vector<KeyPoint>& keypoints );
120+
/*
121+
* Remove duplicated keypoints and sort the remaining keypoints
122+
*/
123+
static void removeDuplicatedSorted( std::vector<KeyPoint>& keypoints );
120124

121125
/*
122126
* Retain the specified number of the best keypoints (according to the response)

modules/features2d/src/keypoint.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,44 @@ void KeyPointsFilter::removeDuplicated( std::vector<KeyPoint>& keypoints )
223223
keypoints.resize(j);
224224
}
225225

226+
struct KeyPoint12_LessThan
227+
{
228+
bool operator()(const KeyPoint &kp1, const KeyPoint &kp2) const
229+
{
230+
if( kp1.pt.x != kp2.pt.x )
231+
return kp1.pt.x < kp2.pt.x;
232+
if( kp1.pt.y != kp2.pt.y )
233+
return kp1.pt.y < kp2.pt.y;
234+
if( kp1.size != kp2.size )
235+
return kp1.size > kp2.size;
236+
if( kp1.angle != kp2.angle )
237+
return kp1.angle < kp2.angle;
238+
if( kp1.response != kp2.response )
239+
return kp1.response > kp2.response;
240+
if( kp1.octave != kp2.octave )
241+
return kp1.octave > kp2.octave;
242+
return kp1.class_id > kp2.class_id;
243+
}
244+
};
245+
246+
void KeyPointsFilter::removeDuplicatedSorted( std::vector<KeyPoint>& keypoints )
247+
{
248+
int i, j, n = (int)keypoints.size();
249+
250+
if (n < 2) return;
251+
252+
std::sort(keypoints.begin(), keypoints.end(), KeyPoint12_LessThan());
253+
254+
for( i = 0, j = 1; j < n; ++j )
255+
{
256+
const KeyPoint& kp1 = keypoints[i];
257+
const KeyPoint& kp2 = keypoints[j];
258+
if( kp1.pt.x != kp2.pt.x || kp1.pt.y != kp2.pt.y ||
259+
kp1.size != kp2.size || kp1.angle != kp2.angle ) {
260+
keypoints[++i] = keypoints[j];
261+
}
262+
}
263+
keypoints.resize(i + 1);
264+
}
265+
226266
}

0 commit comments

Comments
 (0)