Commit 85c904a4 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

fixed build in gpu module (SURF and ORB)

parent 46248851
......@@ -3,7 +3,7 @@ if(ANDROID OR IOS)
endif()
set(the_description "GPU-accelerated Computer Vision")
ocv_add_module(gpu opencv_imgproc opencv_calib3d opencv_objdetect opencv_video)
ocv_add_module(gpu opencv_imgproc opencv_calib3d opencv_objdetect opencv_video opencv_nonfree)
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/cuda")
......
......@@ -1566,13 +1566,12 @@ public:
void releaseMemory();
// SURF parameters;
int extended;
int upright;
// SURF parameters
double hessianThreshold;
int nOctaves;
int nOctaveLayers;
int nOctaves;
int nOctaveLayers;
bool extended;
bool upright;
//! max keypoints = min(keypointsRatio * img.size().area(), 65535)
float keypointsRatio;
......@@ -1662,9 +1661,8 @@ public:
};
//! Constructor
//! n_features - the number of desired features
//! detector_params - parameters to use
explicit ORB_GPU(size_t n_features = 500, float scaleFactor = 1.2f, int nlevels = 3);
explicit ORB_GPU(int nFeatures = 500, float scaleFactor = 1.2f, int nLevels = 3, int edgeThreshold = 31,
int firstLevel = 0, int WTA_K = 2, int scoreType = 0, int patchSize = 31);
//! Compute the ORB features on an image
//! image - the image to compute the features (supports only CV_8UC1 images)
......@@ -1690,7 +1688,6 @@ public:
//! returns the descriptor size in bytes
inline int descriptorSize() const { return kBytes; }
void setParams(size_t n_features, float scaleFactor, int nlevels);
inline void setFastParams(int threshold, bool nonmaxSupression = true)
{
fastDetector_.threshold = threshold;
......@@ -1714,7 +1711,14 @@ private:
void mergeKeyPoints(GpuMat& keypoints);
ORB params_;
int nFeatures_;
float scaleFactor_;
int nLevels_;
int edgeThreshold_;
int firstLevel_;
int WTA_K_;
int scoreType_;
int patchSize_;
// The number of desired features per scale
std::vector<size_t> n_features_per_level_;
......
This diff is collapsed.
......@@ -109,32 +109,26 @@ namespace
return (HAAR_SIZE0 + HAAR_SIZE_INC * layer) << octave;
}
class SURF_GPU_Invoker : private CvSURFParams
class SURF_GPU_Invoker
{
public:
SURF_GPU_Invoker(SURF_GPU& surf, const GpuMat& img, const GpuMat& mask) :
CvSURFParams(surf),
sum(surf.sum), mask1(surf.mask1), maskSum(surf.maskSum), intBuffer(surf.intBuffer), det(surf.det), trace(surf.trace),
maxPosBuffer(surf.maxPosBuffer),
surf_(surf),
img_cols(img.cols), img_rows(img.rows),
use_mask(!mask.empty())
{
CV_Assert(!img.empty() && img.type() == CV_8UC1);
CV_Assert(mask.empty() || (mask.size() == img.size() && mask.type() == CV_8UC1));
CV_Assert(nOctaves > 0 && nOctaveLayers > 0);
CV_Assert(surf_.nOctaves > 0 && surf_.nOctaveLayers > 0);
CV_Assert(TargetArchs::builtWith(GLOBAL_ATOMICS) && DeviceInfo().supports(GLOBAL_ATOMICS));
const int min_size = calcSize(nOctaves - 1, 0);
const int min_size = calcSize(surf_.nOctaves - 1, 0);
CV_Assert(img_rows - min_size >= 0);
CV_Assert(img_cols - min_size >= 0);
const int layer_rows = img_rows >> (nOctaves - 1);
const int layer_cols = img_cols >> (nOctaves - 1);
const int min_margin = ((calcSize((nOctaves - 1), 2) >> 1) >> (nOctaves - 1)) + 1;
const int layer_rows = img_rows >> (surf_.nOctaves - 1);
const int layer_cols = img_cols >> (surf_.nOctaves - 1);
const int min_margin = ((calcSize((surf_.nOctaves - 1), 2) >> 1) >> (surf_.nOctaves - 1)) + 1;
CV_Assert(layer_rows - 2 * min_margin > 0);
CV_Assert(layer_cols - 2 * min_margin > 0);
......@@ -143,44 +137,44 @@ namespace
CV_Assert(maxFeatures > 0);
counters.create(1, nOctaves + 1, CV_32SC1);
counters.create(1, surf_.nOctaves + 1, CV_32SC1);
counters.setTo(Scalar::all(0));
loadGlobalConstants(maxCandidates, maxFeatures, img_rows, img_cols, nOctaveLayers, static_cast<float>(hessianThreshold));
loadGlobalConstants(maxCandidates, maxFeatures, img_rows, img_cols, surf_.nOctaveLayers, static_cast<float>(surf_.hessianThreshold));
bindImgTex(img);
integralBuffered(img, sum, intBuffer);
bindSumTex(sum);
integralBuffered(img, surf_.sum, surf_.intBuffer);
bindSumTex(surf_.sum);
if (use_mask)
{
min(mask, 1.0, mask1);
integralBuffered(mask1, maskSum, intBuffer);
bindMaskSumTex(maskSum);
min(mask, 1.0, surf_.mask1);
integralBuffered(surf_.mask1, surf_.maskSum, surf_.intBuffer);
bindMaskSumTex(surf_.maskSum);
}
}
void detectKeypoints(GpuMat& keypoints)
{
ensureSizeIsEnough(img_rows * (nOctaveLayers + 2), img_cols, CV_32FC1, det);
ensureSizeIsEnough(img_rows * (nOctaveLayers + 2), img_cols, CV_32FC1, trace);
ensureSizeIsEnough(img_rows * (surf_.nOctaveLayers + 2), img_cols, CV_32FC1, surf_.det);
ensureSizeIsEnough(img_rows * (surf_.nOctaveLayers + 2), img_cols, CV_32FC1, surf_.trace);
ensureSizeIsEnough(1, maxCandidates, CV_32SC4, maxPosBuffer);
ensureSizeIsEnough(1, maxCandidates, CV_32SC4, surf_.maxPosBuffer);
ensureSizeIsEnough(SURF_GPU::SF_FEATURE_STRIDE, maxFeatures, CV_32FC1, keypoints);
keypoints.setTo(Scalar::all(0));
for (int octave = 0; octave < nOctaves; ++octave)
for (int octave = 0; octave < surf_.nOctaves; ++octave)
{
const int layer_rows = img_rows >> octave;
const int layer_cols = img_cols >> octave;
loadOctaveConstants(octave, layer_rows, layer_cols);
icvCalcLayerDetAndTrace_gpu(det, trace, img_rows, img_cols, octave, nOctaveLayers);
icvCalcLayerDetAndTrace_gpu(surf_.det, surf_.trace, img_rows, img_cols, octave, surf_.nOctaveLayers);
icvFindMaximaInLayer_gpu(det, trace, maxPosBuffer.ptr<int4>(), counters.ptr<unsigned int>() + 1 + octave,
img_rows, img_cols, octave, use_mask, nOctaveLayers);
icvFindMaximaInLayer_gpu(surf_.det, surf_.trace, surf_.maxPosBuffer.ptr<int4>(), counters.ptr<unsigned int>() + 1 + octave,
img_rows, img_cols, octave, use_mask, surf_.nOctaveLayers);
unsigned int maxCounter;
cudaSafeCall( cudaMemcpy(&maxCounter, counters.ptr<unsigned int>() + 1 + octave, sizeof(unsigned int), cudaMemcpyDeviceToHost) );
......@@ -188,7 +182,7 @@ namespace
if (maxCounter > 0)
{
icvInterpolateKeypoint_gpu(det, maxPosBuffer.ptr<int4>(), maxCounter,
icvInterpolateKeypoint_gpu(surf_.det, surf_.maxPosBuffer.ptr<int4>(), maxCounter,
keypoints.ptr<float>(SURF_GPU::SF_X), keypoints.ptr<float>(SURF_GPU::SF_Y),
keypoints.ptr<int>(SURF_GPU::SF_LAPLACIAN), keypoints.ptr<float>(SURF_GPU::SF_SIZE),
keypoints.ptr<float>(SURF_GPU::SF_HESSIAN), counters.ptr<unsigned int>());
......@@ -200,7 +194,7 @@ namespace
keypoints.cols = featureCounter;
if (upright)
if (surf_.upright)
keypoints.row(SURF_GPU::SF_DIR).setTo(Scalar::all(90.0));
else
findOrientation(keypoints);
......@@ -228,15 +222,7 @@ namespace
}
private:
GpuMat& sum;
GpuMat& mask1;
GpuMat& maskSum;
GpuMat& intBuffer;
GpuMat& det;
GpuMat& trace;
GpuMat& maxPosBuffer;
SURF_GPU& surf_;
int img_cols, img_rows;
......@@ -306,7 +292,7 @@ void cv::gpu::SURF_GPU::uploadKeypoints(const vector<KeyPoint>& keypoints, GpuMa
namespace
{
int getPointOctave(float size, const CvSURFParams& params)
int getPointOctave(float size, const SURF_GPU& params)
{
int best_octave = 0;
float min_diff = numeric_limits<float>::max();
......
......@@ -61,6 +61,7 @@
#include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "utility.hpp"
#include "interpolation.hpp"
......
......@@ -385,7 +385,7 @@ TEST_P(Sqrt, Array)
gpuRes.download(dst);
EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
EXPECT_MAT_NEAR(dst_gold, dst, 1e-6);
}
INSTANTIATE_TEST_CASE_P(Arithm, Sqrt, Combine(
......
......@@ -96,16 +96,16 @@ struct SURF : TestWithParam<cv::gpu::DeviceInfo>
devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
image = readImage("features2d/aloe.png", CV_LOAD_IMAGE_GRAYSCALE);
ASSERT_FALSE(image.empty());
ASSERT_FALSE(image.empty());
mask = cv::Mat(image.size(), CV_8UC1, cv::Scalar::all(1));
mask(cv::Range(0, image.rows / 2), cv::Range(0, image.cols / 2)).setTo(cv::Scalar::all(0));
cv::SURF fdetector_gold;
cv::SURF fdetector_gold;
fdetector_gold.extended = false;
fdetector_gold(image, mask, keypoints_gold, descriptors_gold);
fdetector_gold(image, mask, keypoints_gold, descriptors_gold);
}
};
......@@ -135,7 +135,7 @@ TEST_P(SURF, Accuracy)
dev_descriptors.download(descriptors);
cv::BruteForceMatcher< cv::L2<float> > matcher;
cv::BFMatcher matcher(cv::NORM_L2);
std::vector<cv::DMatch> matches;
matcher.match(cv::Mat(static_cast<int>(keypoints_gold.size()), 64, CV_32FC1, &descriptors_gold[0]), descriptors, matches);
......@@ -696,7 +696,7 @@ TEST_P(ORB, Accuracy)
d_descriptors.download(descriptors);
cv::BruteForceMatcher<cv::Hamming> matcher;
cv::BFMatcher matcher(cv::NORM_HAMMING);
std::vector<cv::DMatch> matches;
matcher.match(descriptors_gold, descriptors, matches);
......
......@@ -334,6 +334,9 @@ PARAM_TEST_CASE(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, UseRoi)
TEST_P(GaussianBlur, Rgba)
{
if (!devInfo.supports(cv::gpu::FEATURE_SET_COMPUTE_20) && ksize.height > 16)
return;
cv::Mat dst_rgba;
cv::gpu::GpuMat dev_dst_rgba;
......@@ -347,6 +350,9 @@ TEST_P(GaussianBlur, Rgba)
TEST_P(GaussianBlur, Gray)
{
if (!devInfo.supports(cv::gpu::FEATURE_SET_COMPUTE_20) && ksize.height > 16)
return;
cv::Mat dst_gray;
cv::gpu::GpuMat dev_dst_gray;
......
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