45
45
46
46
#include " test_precomp.hpp"
47
47
48
- #ifdef HAVE_OPENCV_OCL
48
+ #ifdef HAVE_OPENCL
49
+
50
+ namespace cvtest {
51
+ namespace ocl {
49
52
50
53
using namespace std ;
51
54
using std::tr1::get;
52
-
53
55
static bool keyPointsEquals (const cv::KeyPoint& p1, const cv::KeyPoint& p2)
54
56
{
55
57
const double maxPtDif = 0.1 ;
@@ -133,31 +135,20 @@ PARAM_TEST_CASE(SURF, HessianThreshold, Octaves, OctaveLayers, Extended, Upright
133
135
}
134
136
};
135
137
136
- TEST_P (SURF, DISABLED_Detector )
138
+ TEST_P (SURF, Detector )
137
139
{
138
- cv::Mat image = cv::imread (string (cvtest::TS::ptr ()->get_data_path ()) + " shared/fruits.png" , cv::IMREAD_GRAYSCALE);
140
+ cv::UMat image;
141
+ cv::ocl::setUseOpenCL (true );
142
+ cv::imread (string (cvtest::TS::ptr ()->get_data_path ()) + " shared/fruits.png" , cv::IMREAD_GRAYSCALE).copyTo (image);
139
143
ASSERT_FALSE (image.empty ());
140
144
141
- cv::ocl::SURF_OCL surf;
142
- surf.hessianThreshold = static_cast <float >(hessianThreshold);
143
- surf.nOctaves = nOctaves;
144
- surf.nOctaveLayers = nOctaveLayers;
145
- surf.extended = extended;
146
- surf.upright = upright;
147
- surf.keypointsRatio = 0 .05f ;
148
-
145
+ cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create (hessianThreshold, nOctaves, nOctaveLayers, extended, upright);
149
146
std::vector<cv::KeyPoint> keypoints;
150
- surf (cv::ocl::oclMat (image), cv::ocl::oclMat (), keypoints);
151
-
152
- cv::SURF surf_gold;
153
- surf_gold.hessianThreshold = hessianThreshold;
154
- surf_gold.nOctaves = nOctaves;
155
- surf_gold.nOctaveLayers = nOctaveLayers;
156
- surf_gold.extended = extended;
157
- surf_gold.upright = upright;
147
+ surf->detect (image, keypoints, cv::noArray ());
158
148
149
+ cv::ocl::setUseOpenCL (false );
159
150
std::vector<cv::KeyPoint> keypoints_gold;
160
- surf_gold (image, cv::noArray (), keypoints_gold );
151
+ surf-> detect (image, keypoints_gold, cv::noArray ());
161
152
162
153
ASSERT_EQ (keypoints_gold.size (), keypoints.size ());
163
154
int matchedCount = getMatchedPointsCount (keypoints_gold, keypoints);
@@ -166,38 +157,29 @@ TEST_P(SURF, DISABLED_Detector)
166
157
EXPECT_GT (matchedRatio, 0.99 );
167
158
}
168
159
169
- TEST_P (SURF, DISABLED_Descriptor )
160
+ TEST_P (SURF, Descriptor )
170
161
{
171
- cv::Mat image = cv::imread (string (cvtest::TS::ptr ()->get_data_path ()) + " shared/fruits.png" , cv::IMREAD_GRAYSCALE);
162
+ cv::UMat image;
163
+ cv::ocl::setUseOpenCL (true );
164
+ cv::imread (string (cvtest::TS::ptr ()->get_data_path ()) + " shared/fruits.png" , cv::IMREAD_GRAYSCALE).copyTo (image);
172
165
ASSERT_FALSE (image.empty ());
173
166
174
- cv::ocl::SURF_OCL surf;
175
- surf.hessianThreshold = static_cast <float >(hessianThreshold);
176
- surf.nOctaves = nOctaves;
177
- surf.nOctaveLayers = nOctaveLayers;
178
- surf.extended = extended;
179
- surf.upright = upright;
180
- surf.keypointsRatio = 0 .05f ;
181
-
182
- cv::SURF surf_gold;
183
- surf_gold.hessianThreshold = hessianThreshold;
184
- surf_gold.nOctaves = nOctaves;
185
- surf_gold.nOctaveLayers = nOctaveLayers;
186
- surf_gold.extended = extended;
187
- surf_gold.upright = upright;
167
+ cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create (hessianThreshold, nOctaves, nOctaveLayers, extended, upright);
188
168
189
169
std::vector<cv::KeyPoint> keypoints;
190
- surf_gold (image, cv::noArray (), keypoints);
170
+ surf->detect (image, keypoints, cv::noArray ());
171
+
172
+ cv::UMat descriptors;
191
173
192
- cv::ocl::oclMat descriptors;
193
- surf (cv::ocl::oclMat (image), cv::ocl::oclMat (), keypoints, descriptors, true );
174
+ surf->detectAndCompute (image, cv::noArray (), keypoints, descriptors, true );
194
175
176
+ cv::ocl::setUseOpenCL (false );
195
177
cv::Mat descriptors_gold;
196
- surf_gold (image, cv::noArray (), keypoints, descriptors_gold, true );
178
+ surf-> detectAndCompute (image, cv::noArray (), keypoints, descriptors_gold, true );
197
179
198
- cv::BFMatcher matcher (surf. defaultNorm ());
180
+ cv::BFMatcher matcher (surf-> defaultNorm ());
199
181
std::vector<cv::DMatch> matches;
200
- matcher.match (descriptors_gold, cv::Mat ( descriptors) , matches);
182
+ matcher.match (descriptors_gold, descriptors, matches);
201
183
202
184
int matchedCount = getMatchedPointsCount (keypoints, keypoints, matches);
203
185
double matchedRatio = static_cast <double >(matchedCount) / keypoints.size ();
@@ -212,4 +194,6 @@ INSTANTIATE_TEST_CASE_P(OCL_Features2D, SURF, testing::Combine(
212
194
testing::Values(Extended(false ), Extended(true )),
213
195
testing::Values(Upright(false ), Upright(true ))));
214
196
215
- #endif // HAVE_OPENCV_OCL
197
+ } } // namespace cvtest::ocl
198
+
199
+ #endif // HAVE_OPENCL
0 commit comments