This source file includes following definitions.
- create
- descriptorSize
- descriptorType
- defaultNorm
- setMaxFeatures
- getMaxFeatures
- setScaleFactor
- getScaleFactor
- setNLevels
- getNLevels
- setEdgeThreshold
- getEdgeThreshold
- setFirstLevel
- getFirstLevel
- setWTA_K
- getWTA_K
- setScoreType
- getScoreType
- setPatchSize
- getPatchSize
- setFastThreshold
- getFastThreshold
- setBlurForDescriptor
- getBlurForDescriptor
- initializeOrbPattern
- makeRandomPattern
- blurForDescriptor_
- detectAndCompute
- detectAndComputeAsync
- getScale
- buildScalePyramids
- cull
- computeKeyPointsPyramid
- computeDescriptors
- mergeKeyPoints
- convert
- create
#include "precomp.hpp"
using namespace cv;
using namespace cv::cuda;
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
Ptr<cv::cuda::ORB> cv::cuda::ORB::create(int, float, int, int, int, int, int, int, int, bool) { throw_no_cuda(); return Ptr<cv::cuda::ORB>(); }
#else
namespace cv { namespace cuda { namespace device
{
namespace orb
{
int cull_gpu(int* loc, float* response, int size, int n_points);
void HarrisResponses_gpu(PtrStepSzb img, const short2* loc, float* response, const int npoints, int blockSize, float harris_k, cudaStream_t stream);
void loadUMax(const int* u_max, int count);
void IC_Angle_gpu(PtrStepSzb image, const short2* loc, float* angle, int npoints, int half_k, cudaStream_t stream);
void computeOrbDescriptor_gpu(PtrStepb img, const short2* loc, const float* angle, const int npoints,
const int* pattern_x, const int* pattern_y, PtrStepb desc, int dsize, int WTA_K, cudaStream_t stream);
void mergeLocation_gpu(const short2* loc, float* x, float* y, int npoints, float scale, cudaStream_t stream);
}
}}}
namespace
{
const float HARRIS_K = 0.04f;
const int DESCRIPTOR_SIZE = 32;
const int bit_pattern_31_[256 * 4] =
{
8,-3, 9,5,
4,2, 7,-12,
-11,9, -8,2,
7,-12, 12,-13,
2,-13, 2,12,
1,-7, 1,6,
-2,-10, -2,-4,
-13,-13, -11,-8,
-13,-3, -12,-9,
10,4, 11,9,
-13,-8, -8,-9,
-11,7, -9,12,
7,7, 12,6,
-4,-5, -3,0,
-13,2, -12,-3,
-9,0, -7,5,
12,-6, 12,-1,
-3,6, -2,12,
-6,-13, -4,-8,
11,-13, 12,-8,
4,7, 5,1,
5,-3, 10,-3,
3,-7, 6,12,
-8,-7, -6,-2,
-2,11, -1,-10,
-13,12, -8,10,
-7,3, -5,-3,
-4,2, -3,7,
-10,-12, -6,11,
5,-12, 6,-7,
5,-6, 7,-1,
1,0, 4,-5,
9,11, 11,-13,
4,7, 4,12,
2,-1, 4,4,
-4,-12, -2,7,
-8,-5, -7,-10,
4,11, 9,12,
0,-8, 1,-13,
-13,-2, -8,2,
-3,-2, -2,3,
-6,9, -4,-9,
8,12, 10,7,
0,9, 1,3,
7,-5, 11,-10,
-13,-6, -11,0,
10,7, 12,1,
-6,-3, -6,12,
10,-9, 12,-4,
-13,8, -8,-12,
-13,0, -8,-4,
3,3, 7,8,
5,7, 10,-7,
-1,7, 1,-12,
3,-10, 5,6,
2,-4, 3,-10,
-13,0, -13,5,
-13,-7, -12,12,
-13,3, -11,8,
-7,12, -4,7,
6,-10, 12,8,
-9,-1, -7,-6,
-2,-5, 0,12,
-12,5, -7,5,
3,-10, 8,-13,
-7,-7, -4,5,
-3,-2, -1,-7,
2,9, 5,-11,
-11,-13, -5,-13,
-1,6, 0,-1,
5,-3, 5,2,
-4,-13, -4,12,
-9,-6, -9,6,
-12,-10, -8,-4,
10,2, 12,-3,
7,12, 12,12,
-7,-13, -6,5,
-4,9, -3,4,
7,-1, 12,2,
-7,6, -5,1,
-13,11, -12,5,
-3,7, -2,-6,
7,-8, 12,-7,
-13,-7, -11,-12,
1,-3, 12,12,
2,-6, 3,0,
-4,3, -2,-13,
-1,-13, 1,9,
7,1, 8,-6,
1,-1, 3,12,
9,1, 12,6,
-1,-9, -1,3,
-13,-13, -10,5,
7,7, 10,12,
12,-5, 12,9,
6,3, 7,11,
5,-13, 6,10,
2,-12, 2,3,
3,8, 4,-6,
2,6, 12,-13,
9,-12, 10,3,
-8,4, -7,9,
-11,12, -4,-6,
1,12, 2,-8,
6,-9, 7,-4,
2,3, 3,-2,
6,3, 11,0,
3,-3, 8,-8,
7,8, 9,3,
-11,-5, -6,-4,
-10,11, -5,10,
-5,-8, -3,12,
-10,5, -9,0,
8,-1, 12,-6,
4,-6, 6,-11,
-10,12, -8,7,
4,-2, 6,7,
-2,0, -2,12,
-5,-8, -5,2,
7,-6, 10,12,
-9,-13, -8,-8,
-5,-13, -5,-2,
8,-8, 9,-13,
-9,-11, -9,0,
1,-8, 1,-2,
7,-4, 9,1,
-2,1, -1,-4,
11,-6, 12,-11,
-12,-9, -6,4,
3,7, 7,12,
5,5, 10,8,
0,-4, 2,8,
-9,12, -5,-13,
0,7, 2,12,
-1,2, 1,7,
5,11, 7,-9,
3,5, 6,-8,
-13,-4, -8,9,
-5,9, -3,-3,
-4,-7, -3,-12,
6,5, 8,0,
-7,6, -6,12,
-13,6, -5,-2,
1,-10, 3,10,
4,1, 8,-4,
-2,-2, 2,-13,
2,-12, 12,12,
-2,-13, 0,-6,
4,1, 9,3,
-6,-10, -3,-5,
-3,-13, -1,1,
7,5, 12,-11,
4,-2, 5,-7,
-13,9, -9,-5,
7,1, 8,6,
7,-8, 7,6,
-7,-4, -7,1,
-8,11, -7,-8,
-13,6, -12,-8,
2,4, 3,9,
10,-5, 12,3,
-6,-5, -6,7,
8,-3, 9,-8,
2,-12, 2,8,
-11,-2, -10,3,
-12,-13, -7,-9,
-11,0, -10,-5,
5,-3, 11,8,
-2,-13, -1,12,
-1,-8, 0,9,
-13,-11, -12,-5,
-10,-2, -10,11,
-3,9, -2,-13,
2,-3, 3,2,
-9,-13, -4,0,
-4,6, -3,-10,
-4,12, -2,-7,
-6,-11, -4,9,
6,-3, 6,11,
-13,11, -5,5,
11,11, 12,6,
7,-5, 12,-2,
-1,12, 0,7,
-4,-8, -3,-2,
-7,1, -6,7,
-13,-12, -8,-13,
-7,-2, -6,-8,
-8,5, -6,-9,
-5,-1, -4,5,
-13,7, -8,10,
1,5, 5,-13,
1,0, 10,-13,
9,12, 10,-1,
5,-8, 10,-9,
-1,11, 1,-13,
-9,-3, -6,2,
-1,-10, 1,12,
-13,1, -8,-10,
8,-11, 10,-6,
2,-13, 3,-6,
7,-13, 12,-9,
-10,-10, -5,-7,
-10,-8, -8,-13,
4,-6, 8,5,
3,12, 8,-13,
-4,2, -3,-3,
5,-13, 10,-12,
4,-13, 5,-1,
-9,9, -4,3,
0,3, 3,-9,
-12,1, -6,1,
3,2, 4,-8,
-10,-10, -10,9,
8,-13, 12,12,
-8,-12, -6,-5,
2,2, 3,7,
10,6, 11,-8,
6,8, 8,-12,
-7,10, -6,5,
-3,-9, -3,9,
-1,-13, -1,5,
-3,-7, -3,4,
-8,-2, -8,3,
4,2, 12,12,
2,-5, 3,11,
6,-9, 11,-13,
3,-1, 7,12,
11,-1, 12,4,
-3,0, -3,6,
4,-11, 4,12,
2,-4, 2,1,
-10,-6, -8,1,
-13,7, -11,1,
-13,12, -11,-13,
6,0, 11,-13,
0,-1, 1,4,
-13,3, -9,-2,
-9,8, -6,-3,
-13,-6, -8,-2,
5,-9, 8,10,
2,7, 3,-9,
-1,-6, -1,-1,
9,5, 11,-2,
11,-3, 12,-8,
3,0, 3,5,
-1,4, 0,10,
3,-6, 4,5,
-13,0, -10,5,
5,8, 12,11,
8,9, 9,-6,
7,-4, 8,-12,
-10,4, -10,9,
7,3, 12,4,
9,-7, 10,-2,
7,0, 12,-2,
-1,-6, 0,-11
};
class ORB_Impl : public cv::cuda::ORB
{
public:
ORB_Impl(int nfeatures,
float scaleFactor,
int nlevels,
int edgeThreshold,
int firstLevel,
int WTA_K,
int scoreType,
int patchSize,
int fastThreshold,
bool blurForDescriptor);
virtual void detectAndCompute(InputArray _image, InputArray _mask, std::vector<KeyPoint>& keypoints, OutputArray _descriptors, bool useProvidedKeypoints);
virtual void detectAndComputeAsync(InputArray _image, InputArray _mask, OutputArray _keypoints, OutputArray _descriptors, bool useProvidedKeypoints, Stream& stream);
virtual void convert(InputArray _gpu_keypoints, std::vector<KeyPoint>& keypoints);
virtual int descriptorSize() const { return kBytes; }
virtual int descriptorType() const { return CV_8U; }
virtual int defaultNorm() const { return NORM_HAMMING; }
virtual void setMaxFeatures(int maxFeatures) { nFeatures_ = maxFeatures; }
virtual int getMaxFeatures() const { return nFeatures_; }
virtual void setScaleFactor(double scaleFactor) { scaleFactor_ = scaleFactor; }
virtual double getScaleFactor() const { return scaleFactor_; }
virtual void setNLevels(int nlevels) { nLevels_ = nlevels; }
virtual int getNLevels() const { return nLevels_; }
virtual void setEdgeThreshold(int edgeThreshold) { edgeThreshold_ = edgeThreshold; }
virtual int getEdgeThreshold() const { return edgeThreshold_; }
virtual void setFirstLevel(int firstLevel) { firstLevel_ = firstLevel; }
virtual int getFirstLevel() const { return firstLevel_; }
virtual void setWTA_K(int wta_k) { WTA_K_ = wta_k; }
virtual int getWTA_K() const { return WTA_K_; }
virtual void setScoreType(int scoreType) { scoreType_ = scoreType; }
virtual int getScoreType() const { return scoreType_; }
virtual void setPatchSize(int patchSize) { patchSize_ = patchSize; }
virtual int getPatchSize() const { return patchSize_; }
virtual void setFastThreshold(int fastThreshold) { fastThreshold_ = fastThreshold; }
virtual int getFastThreshold() const { return fastThreshold_; }
virtual void setBlurForDescriptor(bool blurForDescriptor) { blurForDescriptor_ = blurForDescriptor; }
virtual bool getBlurForDescriptor() const { return blurForDescriptor_; }
private:
int nFeatures_;
float scaleFactor_;
int nLevels_;
int edgeThreshold_;
int firstLevel_;
int WTA_K_;
int scoreType_;
int patchSize_;
int fastThreshold_;
bool blurForDescriptor_;
private:
void buildScalePyramids(InputArray _image, InputArray _mask);
void computeKeyPointsPyramid();
void computeDescriptors(OutputArray _descriptors);
void mergeKeyPoints(OutputArray _keypoints);
private:
Ptr<cv::cuda::FastFeatureDetector> fastDetector_;
std::vector<size_t> n_features_per_level_;
GpuMat pattern_;
std::vector<GpuMat> imagePyr_;
std::vector<GpuMat> maskPyr_;
GpuMat buf_;
std::vector<GpuMat> keyPointsPyr_;
std::vector<int> keyPointsCount_;
Ptr<cuda::Filter> blurFilter_;
GpuMat d_keypoints_;
};
static void initializeOrbPattern(const Point* pattern0, Mat& pattern, int ntuples, int tupleSize, int poolSize)
{
RNG rng(0x12345678);
pattern.create(2, ntuples * tupleSize, CV_32SC1);
pattern.setTo(Scalar::all(0));
int* pattern_x_ptr = pattern.ptr<int>(0);
int* pattern_y_ptr = pattern.ptr<int>(1);
for (int i = 0; i < ntuples; i++)
{
for (int k = 0; k < tupleSize; k++)
{
for(;;)
{
int idx = rng.uniform(0, poolSize);
Point pt = pattern0[idx];
int k1;
for (k1 = 0; k1 < k; k1++)
if (pattern_x_ptr[tupleSize * i + k1] == pt.x && pattern_y_ptr[tupleSize * i + k1] == pt.y)
break;
if (k1 == k)
{
pattern_x_ptr[tupleSize * i + k] = pt.x;
pattern_y_ptr[tupleSize * i + k] = pt.y;
break;
}
}
}
}
}
static void makeRandomPattern(int patchSize, Point* pattern, int npoints)
{
RNG rng(0x34985739);
for (int i = 0; i < npoints; i++)
{
pattern[i].x = rng.uniform(-patchSize / 2, patchSize / 2 + 1);
pattern[i].y = rng.uniform(-patchSize / 2, patchSize / 2 + 1);
}
}
ORB_Impl::ORB_Impl(int nFeatures,
float scaleFactor,
int nLevels,
int edgeThreshold,
int firstLevel,
int WTA_K,
int scoreType,
int patchSize,
int fastThreshold,
bool blurForDescriptor) :
nFeatures_(nFeatures),
scaleFactor_(scaleFactor),
nLevels_(nLevels),
edgeThreshold_(edgeThreshold),
firstLevel_(firstLevel),
WTA_K_(WTA_K),
scoreType_(scoreType),
patchSize_(patchSize),
fastThreshold_(fastThreshold),
blurForDescriptor_(blurForDescriptor)
{
CV_Assert( patchSize_ >= 2 );
CV_Assert( WTA_K_ == 2 || WTA_K_ == 3 || WTA_K_ == 4 );
fastDetector_ = cuda::FastFeatureDetector::create(fastThreshold_);
float factor = 1.0f / scaleFactor_;
float n_desired_features_per_scale = nFeatures_ * (1.0f - factor) / (1.0f - std::pow(factor, nLevels_));
n_features_per_level_.resize(nLevels_);
size_t sum_n_features = 0;
for (int level = 0; level < nLevels_ - 1; ++level)
{
n_features_per_level_[level] = cvRound(n_desired_features_per_scale);
sum_n_features += n_features_per_level_[level];
n_desired_features_per_scale *= factor;
}
n_features_per_level_[nLevels_ - 1] = nFeatures - sum_n_features;
int half_patch_size = patchSize_ / 2;
std::vector<int> u_max(half_patch_size + 2);
for (int v = 0; v <= half_patch_size * std::sqrt(2.f) / 2 + 1; ++v)
{
u_max[v] = cvRound(std::sqrt(static_cast<float>(half_patch_size * half_patch_size - v * v)));
}
for (int v = half_patch_size, v_0 = 0; v >= half_patch_size * std::sqrt(2.f) / 2; --v)
{
while (u_max[v_0] == u_max[v_0 + 1])
++v_0;
u_max[v] = v_0;
++v_0;
}
CV_Assert( u_max.size() < 32 );
cv::cuda::device::orb::loadUMax(&u_max[0], static_cast<int>(u_max.size()));
const int npoints = 512;
Point pattern_buf[npoints];
const Point* pattern0 = (const Point*)bit_pattern_31_;
if (patchSize_ != 31)
{
pattern0 = pattern_buf;
makeRandomPattern(patchSize_, pattern_buf, npoints);
}
Mat h_pattern;
if (WTA_K_ == 2)
{
h_pattern.create(2, npoints, CV_32SC1);
int* pattern_x_ptr = h_pattern.ptr<int>(0);
int* pattern_y_ptr = h_pattern.ptr<int>(1);
for (int i = 0; i < npoints; ++i)
{
pattern_x_ptr[i] = pattern0[i].x;
pattern_y_ptr[i] = pattern0[i].y;
}
}
else
{
int ntuples = descriptorSize() * 4;
initializeOrbPattern(pattern0, h_pattern, ntuples, WTA_K_, npoints);
}
pattern_.upload(h_pattern);
blurFilter_ = cuda::createGaussianFilter(CV_8UC1, -1, Size(7, 7), 2, 2, BORDER_REFLECT_101);
}
void ORB_Impl::detectAndCompute(InputArray _image, InputArray _mask, std::vector<KeyPoint>& keypoints, OutputArray _descriptors, bool useProvidedKeypoints)
{
CV_Assert( useProvidedKeypoints == false );
detectAndComputeAsync(_image, _mask, d_keypoints_, _descriptors, false, Stream::Null());
convert(d_keypoints_, keypoints);
}
void ORB_Impl::detectAndComputeAsync(InputArray _image, InputArray _mask, OutputArray _keypoints, OutputArray _descriptors, bool useProvidedKeypoints, Stream& stream)
{
CV_Assert( useProvidedKeypoints == false );
buildScalePyramids(_image, _mask);
computeKeyPointsPyramid();
if (_descriptors.needed())
{
computeDescriptors(_descriptors);
}
mergeKeyPoints(_keypoints);
}
static float getScale(float scaleFactor, int firstLevel, int level)
{
return pow(scaleFactor, level - firstLevel);
}
void ORB_Impl::buildScalePyramids(InputArray _image, InputArray _mask)
{
const GpuMat image = _image.getGpuMat();
const GpuMat mask = _mask.getGpuMat();
CV_Assert( image.type() == CV_8UC1 );
CV_Assert( mask.empty() || (mask.type() == CV_8UC1 && mask.size() == image.size()) );
imagePyr_.resize(nLevels_);
maskPyr_.resize(nLevels_);
for (int level = 0; level < nLevels_; ++level)
{
float scale = 1.0f / getScale(scaleFactor_, firstLevel_, level);
Size sz(cvRound(image.cols * scale), cvRound(image.rows * scale));
ensureSizeIsEnough(sz, image.type(), imagePyr_[level]);
ensureSizeIsEnough(sz, CV_8UC1, maskPyr_[level]);
maskPyr_[level].setTo(Scalar::all(255));
if (level != firstLevel_)
{
if (level < firstLevel_)
{
cuda::resize(image, imagePyr_[level], sz, 0, 0, INTER_LINEAR);
if (!mask.empty())
cuda::resize(mask, maskPyr_[level], sz, 0, 0, INTER_LINEAR);
}
else
{
cuda::resize(imagePyr_[level - 1], imagePyr_[level], sz, 0, 0, INTER_LINEAR);
if (!mask.empty())
{
cuda::resize(maskPyr_[level - 1], maskPyr_[level], sz, 0, 0, INTER_LINEAR);
cuda::threshold(maskPyr_[level], maskPyr_[level], 254, 0, THRESH_TOZERO);
}
}
}
else
{
image.copyTo(imagePyr_[level]);
if (!mask.empty())
mask.copyTo(maskPyr_[level]);
}
ensureSizeIsEnough(sz, CV_8UC1, buf_);
buf_.setTo(Scalar::all(0));
Rect inner(edgeThreshold_, edgeThreshold_, sz.width - 2 * edgeThreshold_, sz.height - 2 * edgeThreshold_);
buf_(inner).setTo(Scalar::all(255));
cuda::bitwise_and(maskPyr_[level], buf_, maskPyr_[level]);
}
}
static void cull(GpuMat& keypoints, int& count, int n_points)
{
using namespace cv::cuda::device::orb;
if (count > n_points)
{
if (n_points == 0)
{
keypoints.release();
return;
}
count = cull_gpu(keypoints.ptr<int>(cuda::FastFeatureDetector::LOCATION_ROW), keypoints.ptr<float>(cuda::FastFeatureDetector::RESPONSE_ROW), count, n_points);
}
}
void ORB_Impl::computeKeyPointsPyramid()
{
using namespace cv::cuda::device::orb;
int half_patch_size = patchSize_ / 2;
keyPointsPyr_.resize(nLevels_);
keyPointsCount_.resize(nLevels_);
fastDetector_->setThreshold(fastThreshold_);
for (int level = 0; level < nLevels_; ++level)
{
fastDetector_->setMaxNumPoints(0.05 * imagePyr_[level].size().area());
GpuMat fastKpRange;
fastDetector_->detectAsync(imagePyr_[level], fastKpRange, maskPyr_[level], Stream::Null());
keyPointsCount_[level] = fastKpRange.cols;
if (keyPointsCount_[level] == 0)
continue;
ensureSizeIsEnough(3, keyPointsCount_[level], fastKpRange.type(), keyPointsPyr_[level]);
fastKpRange.copyTo(keyPointsPyr_[level].rowRange(0, 2));
const int n_features = static_cast<int>(n_features_per_level_[level]);
if (scoreType_ == ORB::HARRIS_SCORE)
{
cull(keyPointsPyr_[level], keyPointsCount_[level], 2 * n_features);
HarrisResponses_gpu(imagePyr_[level], keyPointsPyr_[level].ptr<short2>(0), keyPointsPyr_[level].ptr<float>(1), keyPointsCount_[level], 7, HARRIS_K, 0);
}
cull(keyPointsPyr_[level], keyPointsCount_[level], n_features);
IC_Angle_gpu(imagePyr_[level], keyPointsPyr_[level].ptr<short2>(0), keyPointsPyr_[level].ptr<float>(2), keyPointsCount_[level], half_patch_size, 0);
}
}
void ORB_Impl::computeDescriptors(OutputArray _descriptors)
{
using namespace cv::cuda::device::orb;
int nAllkeypoints = 0;
for (int level = 0; level < nLevels_; ++level)
nAllkeypoints += keyPointsCount_[level];
if (nAllkeypoints == 0)
{
_descriptors.release();
return;
}
ensureSizeIsEnough(nAllkeypoints, descriptorSize(), CV_8UC1, _descriptors);
GpuMat descriptors = _descriptors.getGpuMat();
int offset = 0;
for (int level = 0; level < nLevels_; ++level)
{
if (keyPointsCount_[level] == 0)
continue;
GpuMat descRange = descriptors.rowRange(offset, offset + keyPointsCount_[level]);
if (blurForDescriptor_)
{
ensureSizeIsEnough(imagePyr_[level].size(), imagePyr_[level].type(), buf_);
blurFilter_->apply(imagePyr_[level], buf_);
}
computeOrbDescriptor_gpu(blurForDescriptor_ ? buf_ : imagePyr_[level], keyPointsPyr_[level].ptr<short2>(0), keyPointsPyr_[level].ptr<float>(2),
keyPointsCount_[level], pattern_.ptr<int>(0), pattern_.ptr<int>(1), descRange, descriptorSize(), WTA_K_, 0);
offset += keyPointsCount_[level];
}
}
void ORB_Impl::mergeKeyPoints(OutputArray _keypoints)
{
using namespace cv::cuda::device::orb;
int nAllkeypoints = 0;
for (int level = 0; level < nLevels_; ++level)
nAllkeypoints += keyPointsCount_[level];
if (nAllkeypoints == 0)
{
_keypoints.release();
return;
}
ensureSizeIsEnough(ROWS_COUNT, nAllkeypoints, CV_32FC1, _keypoints);
GpuMat& keypoints = _keypoints.getGpuMatRef();
int offset = 0;
for (int level = 0; level < nLevels_; ++level)
{
if (keyPointsCount_[level] == 0)
continue;
float sf = getScale(scaleFactor_, firstLevel_, level);
GpuMat keyPointsRange = keypoints.colRange(offset, offset + keyPointsCount_[level]);
float locScale = level != firstLevel_ ? sf : 1.0f;
mergeLocation_gpu(keyPointsPyr_[level].ptr<short2>(0), keyPointsRange.ptr<float>(0), keyPointsRange.ptr<float>(1), keyPointsCount_[level], locScale, 0);
GpuMat range = keyPointsRange.rowRange(2, 4);
keyPointsPyr_[level](Range(1, 3), Range(0, keyPointsCount_[level])).copyTo(range);
keyPointsRange.row(4).setTo(Scalar::all(level));
keyPointsRange.row(5).setTo(Scalar::all(patchSize_ * sf));
offset += keyPointsCount_[level];
}
}
void ORB_Impl::convert(InputArray _gpu_keypoints, std::vector<KeyPoint>& keypoints)
{
if (_gpu_keypoints.empty())
{
keypoints.clear();
return;
}
Mat h_keypoints;
if (_gpu_keypoints.kind() == _InputArray::CUDA_GPU_MAT)
{
_gpu_keypoints.getGpuMat().download(h_keypoints);
}
else
{
h_keypoints = _gpu_keypoints.getMat();
}
CV_Assert( h_keypoints.rows == ROWS_COUNT );
CV_Assert( h_keypoints.type() == CV_32FC1 );
const int npoints = h_keypoints.cols;
keypoints.resize(npoints);
const float* x_ptr = h_keypoints.ptr<float>(X_ROW);
const float* y_ptr = h_keypoints.ptr<float>(Y_ROW);
const float* response_ptr = h_keypoints.ptr<float>(RESPONSE_ROW);
const float* angle_ptr = h_keypoints.ptr<float>(ANGLE_ROW);
const float* octave_ptr = h_keypoints.ptr<float>(OCTAVE_ROW);
const float* size_ptr = h_keypoints.ptr<float>(SIZE_ROW);
for (int i = 0; i < npoints; ++i)
{
KeyPoint kp;
kp.pt.x = x_ptr[i];
kp.pt.y = y_ptr[i];
kp.response = response_ptr[i];
kp.angle = angle_ptr[i];
kp.octave = static_cast<int>(octave_ptr[i]);
kp.size = size_ptr[i];
keypoints[i] = kp;
}
}
}
Ptr<cv::cuda::ORB> cv::cuda::ORB::create(int nfeatures,
float scaleFactor,
int nlevels,
int edgeThreshold,
int firstLevel,
int WTA_K,
int scoreType,
int patchSize,
int fastThreshold,
bool blurForDescriptor)
{
return makePtr<ORB_Impl>(nfeatures, scaleFactor, nlevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize, fastThreshold, blurForDescriptor);
}
#endif