diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index 854b89d2e8..a184358a41 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -1545,7 +1545,7 @@ namespace cv SURF_GPU(); //! the full constructor taking all the necessary parameters explicit SURF_GPU(double _hessianThreshold, int _nOctaves=4, - int _nOctaveLayers=2, bool _extended=false, float _keypointsRatio=0.01f); + int _nOctaveLayers=2, bool _extended=false, float _keypointsRatio=0.01f, bool _upright = false); //! returns the descriptor size in float's (64 or 128) int descriptorSize() const; @@ -1568,17 +1568,19 @@ namespace cv //! Optionally it can compute descriptors for the user-provided keypoints and recompute keypoints direction void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors, bool useProvidedKeypoints = false); - + void operator()(const GpuMat& img, const GpuMat& mask, std::vector& keypoints); void operator()(const GpuMat& img, const GpuMat& mask, std::vector& keypoints, GpuMat& descriptors, bool useProvidedKeypoints = false); - + void operator()(const GpuMat& img, const GpuMat& mask, std::vector& keypoints, std::vector& descriptors, bool useProvidedKeypoints = false); //! max keypoints = keypointsRatio * img.size().area() float keypointsRatio; + bool upright; + GpuMat sum, mask1, maskSum, intBuffer; GpuMat det, trace; diff --git a/modules/gpu/src/surf.cpp b/modules/gpu/src/surf.cpp index ffdaabb126..d1f18a763e 100644 --- a/modules/gpu/src/surf.cpp +++ b/modules/gpu/src/surf.cpp @@ -49,7 +49,7 @@ using namespace std; #if !defined (HAVE_CUDA) cv::gpu::SURF_GPU::SURF_GPU() { throw_nogpu(); } -cv::gpu::SURF_GPU::SURF_GPU(double, int, int, bool, float) { throw_nogpu(); } +cv::gpu::SURF_GPU::SURF_GPU(double, int, int, bool, float, bool) { throw_nogpu(); } int cv::gpu::SURF_GPU::descriptorSize() const { throw_nogpu(); return 0;} void cv::gpu::SURF_GPU::uploadKeypoints(const vector&, GpuMat&) { throw_nogpu(); } void cv::gpu::SURF_GPU::downloadKeypoints(const GpuMat&, vector&) { throw_nogpu(); } @@ -92,7 +92,9 @@ namespace img_cols(img.cols), img_rows(img.rows), - use_mask(!mask.empty()) + use_mask(!mask.empty()), + + upright(surf.upright) { CV_Assert(!img.empty() && img.type() == CV_8UC1); CV_Assert(mask.empty() || (mask.size() == img.size() && mask.type() == CV_8UC1)); @@ -176,7 +178,15 @@ namespace cudaSafeCall( cudaMemcpy(&featureCounter, d_counters, sizeof(unsigned int), cudaMemcpyDeviceToHost) ); featureCounter = std::min(featureCounter, static_cast(maxFeatures)); - findOrientation(featuresBuffer.colRange(0, featureCounter), keypoints); + if (!upright) + findOrientation(featuresBuffer.colRange(0, featureCounter), keypoints); + else + { + if (featureCounter > 0) + featuresBuffer.colRange(0, featureCounter).copyTo(keypoints); + else + keypoints.release(); + } } void findOrientation(const GpuMat& features, GpuMat& keypoints) @@ -225,6 +235,8 @@ namespace bool use_mask; + bool upright; + int maxCandidates; int maxFeatures; int maxKeypoints; @@ -240,15 +252,17 @@ cv::gpu::SURF_GPU::SURF_GPU() nOctaves = 4; nOctaveLayers = 2; keypointsRatio = 0.01f; + upright = false; } -cv::gpu::SURF_GPU::SURF_GPU(double _threshold, int _nOctaves, int _nOctaveLayers, bool _extended, float _keypointsRatio) +cv::gpu::SURF_GPU::SURF_GPU(double _threshold, int _nOctaves, int _nOctaveLayers, bool _extended, float _keypointsRatio, bool _upright) { hessianThreshold = _threshold; extended = _extended; nOctaves = _nOctaves; nOctaveLayers = _nOctaveLayers; keypointsRatio = _keypointsRatio; + upright = _upright; } int cv::gpu::SURF_GPU::descriptorSize() const @@ -387,7 +401,7 @@ void cv::gpu::SURF_GPU::operator()(const GpuMat& img, const GpuMat& mask, GpuMat if (!useProvidedKeypoints) surf.detectKeypoints(keypoints); - else + else if (!upright) { GpuMat keypointsBuf; surf.findOrientation(keypoints, keypointsBuf);