Skip to content

Commit 4064d4c

Browse files
authored
Merge pull request opencv#17618 from Yosshi999:gsoc_sift-better-test
Added/Fixed testcases for SIFT * merge perf_sift into conventional perf tests * Fix disabled SIFT scale invariance tests allows trainIdx duplication in matching scaled keypoints
1 parent 6259ba1 commit 4064d4c

File tree

6 files changed

+43
-97
lines changed

6 files changed

+43
-97
lines changed

modules/features2d/include/opencv2/features2d.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ class CV_EXPORTS_W SIFT : public Feature2D
261261
@param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform
262262
(low-contrast) regions. The larger the threshold, the less features are produced by the detector.
263263
264+
@note The contrast threshold will be divided by nOctaveLayers when the filtering is applied. When
265+
nOctaveLayers is set to default and if you want to use the value used in D. Lowe paper, 0.03, set
266+
this argument to 0.09.
267+
264268
@param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning
265269
is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are
266270
filtered out (more features are retained).
@@ -271,6 +275,8 @@ class CV_EXPORTS_W SIFT : public Feature2D
271275
CV_WRAP static Ptr<SIFT> create(int nfeatures = 0, int nOctaveLayers = 3,
272276
double contrastThreshold = 0.04, double edgeThreshold = 10,
273277
double sigma = 1.6);
278+
279+
CV_WRAP virtual String getDefaultName() const CV_OVERRIDE;
274280
};
275281

276282
typedef SIFT SiftFeatureDetector;

modules/features2d/perf/perf_feature2d.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace opencv_test
2121
ORB_DEFAULT, ORB_1500_13_1, \
2222
AKAZE_DEFAULT, AKAZE_DESCRIPTOR_KAZE, \
2323
BRISK_DEFAULT, \
24-
KAZE_DEFAULT
24+
KAZE_DEFAULT, \
25+
SIFT_DEFAULT
2526

2627
#define CV_ENUM_EXPAND(name, ...) CV_ENUM(name, __VA_ARGS__)
2728

@@ -77,6 +78,8 @@ static inline Ptr<Feature2D> getFeature2D(Feature2DType type)
7778
return KAZE::create();
7879
case MSER_DEFAULT:
7980
return MSER::create();
81+
case SIFT_DEFAULT:
82+
return SIFT::create();
8083
default:
8184
return Ptr<Feature2D>();
8285
}

modules/features2d/perf/perf_sift.cpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

modules/features2d/src/sift.dispatch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ Ptr<SIFT> SIFT::create( int _nfeatures, int _nOctaveLayers,
126126
return makePtr<SIFT_Impl>(_nfeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma);
127127
}
128128

129+
String SIFT::getDefaultName() const
130+
{
131+
return (Feature2D::getDefaultName() + ".SIFT");
132+
}
133+
129134
static inline void
130135
unpackOctave(const KeyPoint& kpt, int& octave, int& layer, float& scale)
131136
{

modules/features2d/test/test_descriptors_invariance.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ const static std::string IMAGE_TSUKUBA = "features2d/tsukuba.png";
1515
const static std::string IMAGE_BIKES = "detectors_descriptors_evaluation/images_datasets/bikes/img1.png";
1616
#define Value(...) Values(String_FeatureDetector_DescriptorExtractor_Float_t(__VA_ARGS__))
1717

18+
static
19+
void SetSuitableSIFTOctave(vector<KeyPoint>& keypoints,
20+
int firstOctave = -1, int nOctaveLayers = 3, double sigma = 1.6)
21+
{
22+
for (size_t i = 0; i < keypoints.size(); i++ )
23+
{
24+
int octv, layer;
25+
KeyPoint& kpt = keypoints[i];
26+
double octv_layer = std::log(kpt.size / sigma) / std::log(2.) - 1;
27+
octv = cvFloor(octv_layer);
28+
layer = cvRound( (octv_layer - octv) * nOctaveLayers );
29+
if (octv < firstOctave)
30+
{
31+
octv = firstOctave;
32+
layer = 0;
33+
}
34+
kpt.octave = (layer << 8) | (octv & 255);
35+
}
36+
}
37+
1838
static
1939
void rotateKeyPoints(const vector<KeyPoint>& src, const Mat& H, float angle, vector<KeyPoint>& dst)
2040
{
@@ -132,6 +152,10 @@ TEST_P(DescriptorScaleInvariance, scale)
132152

133153
vector<KeyPoint> keypoints1;
134154
scaleKeyPoints(keypoints0, keypoints1, 1.0f/scale);
155+
if (featureDetector->getDefaultName() == "Feature2D.SIFT")
156+
{
157+
SetSuitableSIFTOctave(keypoints1);
158+
}
135159
Mat descriptors1;
136160
descriptorExtractor->compute(image1, keypoints1, descriptors1);
137161

@@ -186,9 +210,8 @@ INSTANTIATE_TEST_CASE_P(AKAZE_DESCRIPTOR_KAZE, DescriptorRotationInvariance,
186210
* Descriptor's scale invariance check
187211
*/
188212

189-
// TODO: Expected: (descInliersRatio) >= (minInliersRatio), actual: 0.330378 vs 0.78
190-
INSTANTIATE_TEST_CASE_P(DISABLED_SIFT, DescriptorScaleInvariance,
191-
Value(IMAGE_BIKES, SIFT::create(), SIFT::create(), 0.78f));
213+
INSTANTIATE_TEST_CASE_P(SIFT, DescriptorScaleInvariance,
214+
Value(IMAGE_BIKES, SIFT::create(0, 3, 0.09), SIFT::create(0, 3, 0.09), 0.78f));
192215

193216
INSTANTIATE_TEST_CASE_P(AKAZE, DescriptorScaleInvariance,
194217
Value(IMAGE_BIKES, AKAZE::create(), AKAZE::create(), 0.6f));

modules/features2d/test/test_detectors_invariance.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@ void matchKeyPoints(const vector<KeyPoint>& keypoints0, const Mat& H,
2929
perspectiveTransform(Mat(points0), points0t, H);
3030

3131
matches.clear();
32-
vector<uchar> usedMask(keypoints1.size(), 0);
3332
for(int i0 = 0; i0 < static_cast<int>(keypoints0.size()); i0++)
3433
{
3534
int nearestPointIndex = -1;
3635
float maxIntersectRatio = 0.f;
3736
const float r0 = 0.5f * keypoints0[i0].size;
3837
for(size_t i1 = 0; i1 < keypoints1.size(); i1++)
3938
{
40-
if(nearestPointIndex >= 0 && usedMask[i1])
41-
continue;
4239

4340
float r1 = 0.5f * keypoints1[i1].size;
4441
float intersectRatio = calcIntersectRatio(points0t.at<Point2f>(i0), r0,
@@ -51,8 +48,6 @@ void matchKeyPoints(const vector<KeyPoint>& keypoints0, const Mat& H,
5148
}
5249

5350
matches.push_back(DMatch(i0, nearestPointIndex, maxIntersectRatio));
54-
if(nearestPointIndex >= 0)
55-
usedMask[nearestPointIndex] = 1;
5651
}
5752
}
5853

@@ -239,9 +234,8 @@ INSTANTIATE_TEST_CASE_P(AKAZE_DESCRIPTOR_KAZE, DetectorRotationInvariance,
239234
* Detector's scale invariance check
240235
*/
241236

242-
// TODO: Expected: (keyPointMatchesRatio) >= (minKeyPointMatchesRatio), actual: 0.596752 vs 0.69
243-
INSTANTIATE_TEST_CASE_P(DISABLED_SIFT, DetectorScaleInvariance,
244-
Value(IMAGE_BIKES, SIFT::create(), 0.69f, 0.98f));
237+
INSTANTIATE_TEST_CASE_P(SIFT, DetectorScaleInvariance,
238+
Value(IMAGE_BIKES, SIFT::create(0, 3, 0.09), 0.69f, 0.98f));
245239

246240
INSTANTIATE_TEST_CASE_P(BRISK, DetectorScaleInvariance,
247241
Value(IMAGE_BIKES, BRISK::create(), 0.08f, 0.49f));

0 commit comments

Comments
 (0)