Commit 66843d98 authored by Albert's avatar Albert Committed by Vladislav Sovrasov

Fix opencv/opencv#4685. Fix opencv/opencv_contrib#433.

Enable SURF OCL. Fix incorrect calling sequence for two kernels.
Fix compiler warnings in surf.cl.
Enable SURF OCL test. Test runs with no failures.
parent b9541897
......@@ -1102,10 +1102,10 @@ void SURF_computeDescriptors128(
descriptors_step /= sizeof(*descriptors);
keypoints_step /= sizeof(*keypoints);
__global float * featureX = keypoints + X_ROW * keypoints_step;
__global float * featureY = keypoints + Y_ROW * keypoints_step;
__global float* featureSize = keypoints + SIZE_ROW * keypoints_step;
__global float* featureDir = keypoints + ANGLE_ROW * keypoints_step;
__global const float * featureX = keypoints + X_ROW * keypoints_step;
__global const float * featureY = keypoints + Y_ROW * keypoints_step;
__global const float* featureSize = keypoints + SIZE_ROW * keypoints_step;
__global const float* featureDir = keypoints + ANGLE_ROW * keypoints_step;
// 2 floats (dx,dy) for each thread (5x5 sample points in each sub-region)
volatile __local float sdx[25];
......
......@@ -91,11 +91,13 @@ bool SURF_OCL::init(const SURF_Impl* p)
if(ocl::haveOpenCL())
{
const ocl::Device& dev = ocl::Device::getDefault();
if( dev.type() == ocl::Device::TYPE_CPU || dev.doubleFPConfig() == 0 )
if( dev.type() == ocl::Device::TYPE_CPU )
return false;
haveImageSupport = false;//dev.imageSupport();
kerOpts = haveImageSupport ? "-D HAVE_IMAGE2D -D DOUBLE_SUPPORT" : "";
// status = 1;
haveImageSupport = dev.imageSupport();
kerOpts = format("%s%s",
haveImageSupport ? "-D HAVE_IMAGE2D" : "",
dev.doubleFPConfig() > 0? " -D DOUBLE_SUPPORT": "");
status = 1;
}
}
return status > 0;
......@@ -243,7 +245,7 @@ bool SURF_OCL::computeDescriptors(const UMat &keypoints, OutputArray _descriptor
}
size_t localThreads[] = {6, 6};
size_t globalThreads[] = {nFeatures*localThreads[0], localThreads[1]};
size_t globalThreads[] = {nFeatures*localThreads[0], 16 * localThreads[1]};
if(haveImageSupport)
{
......@@ -420,7 +422,7 @@ bool SURF_OCL::findMaximaInLayer(int counterOffset, int octave,
ocl::KernelArg::PtrReadWrite(maxPosBuffer),
ocl::KernelArg::PtrReadWrite(counters),
counterOffset, img_rows, img_cols,
octave, nOctaveLayers,
nOctaveLayers, octave,
layer_rows, layer_cols,
maxCandidates,
(float)params->hessianThreshold).run(2, globalThreads, localThreads, true);
......
......@@ -21,8 +21,8 @@
#include "opencv2/opencv_modules.hpp"
#include "cvconfig.h"
#ifdef HAVE_OPENCV_OCL
# include "opencv2/ocl.hpp"
#ifdef HAVE_OPENCL
# include "opencv2/core/ocl.hpp"
#endif
#ifdef HAVE_CUDA
......
......@@ -45,11 +45,13 @@
#include "test_precomp.hpp"
#ifdef HAVE_OPENCV_OCL
#ifdef HAVE_OPENCL
namespace cvtest {
namespace ocl {
using namespace std;
using std::tr1::get;
static bool keyPointsEquals(const cv::KeyPoint& p1, const cv::KeyPoint& p2)
{
const double maxPtDif = 0.1;
......@@ -133,31 +135,20 @@ PARAM_TEST_CASE(SURF, HessianThreshold, Octaves, OctaveLayers, Extended, Upright
}
};
TEST_P(SURF, DISABLED_Detector)
TEST_P(SURF, Detector)
{
cv::Mat image = cv::imread(string(cvtest::TS::ptr()->get_data_path()) + "shared/fruits.png", cv::IMREAD_GRAYSCALE);
cv::UMat image;
cv::ocl::setUseOpenCL(true);
cv::imread(string(cvtest::TS::ptr()->get_data_path()) + "shared/fruits.png", cv::IMREAD_GRAYSCALE).copyTo(image);
ASSERT_FALSE(image.empty());
cv::ocl::SURF_OCL surf;
surf.hessianThreshold = static_cast<float>(hessianThreshold);
surf.nOctaves = nOctaves;
surf.nOctaveLayers = nOctaveLayers;
surf.extended = extended;
surf.upright = upright;
surf.keypointsRatio = 0.05f;
cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create(hessianThreshold, nOctaves, nOctaveLayers, extended, upright);
std::vector<cv::KeyPoint> keypoints;
surf(cv::ocl::oclMat(image), cv::ocl::oclMat(), keypoints);
cv::SURF surf_gold;
surf_gold.hessianThreshold = hessianThreshold;
surf_gold.nOctaves = nOctaves;
surf_gold.nOctaveLayers = nOctaveLayers;
surf_gold.extended = extended;
surf_gold.upright = upright;
surf->detect(image, keypoints, cv::noArray());
cv::ocl::setUseOpenCL(false);
std::vector<cv::KeyPoint> keypoints_gold;
surf_gold(image, cv::noArray(), keypoints_gold);
surf->detect(image, keypoints_gold, cv::noArray());
ASSERT_EQ(keypoints_gold.size(), keypoints.size());
int matchedCount = getMatchedPointsCount(keypoints_gold, keypoints);
......@@ -166,38 +157,29 @@ TEST_P(SURF, DISABLED_Detector)
EXPECT_GT(matchedRatio, 0.99);
}
TEST_P(SURF, DISABLED_Descriptor)
TEST_P(SURF, Descriptor)
{
cv::Mat image = cv::imread(string(cvtest::TS::ptr()->get_data_path()) + "shared/fruits.png", cv::IMREAD_GRAYSCALE);
cv::UMat image;
cv::ocl::setUseOpenCL(true);
cv::imread(string(cvtest::TS::ptr()->get_data_path()) + "shared/fruits.png", cv::IMREAD_GRAYSCALE).copyTo(image);
ASSERT_FALSE(image.empty());
cv::ocl::SURF_OCL surf;
surf.hessianThreshold = static_cast<float>(hessianThreshold);
surf.nOctaves = nOctaves;
surf.nOctaveLayers = nOctaveLayers;
surf.extended = extended;
surf.upright = upright;
surf.keypointsRatio = 0.05f;
cv::SURF surf_gold;
surf_gold.hessianThreshold = hessianThreshold;
surf_gold.nOctaves = nOctaves;
surf_gold.nOctaveLayers = nOctaveLayers;
surf_gold.extended = extended;
surf_gold.upright = upright;
cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create(hessianThreshold, nOctaves, nOctaveLayers, extended, upright);
std::vector<cv::KeyPoint> keypoints;
surf_gold(image, cv::noArray(), keypoints);
surf->detect(image, keypoints, cv::noArray());
cv::UMat descriptors;
cv::ocl::oclMat descriptors;
surf(cv::ocl::oclMat(image), cv::ocl::oclMat(), keypoints, descriptors, true);
surf->detectAndCompute(image, cv::noArray(), keypoints, descriptors, true);
cv::ocl::setUseOpenCL(false);
cv::Mat descriptors_gold;
surf_gold(image, cv::noArray(), keypoints, descriptors_gold, true);
surf->detectAndCompute(image, cv::noArray(), keypoints, descriptors_gold, true);
cv::BFMatcher matcher(surf.defaultNorm());
cv::BFMatcher matcher(surf->defaultNorm());
std::vector<cv::DMatch> matches;
matcher.match(descriptors_gold, cv::Mat(descriptors), matches);
matcher.match(descriptors_gold, descriptors, matches);
int matchedCount = getMatchedPointsCount(keypoints, keypoints, matches);
double matchedRatio = static_cast<double>(matchedCount) / keypoints.size();
......@@ -212,4 +194,6 @@ INSTANTIATE_TEST_CASE_P(OCL_Features2D, SURF, testing::Combine(
testing::Values(Extended(false), Extended(true)),
testing::Values(Upright(false), Upright(true))));
#endif // HAVE_OPENCV_OCL
} } // namespace cvtest::ocl
#endif // HAVE_OPENCL
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment