2010-12-20 13:49:40 +01:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other GpuMaterials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or bpied warranties, including, but not limited to, the bpied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace cv::gpu;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#if !defined (HAVE_CUDA)
|
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
cv::gpu::SURF_GPU::SURF_GPU() { throw_nogpu(); }
|
|
|
|
cv::gpu::SURF_GPU::SURF_GPU(double, int, int, bool, float) { throw_nogpu(); }
|
2010-12-20 13:49:40 +01:00
|
|
|
int cv::gpu::SURF_GPU::descriptorSize() const { throw_nogpu(); return 0;}
|
|
|
|
void cv::gpu::SURF_GPU::uploadKeypoints(const vector<KeyPoint>&, GpuMat&) { throw_nogpu(); }
|
|
|
|
void cv::gpu::SURF_GPU::downloadKeypoints(const GpuMat&, vector<KeyPoint>&) { throw_nogpu(); }
|
|
|
|
void cv::gpu::SURF_GPU::downloadDescriptors(const GpuMat&, vector<float>&) { throw_nogpu(); }
|
2010-12-21 15:02:09 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat&, const GpuMat&, GpuMat&) { throw_nogpu(); }
|
2011-03-10 14:53:58 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, bool) { throw_nogpu(); }
|
2010-12-21 15:02:09 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat&, const GpuMat&, vector<KeyPoint>&) { throw_nogpu(); }
|
2011-03-10 14:53:58 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat&, const GpuMat&, vector<KeyPoint>&, GpuMat&, bool) { throw_nogpu(); }
|
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat&, const GpuMat&, vector<KeyPoint>&, vector<float>&, bool) { throw_nogpu(); }
|
2010-12-20 13:49:40 +01:00
|
|
|
|
|
|
|
#else /* !defined (HAVE_CUDA) */
|
|
|
|
|
|
|
|
namespace cv { namespace gpu { namespace surf
|
2011-02-09 10:11:11 +01:00
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
void icvCalcLayerDetAndTrace_gpu(const PtrStepf& det, const PtrStepf& trace, int img_rows, int img_cols, int octave, int nOctaveLayers);
|
|
|
|
|
|
|
|
void icvFindMaximaInLayer_gpu(const PtrStepf& det, const PtrStepf& trace, int4* maxPosBuffer, unsigned int* maxCounter,
|
|
|
|
int img_rows, int img_cols, int octave, bool use_mask, int nLayers);
|
|
|
|
|
|
|
|
void icvInterpolateKeypoint_gpu(const PtrStepf& det, const int4* maxPosBuffer, unsigned int maxCounter, KeyPoint_GPU* featuresBuffer, unsigned int* featureCounter);
|
|
|
|
|
|
|
|
void icvCalcOrientation_gpu(const KeyPoint_GPU* featureBuffer, int nFeatures, KeyPoint_GPU* keypoints, unsigned int* keypointCounter);
|
|
|
|
|
2010-12-20 13:49:40 +01:00
|
|
|
void compute_descriptors_gpu(const DevMem2Df& descriptors, const KeyPoint_GPU* features, int nFeatures);
|
|
|
|
}}}
|
|
|
|
|
|
|
|
using namespace cv::gpu::surf;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
class SURF_GPU_Invoker : private CvSURFParams
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
|
|
|
public:
|
2011-03-10 14:53:58 +01:00
|
|
|
SURF_GPU_Invoker(SURF_GPU& surf, const GpuMat& img, const GpuMat& mask) :
|
|
|
|
CvSURFParams(surf),
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
sum(surf.sum), mask1(surf.mask1), maskSum(surf.maskSum), intBuffer(surf.intBuffer), det(surf.det), trace(surf.trace),
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
maxPosBuffer(surf.maxPosBuffer), featuresBuffer(surf.featuresBuffer), keypointsBuffer(surf.keypointsBuffer),
|
2010-12-20 13:49:40 +01:00
|
|
|
|
|
|
|
img_cols(img.cols), img_rows(img.rows),
|
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
use_mask(!mask.empty())
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
2011-02-07 11:12:04 +01:00
|
|
|
CV_Assert(!img.empty() && img.type() == CV_8UC1);
|
2010-12-21 15:02:09 +01:00
|
|
|
CV_Assert(mask.empty() || (mask.size() == img.size() && mask.type() == CV_8UC1));
|
2011-03-10 14:53:58 +01:00
|
|
|
CV_Assert(nOctaves > 0 && nOctaveLayers > 0);
|
|
|
|
CV_Assert(TargetArchs::builtWith(GLOBAL_ATOMICS) && DeviceInfo().supports(GLOBAL_ATOMICS));
|
2011-02-07 11:12:04 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
maxKeypoints = static_cast<int>(img.size().area() * surf.keypointsRatio);
|
|
|
|
maxFeatures = static_cast<int>(1.5 * maxKeypoints);
|
|
|
|
maxCandidates = static_cast<int>(1.5 * maxFeatures);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
CV_Assert(maxKeypoints > 0);
|
|
|
|
|
|
|
|
cudaSafeCall( cudaMalloc((void**)&d_counters, (nOctaves + 2) * sizeof(unsigned int)) );
|
|
|
|
cudaSafeCall( cudaMemset(d_counters, 0, (nOctaves + 2) * sizeof(unsigned int)) );
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
uploadConstant("cv::gpu::surf::c_max_candidates", maxCandidates);
|
|
|
|
uploadConstant("cv::gpu::surf::c_max_features", maxFeatures);
|
|
|
|
uploadConstant("cv::gpu::surf::c_max_keypoints", maxKeypoints);
|
|
|
|
uploadConstant("cv::gpu::surf::c_img_rows", img_rows);
|
|
|
|
uploadConstant("cv::gpu::surf::c_img_cols", img_cols);
|
|
|
|
uploadConstant("cv::gpu::surf::c_nOctaveLayers", nOctaveLayers);
|
|
|
|
uploadConstant("cv::gpu::surf::c_hessianThreshold", static_cast<float>(hessianThreshold));
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
bindTexture("cv::gpu::surf::imgTex", (DevMem2D)img);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
integralBuffered(img, sum, intBuffer);
|
|
|
|
bindTexture("cv::gpu::surf::sumTex", (DevMem2D_<unsigned int>)sum);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
if (use_mask)
|
|
|
|
{
|
2010-12-21 15:02:09 +01:00
|
|
|
min(mask, 1.0, mask1);
|
2011-03-10 14:53:58 +01:00
|
|
|
integralBuffered(mask1, maskSum, intBuffer);
|
|
|
|
|
|
|
|
bindTexture("cv::gpu::surf::maskSumTex", (DevMem2D_<unsigned int>)maskSum);
|
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~SURF_GPU_Invoker()
|
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
cudaSafeCall( cudaFree(d_counters) );
|
|
|
|
|
|
|
|
unbindTexture("cv::gpu::surf::imgTex");
|
2010-12-20 13:49:40 +01:00
|
|
|
unbindTexture("cv::gpu::surf::sumTex");
|
2010-12-21 15:02:09 +01:00
|
|
|
if (use_mask)
|
|
|
|
unbindTexture("cv::gpu::surf::maskSumTex");
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void detectKeypoints(GpuMat& keypoints)
|
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
ensureSizeIsEnough(img_rows * (nOctaveLayers + 2), img_cols, CV_32FC1, det);
|
|
|
|
ensureSizeIsEnough(img_rows * (nOctaveLayers + 2), img_cols, CV_32FC1, trace);
|
|
|
|
|
|
|
|
ensureSizeIsEnough(1, maxCandidates, CV_32SC4, maxPosBuffer);
|
|
|
|
ensureSizeIsEnough(1, maxFeatures, CV_32FC(6), featuresBuffer);
|
2011-02-14 16:50:17 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
for (int octave = 0; octave < nOctaves; ++octave)
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
const int layer_rows = img_rows >> octave;
|
|
|
|
const int layer_cols = img_cols >> octave;
|
|
|
|
|
|
|
|
uploadConstant("cv::gpu::surf::c_octave", octave);
|
|
|
|
uploadConstant("cv::gpu::surf::c_layer_rows", layer_rows);
|
|
|
|
uploadConstant("cv::gpu::surf::c_layer_cols", layer_cols);
|
|
|
|
|
|
|
|
icvCalcLayerDetAndTrace_gpu(det, trace, img_rows, img_cols, octave, nOctaveLayers);
|
|
|
|
|
|
|
|
icvFindMaximaInLayer_gpu(det, trace, maxPosBuffer.ptr<int4>(), d_counters + 2 + octave,
|
|
|
|
img_rows, img_cols, octave, use_mask, nOctaveLayers);
|
|
|
|
|
|
|
|
unsigned int maxCounter;
|
|
|
|
cudaSafeCall( cudaMemcpy(&maxCounter, d_counters + 2 + octave, sizeof(unsigned int), cudaMemcpyDeviceToHost) );
|
|
|
|
maxCounter = std::min(maxCounter, static_cast<unsigned int>(maxCandidates));
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-14 16:50:17 +01:00
|
|
|
if (maxCounter > 0)
|
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
icvInterpolateKeypoint_gpu(det, maxPosBuffer.ptr<int4>(), maxCounter,
|
|
|
|
featuresBuffer.ptr<KeyPoint_GPU>(), d_counters);
|
2011-02-14 16:50:17 +01:00
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
2011-03-10 14:53:58 +01:00
|
|
|
unsigned int featureCounter;
|
|
|
|
cudaSafeCall( cudaMemcpy(&featureCounter, d_counters, sizeof(unsigned int), cudaMemcpyDeviceToHost) );
|
|
|
|
featureCounter = std::min(featureCounter, static_cast<unsigned int>(maxFeatures));
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
findOrientation(featuresBuffer.colRange(0, featureCounter), keypoints);
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
void findOrientation(const GpuMat& features, GpuMat& keypoints)
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
if (features.cols > 0)
|
|
|
|
{
|
|
|
|
ensureSizeIsEnough(1, maxKeypoints, CV_32FC(6), keypointsBuffer);
|
|
|
|
|
|
|
|
icvCalcOrientation_gpu(features.ptr<KeyPoint_GPU>(), features.cols, keypointsBuffer.ptr<KeyPoint_GPU>(),
|
|
|
|
d_counters + 1);
|
|
|
|
|
|
|
|
unsigned int keypointsCounter;
|
|
|
|
cudaSafeCall( cudaMemcpy(&keypointsCounter, d_counters + 1, sizeof(unsigned int), cudaMemcpyDeviceToHost) );
|
|
|
|
keypointsCounter = std::min(keypointsCounter, static_cast<unsigned int>(maxKeypoints));
|
|
|
|
|
|
|
|
if (keypointsCounter > 0)
|
|
|
|
keypointsBuffer.colRange(0, keypointsCounter).copyTo(keypoints);
|
|
|
|
else
|
|
|
|
keypoints.release();
|
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void computeDescriptors(const GpuMat& keypoints, GpuMat& descriptors, int descriptorSize)
|
|
|
|
{
|
|
|
|
if (keypoints.cols > 0)
|
|
|
|
{
|
|
|
|
descriptors.create(keypoints.cols, descriptorSize, CV_32F);
|
2011-03-10 14:53:58 +01:00
|
|
|
compute_descriptors_gpu(descriptors, keypoints.ptr<KeyPoint_GPU>(), keypoints.cols);
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GpuMat& sum;
|
2010-12-21 15:02:09 +01:00
|
|
|
GpuMat& mask1;
|
|
|
|
GpuMat& maskSum;
|
2011-03-10 14:53:58 +01:00
|
|
|
GpuMat& intBuffer;
|
|
|
|
|
|
|
|
GpuMat& det;
|
|
|
|
GpuMat& trace;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
|
|
|
GpuMat& maxPosBuffer;
|
|
|
|
GpuMat& featuresBuffer;
|
2011-03-10 14:53:58 +01:00
|
|
|
GpuMat& keypointsBuffer;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
|
|
|
int img_cols, img_rows;
|
2010-12-21 15:02:09 +01:00
|
|
|
|
|
|
|
bool use_mask;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
int maxCandidates;
|
|
|
|
int maxFeatures;
|
|
|
|
int maxKeypoints;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
unsigned int* d_counters;
|
2010-12-20 13:49:40 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
cv::gpu::SURF_GPU::SURF_GPU()
|
|
|
|
{
|
|
|
|
hessianThreshold = 100;
|
|
|
|
extended = 1;
|
|
|
|
nOctaves = 4;
|
|
|
|
nOctaveLayers = 2;
|
|
|
|
keypointsRatio = 0.01f;
|
|
|
|
}
|
|
|
|
|
|
|
|
cv::gpu::SURF_GPU::SURF_GPU(double _threshold, int _nOctaves, int _nOctaveLayers, bool _extended, float _keypointsRatio)
|
|
|
|
{
|
|
|
|
hessianThreshold = _threshold;
|
|
|
|
extended = _extended;
|
|
|
|
nOctaves = _nOctaves;
|
|
|
|
nOctaveLayers = _nOctaveLayers;
|
|
|
|
keypointsRatio = _keypointsRatio;
|
|
|
|
}
|
|
|
|
|
2010-12-20 13:49:40 +01:00
|
|
|
int cv::gpu::SURF_GPU::descriptorSize() const
|
|
|
|
{
|
|
|
|
return extended ? 128 : 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cv::gpu::SURF_GPU::uploadKeypoints(const vector<KeyPoint>& keypoints, GpuMat& keypointsGPU)
|
|
|
|
{
|
2011-02-07 11:12:04 +01:00
|
|
|
if (keypoints.empty())
|
|
|
|
keypointsGPU.release();
|
|
|
|
else
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
2011-02-07 11:12:04 +01:00
|
|
|
Mat keypointsCPU(1, keypoints.size(), CV_32FC(6));
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
for (size_t i = 0; i < keypoints.size(); ++i)
|
2011-02-07 11:12:04 +01:00
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
const KeyPoint& kp = keypoints[i];
|
|
|
|
KeyPoint_GPU& gkp = keypointsCPU.ptr<KeyPoint_GPU>()[i];
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
gkp.x = kp.pt.x;
|
|
|
|
gkp.y = kp.pt.y;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
gkp.laplacian = 1.0f;
|
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
gkp.size = kp.size;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
gkp.dir = kp.angle;
|
|
|
|
gkp.hessian = kp.response;
|
2011-02-07 11:12:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
keypointsGPU.upload(keypointsCPU);
|
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
int calcSize(int octave, int layer)
|
|
|
|
{
|
|
|
|
/* Wavelet size at first layer of first octave. */
|
|
|
|
const int HAAR_SIZE0 = 9;
|
|
|
|
|
|
|
|
/* Wavelet size increment between layers. This should be an even number,
|
|
|
|
such that the wavelet sizes in an octave are either all even or all odd.
|
|
|
|
This ensures that when looking for the neighbours of a sample, the layers
|
|
|
|
above and below are aligned correctly. */
|
|
|
|
const int HAAR_SIZE_INC = 6;
|
|
|
|
|
|
|
|
return (HAAR_SIZE0 + HAAR_SIZE_INC * layer) << octave;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getPointOctave(const KeyPoint_GPU& kpt, const CvSURFParams& params)
|
|
|
|
{
|
|
|
|
int best_octave = 0;
|
|
|
|
float min_diff = numeric_limits<float>::max();
|
|
|
|
for (int octave = 1; octave < params.nOctaves; ++octave)
|
|
|
|
{
|
|
|
|
for (int layer = 0; layer < params.nOctaveLayers; ++layer)
|
|
|
|
{
|
|
|
|
float diff = std::abs(kpt.size - (float)calcSize(octave, layer));
|
|
|
|
if (min_diff > diff)
|
|
|
|
{
|
|
|
|
min_diff = diff;
|
|
|
|
best_octave = octave;
|
|
|
|
if (min_diff == 0)
|
|
|
|
return best_octave;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return best_octave;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 13:49:40 +01:00
|
|
|
void cv::gpu::SURF_GPU::downloadKeypoints(const GpuMat& keypointsGPU, vector<KeyPoint>& keypoints)
|
|
|
|
{
|
2011-02-07 11:12:04 +01:00
|
|
|
if (keypointsGPU.empty())
|
|
|
|
keypoints.clear();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CV_Assert(keypointsGPU.type() == CV_32FC(6) && keypointsGPU.isContinuous());
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
Mat keypointsCPU = keypointsGPU;
|
|
|
|
keypoints.resize(keypointsGPU.cols);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
for (int i = 0; i < keypointsGPU.cols; ++i)
|
2011-02-07 11:12:04 +01:00
|
|
|
{
|
2011-03-10 14:53:58 +01:00
|
|
|
KeyPoint& kp = keypoints[i];
|
|
|
|
const KeyPoint_GPU& gkp = keypointsCPU.ptr<KeyPoint_GPU>()[i];
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
kp.pt.x = gkp.x;
|
|
|
|
kp.pt.y = gkp.y;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
kp.size = gkp.size;
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
kp.angle = gkp.dir;
|
|
|
|
|
|
|
|
kp.response = gkp.hessian;
|
|
|
|
|
|
|
|
kp.octave = getPointOctave(gkp, *this);
|
|
|
|
|
|
|
|
kp.class_id = static_cast<int>(gkp.laplacian);
|
2011-02-07 11:12:04 +01:00
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cv::gpu::SURF_GPU::downloadDescriptors(const GpuMat& descriptorsGPU, vector<float>& descriptors)
|
|
|
|
{
|
2011-02-07 11:12:04 +01:00
|
|
|
if (descriptorsGPU.empty())
|
|
|
|
descriptors.clear();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CV_Assert(descriptorsGPU.type() == CV_32F);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
descriptors.resize(descriptorsGPU.rows * descriptorsGPU.cols);
|
|
|
|
Mat descriptorsCPU(descriptorsGPU.size(), CV_32F, &descriptors[0]);
|
|
|
|
descriptorsGPU.download(descriptorsCPU);
|
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
2010-12-21 15:02:09 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints)
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
2011-02-07 11:12:04 +01:00
|
|
|
if (!img.empty())
|
|
|
|
{
|
|
|
|
SURF_GPU_Invoker surf(*this, img, mask);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
surf.detectKeypoints(keypoints);
|
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
2010-12-21 15:02:09 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors,
|
2011-03-10 14:53:58 +01:00
|
|
|
bool useProvidedKeypoints)
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
2011-02-07 11:12:04 +01:00
|
|
|
if (!img.empty())
|
|
|
|
{
|
|
|
|
SURF_GPU_Invoker surf(*this, img, mask);
|
2011-03-10 14:53:58 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
if (!useProvidedKeypoints)
|
|
|
|
surf.detectKeypoints(keypoints);
|
2011-03-10 14:53:58 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GpuMat keypointsBuf;
|
|
|
|
surf.findOrientation(keypoints, keypointsBuf);
|
|
|
|
keypointsBuf.copyTo(keypoints);
|
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
|
2011-02-07 11:12:04 +01:00
|
|
|
surf.computeDescriptors(keypoints, descriptors, descriptorSize());
|
|
|
|
}
|
2010-12-20 13:49:40 +01:00
|
|
|
}
|
|
|
|
|
2010-12-21 15:02:09 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat& img, const GpuMat& mask, vector<KeyPoint>& keypoints)
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
|
|
|
GpuMat keypointsGPU;
|
|
|
|
|
2010-12-21 15:02:09 +01:00
|
|
|
(*this)(img, mask, keypointsGPU);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
|
|
|
downloadKeypoints(keypointsGPU, keypoints);
|
|
|
|
}
|
|
|
|
|
2010-12-21 15:02:09 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat& img, const GpuMat& mask, vector<KeyPoint>& keypoints,
|
2011-03-10 14:53:58 +01:00
|
|
|
GpuMat& descriptors, bool useProvidedKeypoints)
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
|
|
|
GpuMat keypointsGPU;
|
|
|
|
|
|
|
|
if (useProvidedKeypoints)
|
|
|
|
uploadKeypoints(keypoints, keypointsGPU);
|
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
(*this)(img, mask, keypointsGPU, descriptors, useProvidedKeypoints);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
|
|
|
downloadKeypoints(keypointsGPU, keypoints);
|
|
|
|
}
|
|
|
|
|
2010-12-21 15:02:09 +01:00
|
|
|
void cv::gpu::SURF_GPU::operator()(const GpuMat& img, const GpuMat& mask, vector<KeyPoint>& keypoints,
|
2011-03-10 14:53:58 +01:00
|
|
|
vector<float>& descriptors, bool useProvidedKeypoints)
|
2010-12-20 13:49:40 +01:00
|
|
|
{
|
|
|
|
GpuMat descriptorsGPU;
|
|
|
|
|
2011-03-10 14:53:58 +01:00
|
|
|
(*this)(img, mask, keypoints, descriptorsGPU, useProvidedKeypoints);
|
2010-12-20 13:49:40 +01:00
|
|
|
|
|
|
|
downloadDescriptors(descriptorsGPU, descriptors);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined (HAVE_CUDA) */
|