Skip to content

Commit cdbdb57

Browse files
acyensovrasov
authored andcommitted
Fix tests to work transparently with OpenCL SURF.
1 parent 66843d9 commit cdbdb57

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

modules/xfeatures2d/test/test_features2d.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ class CV_DescriptorExtractorTest : public cvtest::BaseTest
357357
}
358358

359359
if(imgLoadMode == IMREAD_GRAYSCALE)
360-
image.create( 50, 50, CV_8UC1 );
360+
image.create( 256, 256, CV_8UC1 );
361361
else
362-
image.create( 50, 50, CV_8UC3 );
362+
image.create( 256, 256, CV_8UC3 );
363363
try
364364
{
365365
dextractor->compute( image, keypoints, descriptors );
@@ -1187,7 +1187,7 @@ TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
11871187
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");
11881188
ASSERT_TRUE(matcher != NULL);
11891189

1190-
Mat imgT(sz, sz, CV_8U, Scalar(255));
1190+
Mat imgT(256, 256, CV_8U, Scalar(255));
11911191
line(imgT, Point(20, sz/2), Point(sz-21, sz/2), Scalar(100), 2);
11921192
line(imgT, Point(sz/2, 20), Point(sz/2, sz-21), Scalar(100), 2);
11931193
vector<KeyPoint> kpT;
@@ -1196,7 +1196,7 @@ TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
11961196
Mat descT;
11971197
ext->compute(imgT, kpT, descT);
11981198

1199-
Mat imgQ(sz, sz, CV_8U, Scalar(255));
1199+
Mat imgQ(256, 256, CV_8U, Scalar(255));
12001200
line(imgQ, Point(30, sz/2), Point(sz-31, sz/2), Scalar(100), 3);
12011201
line(imgQ, Point(sz/2, 30), Point(sz/2, sz-31), Scalar(100), 3);
12021202
vector<KeyPoint> kpQ;

modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ void matchKeyPoints(const vector<KeyPoint>& keypoints0, const Mat& H,
168168
const float r0 = 0.5f * keypoints0[i0].size;
169169
for(size_t i1 = 0; i1 < keypoints1.size(); i1++)
170170
{
171-
if(nearestPointIndex >= 0 && usedMask[i1])
172-
continue;
173-
174171
float r1 = 0.5f * keypoints1[i1].size;
175172
float intersectRatio = calcIntersectRatio(points0t.at<Point2f>(i0), r0,
176173
keypoints1[i1].pt, r1);
@@ -619,7 +616,7 @@ class DescriptorScaleInvarianceTest : public cvtest::BaseTest
619616
TEST(Features2d_RotationInvariance_Detector_SURF, regression)
620617
{
621618
DetectorRotationInvarianceTest test(SURF::create(),
622-
0.44f,
619+
0.65f,
623620
0.76f);
624621
test.safe_run();
625622
}
@@ -859,10 +856,21 @@ TEST(Features2d_RotationInvariance2_Detector_SURF, regression)
859856
vector<KeyPoint> keypoints;
860857
surf->detect(cross, keypoints);
861858

859+
// Expect 5 keypoints. One keypoint has coordinates (50.0, 50.0).
860+
// The other 4 keypoints should have the same response.
861+
// The order of the keypoints is indeterminate.
862862
ASSERT_EQ(keypoints.size(), (vector<KeyPoint>::size_type) 5);
863-
ASSERT_LT( fabs(keypoints[1].response - keypoints[2].response), 1e-6);
864-
ASSERT_LT( fabs(keypoints[1].response - keypoints[3].response), 1e-6);
865-
ASSERT_LT( fabs(keypoints[1].response - keypoints[4].response), 1e-6);
863+
864+
int i1 = -1;
865+
for(int i = 0; i < 5; i++)
866+
{
867+
if(keypoints[i].pt.x == 50.0f)
868+
;
869+
else if(i1 == -1)
870+
i1 = i;
871+
else
872+
ASSERT_LT(fabs(keypoints[i1].response - keypoints[i].response) / keypoints[i1].response, 1e-6);
873+
}
866874
}
867875

868876
TEST(DISABLED_Features2d_ScaleInvariance_Descriptor_DAISY, regression)

modules/xfeatures2d/test/test_surf.ocl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ IMPLEMENT_PARAM_CLASS(Upright, bool)
119119

120120
PARAM_TEST_CASE(SURF, HessianThreshold, Octaves, OctaveLayers, Extended, Upright)
121121
{
122+
bool useOpenCL;
122123
double hessianThreshold;
123124
int nOctaves;
124125
int nOctaveLayers;
@@ -127,12 +128,18 @@ PARAM_TEST_CASE(SURF, HessianThreshold, Octaves, OctaveLayers, Extended, Upright
127128

128129
virtual void SetUp()
129130
{
131+
useOpenCL = cv::ocl::useOpenCL();
130132
hessianThreshold = get<0>(GetParam());
131133
nOctaves = get<1>(GetParam());
132134
nOctaveLayers = get<2>(GetParam());
133135
extended = get<3>(GetParam());
134136
upright = get<4>(GetParam());
135137
}
138+
139+
virtual void TearDown()
140+
{
141+
cv::ocl::setUseOpenCL(useOpenCL);
142+
}
136143
};
137144

138145
TEST_P(SURF, Detector)

0 commit comments

Comments
 (0)