Merge pull request #1954 from pentschev:ocl_features2d_fast_master
This commit is contained in:
commit
b43d6b6858
@ -305,6 +305,153 @@ Converts matrices obtained via :ocv:func:`ocl::BruteForceMatcher_OCL_base::radiu
|
||||
|
||||
If ``compactResult`` is ``true`` , the ``matches`` vector does not contain matches for fully masked-out query descriptors.
|
||||
|
||||
|
||||
ocl::FAST_OCL
|
||||
------------------
|
||||
.. ocv:class:: ocl::FAST_OCL
|
||||
|
||||
Class used for corner detection using the FAST algorithm. ::
|
||||
|
||||
class CV_EXPORTS FAST_OCL
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
X_ROW = 0,
|
||||
Y_ROW,
|
||||
RESPONSE_ROW,
|
||||
ROWS_COUNT
|
||||
};
|
||||
|
||||
// all features have same size
|
||||
static const int FEATURE_SIZE = 7;
|
||||
|
||||
explicit FAST_OCL(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05);
|
||||
|
||||
//! finds the keypoints using FAST detector
|
||||
//! supports only CV_8UC1 images
|
||||
void operator ()(const oclMat& image, const oclMat& mask, oclMat& keypoints);
|
||||
void operator ()(const oclMat& image, const oclMat& mask, std::vector<KeyPoint>& keypoints);
|
||||
|
||||
//! download keypoints from device to host memory
|
||||
static void downloadKeypoints(const oclMat& d_keypoints, std::vector<KeyPoint>& keypoints);
|
||||
|
||||
//! convert keypoints to KeyPoint vector
|
||||
static void convertKeypoints(const Mat& h_keypoints, std::vector<KeyPoint>& keypoints);
|
||||
|
||||
//! release temporary buffer's memory
|
||||
void release();
|
||||
|
||||
bool nonmaxSupression;
|
||||
|
||||
int threshold;
|
||||
|
||||
//! max keypoints = keypointsRatio * img.size().area()
|
||||
double keypointsRatio;
|
||||
|
||||
//! find keypoints and compute it's response if nonmaxSupression is true
|
||||
//! return count of detected keypoints
|
||||
int calcKeyPointsLocation(const oclMat& image, const oclMat& mask);
|
||||
|
||||
//! get final array of keypoints
|
||||
//! performs nonmax supression if needed
|
||||
//! return final count of keypoints
|
||||
int getKeyPoints(oclMat& keypoints);
|
||||
|
||||
private:
|
||||
// Hidden
|
||||
};
|
||||
|
||||
|
||||
The class ``FAST_OCL`` implements FAST corner detection algorithm.
|
||||
|
||||
.. seealso:: :ocv:func:`FAST`
|
||||
|
||||
|
||||
|
||||
ocl::FAST_OCL::FAST_OCL
|
||||
--------------------------
|
||||
Constructor.
|
||||
|
||||
.. ocv:function:: ocl::FAST_OCL::FAST_OCL(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05)
|
||||
|
||||
:param threshold: Threshold on difference between intensity of the central pixel and pixels on a circle around this pixel.
|
||||
|
||||
:param nonmaxSupression: If it is true, non-maximum suppression is applied to detected corners (keypoints).
|
||||
|
||||
:param keypointsRatio: Inner buffer size for keypoints store is determined as (keypointsRatio * image_width * image_height).
|
||||
|
||||
|
||||
|
||||
ocl::FAST_OCL::operator ()
|
||||
----------------------------
|
||||
Finds the keypoints using FAST detector.
|
||||
|
||||
.. ocv:function:: void ocl::FAST_OCL::operator ()(const oclMat& image, const oclMat& mask, oclMat& keypoints)
|
||||
.. ocv:function:: void ocl::FAST_OCL::operator ()(const oclMat& image, const oclMat& mask, std::vector<KeyPoint>& keypoints)
|
||||
|
||||
:param image: Image where keypoints (corners) are detected. Only 8-bit grayscale images are supported.
|
||||
|
||||
:param mask: Optional input mask that marks the regions where we should detect features.
|
||||
|
||||
:param keypoints: The output vector of keypoints. Can be stored both in host or device memory. For device memory:
|
||||
|
||||
* X_ROW of keypoints will contain the horizontal coordinate of the i'th point
|
||||
* Y_ROW of keypoints will contain the vertical coordinate of the i'th point
|
||||
* RESPONSE_ROW will contain response of i'th point (if non-maximum suppression is applied)
|
||||
|
||||
|
||||
|
||||
ocl::FAST_OCL::downloadKeypoints
|
||||
----------------------------------
|
||||
Download keypoints from device to host memory.
|
||||
|
||||
.. ocv:function:: void ocl::FAST_OCL::downloadKeypoints(const oclMat& d_keypoints, std::vector<KeyPoint>& keypoints)
|
||||
|
||||
|
||||
|
||||
ocl::FAST_OCL::convertKeypoints
|
||||
---------------------------------
|
||||
Converts keypoints from OpenCL representation to vector of ``KeyPoint``.
|
||||
|
||||
.. ocv:function:: void ocl::FAST_OCL::convertKeypoints(const Mat& h_keypoints, std::vector<KeyPoint>& keypoints)
|
||||
|
||||
|
||||
|
||||
ocl::FAST_OCL::release
|
||||
------------------------
|
||||
Releases inner buffer memory.
|
||||
|
||||
.. ocv:function:: void ocl::FAST_OCL::release()
|
||||
|
||||
|
||||
|
||||
ocl::FAST_OCL::calcKeyPointsLocation
|
||||
--------------------------------------
|
||||
Find keypoints. If ``nonmaxSupression`` is true, responses are computed and eliminates keypoints with the smaller responses from 9-neighborhood regions.
|
||||
|
||||
.. ocv:function:: int ocl::FAST_OCL::calcKeyPointsLocation(const oclMat& image, const oclMat& mask)
|
||||
|
||||
:param image: Image where keypoints (corners) are detected. Only 8-bit grayscale images are supported.
|
||||
|
||||
:param mask: Optional input mask that marks the regions where we should detect features.
|
||||
|
||||
The function returns the amount of detected keypoints.
|
||||
|
||||
|
||||
|
||||
ocl::FAST_OCL::getKeyPoints
|
||||
-----------------------------
|
||||
Gets final array of keypoints.
|
||||
|
||||
.. ocv:function:: int ocl::FAST_OCL::getKeyPoints(oclMat& keypoints)
|
||||
|
||||
:param keypoints: The output vector of keypoints.
|
||||
|
||||
The function performs non-max suppression if needed and returns the final amount of keypoints.
|
||||
|
||||
|
||||
|
||||
ocl::HOGDescriptor
|
||||
----------------------
|
||||
|
||||
|
@ -1482,6 +1482,65 @@ namespace cv
|
||||
harrisK = harrisK_;
|
||||
}
|
||||
|
||||
////////////////////////////////// FAST Feature Detector //////////////////////////////////
|
||||
class CV_EXPORTS FAST_OCL
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
X_ROW = 0,
|
||||
Y_ROW,
|
||||
RESPONSE_ROW,
|
||||
ROWS_COUNT
|
||||
};
|
||||
|
||||
// all features have same size
|
||||
static const int FEATURE_SIZE = 7;
|
||||
|
||||
explicit FAST_OCL(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05);
|
||||
|
||||
//! finds the keypoints using FAST detector
|
||||
//! supports only CV_8UC1 images
|
||||
void operator ()(const oclMat& image, const oclMat& mask, oclMat& keypoints);
|
||||
void operator ()(const oclMat& image, const oclMat& mask, std::vector<KeyPoint>& keypoints);
|
||||
|
||||
//! download keypoints from device to host memory
|
||||
static void downloadKeypoints(const oclMat& d_keypoints, std::vector<KeyPoint>& keypoints);
|
||||
|
||||
//! convert keypoints to KeyPoint vector
|
||||
static void convertKeypoints(const Mat& h_keypoints, std::vector<KeyPoint>& keypoints);
|
||||
|
||||
//! release temporary buffer's memory
|
||||
void release();
|
||||
|
||||
bool nonmaxSupression;
|
||||
|
||||
int threshold;
|
||||
|
||||
//! max keypoints = keypointsRatio * img.size().area()
|
||||
double keypointsRatio;
|
||||
|
||||
//! find keypoints and compute it's response if nonmaxSupression is true
|
||||
//! return count of detected keypoints
|
||||
int calcKeyPointsLocation(const oclMat& image, const oclMat& mask);
|
||||
|
||||
//! get final array of keypoints
|
||||
//! performs nonmax supression if needed
|
||||
//! return final count of keypoints
|
||||
int getKeyPoints(oclMat& keypoints);
|
||||
|
||||
private:
|
||||
oclMat kpLoc_;
|
||||
int count_;
|
||||
|
||||
oclMat score_;
|
||||
|
||||
oclMat d_keypoints_;
|
||||
|
||||
int calcKeypointsOCL(const oclMat& img, const oclMat& mask, int maxKeypoints);
|
||||
int nonmaxSupressionOCL(oclMat& keypoints);
|
||||
};
|
||||
|
||||
/////////////////////////////// PyrLKOpticalFlow /////////////////////////////////////
|
||||
|
||||
class CV_EXPORTS PyrLKOpticalFlow
|
||||
|
93
modules/ocl/perf/perf_fast.cpp
Normal file
93
modules/ocl/perf/perf_fast.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*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) 2013, OpenCV Foundation, 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 materials 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 implied warranties, including, but not limited to, the implied
|
||||
// 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.
|
||||
//
|
||||
// Authors:
|
||||
// * Peter Andreas Entschev, peter@entschev.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
using namespace perf;
|
||||
|
||||
///////////// FAST ////////////////////////
|
||||
|
||||
typedef std::tr1::tuple<std::string, int, bool> Image_Threshold_NonmaxSupression_t;
|
||||
typedef perf::TestBaseWithParam<Image_Threshold_NonmaxSupression_t> Image_Threshold_NonmaxSupression;
|
||||
|
||||
PERF_TEST_P(Image_Threshold_NonmaxSupression, FAST,
|
||||
testing::Combine(testing::Values<string>("gpu/perf/aloe.png"),
|
||||
testing::Values(20),
|
||||
testing::Bool()))
|
||||
{
|
||||
const Image_Threshold_NonmaxSupression_t params = GetParam();
|
||||
const std::string imgFile = std::tr1::get<0>(params);
|
||||
const int threshold = std::tr1::get<1>(params);
|
||||
const bool nonmaxSupression = std::tr1::get<2>(params);
|
||||
|
||||
const cv::Mat img = imread(getDataPath(imgFile), cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(img.empty());
|
||||
|
||||
if (RUN_OCL_IMPL)
|
||||
{
|
||||
cv::ocl::FAST_OCL fast(threshold, nonmaxSupression, 0.5);
|
||||
|
||||
cv::ocl::oclMat d_img(img);
|
||||
cv::ocl::oclMat d_keypoints;
|
||||
|
||||
OCL_TEST_CYCLE() fast(d_img, cv::ocl::oclMat(), d_keypoints);
|
||||
|
||||
std::vector<cv::KeyPoint> ocl_keypoints;
|
||||
fast.downloadKeypoints(d_keypoints, ocl_keypoints);
|
||||
|
||||
sortKeyPoints(ocl_keypoints);
|
||||
|
||||
SANITY_CHECK_KEYPOINTS(ocl_keypoints);
|
||||
}
|
||||
else if (RUN_PLAIN_IMPL)
|
||||
{
|
||||
std::vector<cv::KeyPoint> cpu_keypoints;
|
||||
|
||||
TEST_CYCLE() cv::FAST(img, cpu_keypoints, threshold, nonmaxSupression);
|
||||
|
||||
SANITY_CHECK_KEYPOINTS(cpu_keypoints);
|
||||
}
|
||||
else
|
||||
OCL_PERF_ELSE;
|
||||
}
|
@ -116,6 +116,7 @@ using namespace cv;
|
||||
#define OCL_TEST_CYCLE() for(; startTimer(), next(); cv::ocl::finish(), stopTimer())
|
||||
#define OCL_TEST_CYCLE_MULTIRUN(runsNum) for(declare.runs(runsNum); startTimer(), next(); stopTimer()) for(int r = 0; r < runsNum; cv::ocl::finish(), ++r)
|
||||
|
||||
// TODO: Move to the ts module
|
||||
namespace cvtest {
|
||||
namespace ocl {
|
||||
inline void checkDeviceMaxMemoryAllocSize(const Size& size, int type, int factor = 1)
|
||||
@ -133,6 +134,60 @@ inline void checkDeviceMaxMemoryAllocSize(const Size& size, int type, int factor
|
||||
throw perf::TestBase::PerfSkipTestException();
|
||||
}
|
||||
}
|
||||
|
||||
struct KeypointIdxCompare
|
||||
{
|
||||
std::vector<cv::KeyPoint>* keypoints;
|
||||
|
||||
explicit KeypointIdxCompare(std::vector<cv::KeyPoint>* _keypoints) : keypoints(_keypoints) {}
|
||||
|
||||
bool operator ()(size_t i1, size_t i2) const
|
||||
{
|
||||
cv::KeyPoint kp1 = (*keypoints)[i1];
|
||||
cv::KeyPoint kp2 = (*keypoints)[i2];
|
||||
if (kp1.pt.x != kp2.pt.x)
|
||||
return kp1.pt.x < kp2.pt.x;
|
||||
if (kp1.pt.y != kp2.pt.y)
|
||||
return kp1.pt.y < kp2.pt.y;
|
||||
if (kp1.response != kp2.response)
|
||||
return kp1.response < kp2.response;
|
||||
return kp1.octave < kp2.octave;
|
||||
}
|
||||
};
|
||||
|
||||
inline void sortKeyPoints(std::vector<cv::KeyPoint>& keypoints, cv::InputOutputArray _descriptors = cv::noArray())
|
||||
{
|
||||
std::vector<size_t> indexies(keypoints.size());
|
||||
for (size_t i = 0; i < indexies.size(); ++i)
|
||||
indexies[i] = i;
|
||||
|
||||
std::sort(indexies.begin(), indexies.end(), KeypointIdxCompare(&keypoints));
|
||||
|
||||
std::vector<cv::KeyPoint> new_keypoints;
|
||||
cv::Mat new_descriptors;
|
||||
|
||||
new_keypoints.resize(keypoints.size());
|
||||
|
||||
cv::Mat descriptors;
|
||||
if (_descriptors.needed())
|
||||
{
|
||||
descriptors = _descriptors.getMat();
|
||||
new_descriptors.create(descriptors.size(), descriptors.type());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < indexies.size(); ++i)
|
||||
{
|
||||
size_t new_idx = indexies[i];
|
||||
new_keypoints[i] = keypoints[new_idx];
|
||||
if (!new_descriptors.empty())
|
||||
descriptors.row((int) new_idx).copyTo(new_descriptors.row((int) i));
|
||||
}
|
||||
|
||||
keypoints.swap(new_keypoints);
|
||||
if (_descriptors.needed())
|
||||
new_descriptors.copyTo(_descriptors);
|
||||
}
|
||||
|
||||
} // namespace cvtest::ocl
|
||||
} // namespace cvtest
|
||||
|
||||
|
229
modules/ocl/src/fast.cpp
Normal file
229
modules/ocl/src/fast.cpp
Normal file
@ -0,0 +1,229 @@
|
||||
/*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) 2013, OpenCV Foundation, 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 materials 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 implied warranties, including, but not limited to, the implied
|
||||
// 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.
|
||||
//
|
||||
// Authors:
|
||||
// * Peter Andreas Entschev, peter@entschev.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "opencl_kernels.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::ocl;
|
||||
|
||||
cv::ocl::FAST_OCL::FAST_OCL(int _threshold, bool _nonmaxSupression, double _keypointsRatio) :
|
||||
nonmaxSupression(_nonmaxSupression), threshold(_threshold), keypointsRatio(_keypointsRatio), count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
void cv::ocl::FAST_OCL::operator ()(const oclMat& image, const oclMat& mask, std::vector<KeyPoint>& keypoints)
|
||||
{
|
||||
if (image.empty())
|
||||
return;
|
||||
|
||||
(*this)(image, mask, d_keypoints_);
|
||||
downloadKeypoints(d_keypoints_, keypoints);
|
||||
}
|
||||
|
||||
void cv::ocl::FAST_OCL::downloadKeypoints(const oclMat& d_keypoints, std::vector<KeyPoint>& keypoints)
|
||||
{
|
||||
if (d_keypoints.empty())
|
||||
return;
|
||||
|
||||
Mat h_keypoints(d_keypoints);
|
||||
convertKeypoints(h_keypoints, keypoints);
|
||||
}
|
||||
|
||||
void cv::ocl::FAST_OCL::convertKeypoints(const Mat& h_keypoints, std::vector<KeyPoint>& keypoints)
|
||||
{
|
||||
if (h_keypoints.empty())
|
||||
return;
|
||||
|
||||
CV_Assert(h_keypoints.rows == ROWS_COUNT && h_keypoints.elemSize() == 4);
|
||||
|
||||
int npoints = h_keypoints.cols;
|
||||
|
||||
keypoints.resize(npoints);
|
||||
|
||||
const float* loc_x = h_keypoints.ptr<float>(X_ROW);
|
||||
const float* loc_y = h_keypoints.ptr<float>(Y_ROW);
|
||||
const float* response_row = h_keypoints.ptr<float>(RESPONSE_ROW);
|
||||
|
||||
for (int i = 0; i < npoints; ++i)
|
||||
{
|
||||
KeyPoint kp(loc_x[i], loc_y[i], static_cast<float>(FEATURE_SIZE), -1, response_row[i]);
|
||||
keypoints[i] = kp;
|
||||
}
|
||||
}
|
||||
|
||||
void cv::ocl::FAST_OCL::operator ()(const oclMat& img, const oclMat& mask, oclMat& keypoints)
|
||||
{
|
||||
calcKeyPointsLocation(img, mask);
|
||||
keypoints.cols = getKeyPoints(keypoints);
|
||||
}
|
||||
|
||||
int cv::ocl::FAST_OCL::calcKeyPointsLocation(const oclMat& img, const oclMat& mask)
|
||||
{
|
||||
CV_Assert(img.type() == CV_8UC1);
|
||||
CV_Assert(mask.empty() || (mask.type() == CV_8UC1 && mask.size() == img.size()));
|
||||
|
||||
int maxKeypoints = static_cast<int>(keypointsRatio * img.size().area());
|
||||
|
||||
ensureSizeIsEnough(ROWS_COUNT, maxKeypoints, CV_32SC1, kpLoc_);
|
||||
kpLoc_.setTo(Scalar::all(0));
|
||||
|
||||
if (nonmaxSupression)
|
||||
{
|
||||
ensureSizeIsEnough(img.size(), CV_32SC1, score_);
|
||||
score_.setTo(Scalar::all(0));
|
||||
}
|
||||
|
||||
count_ = calcKeypointsOCL(img, mask, maxKeypoints);
|
||||
count_ = std::min(count_, maxKeypoints);
|
||||
|
||||
return count_;
|
||||
}
|
||||
|
||||
int cv::ocl::FAST_OCL::calcKeypointsOCL(const oclMat& img, const oclMat& mask, int maxKeypoints)
|
||||
{
|
||||
size_t localThreads[3] = {16, 16, 1};
|
||||
size_t globalThreads[3] = {divUp(img.cols - 6, localThreads[0]) * localThreads[0],
|
||||
divUp(img.rows - 6, localThreads[1]) * localThreads[1],
|
||||
1};
|
||||
|
||||
Context *clCxt = Context::getContext();
|
||||
String kernelName = (mask.empty()) ? "calcKeypoints" : "calcKeypointsWithMask";
|
||||
std::vector< std::pair<size_t, const void *> > args;
|
||||
|
||||
int counter = 0;
|
||||
int err = CL_SUCCESS;
|
||||
cl_mem counterCL = clCreateBuffer(*(cl_context*)clCxt->getOpenCLContextPtr(),
|
||||
CL_MEM_COPY_HOST_PTR, sizeof(int),
|
||||
&counter, &err);
|
||||
|
||||
int kpLocStep = kpLoc_.step / kpLoc_.elemSize();
|
||||
int scoreStep = score_.step / score_.elemSize();
|
||||
int nms = (nonmaxSupression) ? 1 : 0;
|
||||
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&img.data));
|
||||
if (!mask.empty()) args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data));
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&kpLoc_.data));
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&score_.data));
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&counterCL));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&nms));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&maxKeypoints));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&threshold));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&img.step));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&img.rows));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&img.cols));
|
||||
if (!mask.empty()) args.push_back( std::make_pair( sizeof(cl_int), (void *)&mask.step));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&kpLocStep));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&scoreStep));
|
||||
|
||||
openCLExecuteKernel(clCxt, &featdetect_fast, kernelName, globalThreads, localThreads, args, -1, -1);
|
||||
|
||||
openCLSafeCall(clEnqueueReadBuffer(*(cl_command_queue*)clCxt->getOpenCLCommandQueuePtr(),
|
||||
counterCL, CL_TRUE, 0, sizeof(int), &counter, 0, NULL, NULL));
|
||||
openCLSafeCall(clReleaseMemObject(counterCL));
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
int cv::ocl::FAST_OCL::nonmaxSupressionOCL(oclMat& keypoints)
|
||||
{
|
||||
size_t localThreads[3] = {256, 1, 1};
|
||||
size_t globalThreads[3] = {count_, 1, 1};
|
||||
|
||||
Context *clCxt = Context::getContext();
|
||||
String kernelName = "nonmaxSupression";
|
||||
std::vector< std::pair<size_t, const void *> > args;
|
||||
|
||||
int counter = 0;
|
||||
int err = CL_SUCCESS;
|
||||
cl_mem counterCL = clCreateBuffer(*(cl_context*)clCxt->getOpenCLContextPtr(),
|
||||
CL_MEM_COPY_HOST_PTR, sizeof(int),
|
||||
&counter, &err);
|
||||
|
||||
int kpLocStep = kpLoc_.step / kpLoc_.elemSize();
|
||||
int sStep = score_.step / score_.elemSize();
|
||||
int kStep = keypoints.step / keypoints.elemSize();
|
||||
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&kpLoc_.data));
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&score_.data));
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&keypoints.data));
|
||||
args.push_back( std::make_pair( sizeof(cl_mem), (void *)&counterCL));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&count_));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&kpLocStep));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&sStep));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&kStep));
|
||||
|
||||
openCLExecuteKernel(clCxt, &featdetect_fast, kernelName, globalThreads, localThreads, args, -1, -1);
|
||||
|
||||
openCLSafeCall(clEnqueueReadBuffer(*(cl_command_queue*)clCxt->getOpenCLCommandQueuePtr(),
|
||||
counterCL, CL_TRUE, 0, sizeof(int), &counter, 0, NULL, NULL));
|
||||
openCLSafeCall(clReleaseMemObject(counterCL));
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
int cv::ocl::FAST_OCL::getKeyPoints(oclMat& keypoints)
|
||||
{
|
||||
if (count_ == 0)
|
||||
return 0;
|
||||
|
||||
if (nonmaxSupression)
|
||||
{
|
||||
ensureSizeIsEnough(ROWS_COUNT, count_, CV_32FC1, keypoints);
|
||||
return nonmaxSupressionOCL(keypoints);
|
||||
}
|
||||
|
||||
kpLoc_.convertTo(keypoints, CV_32FC1);
|
||||
Mat k = keypoints;
|
||||
|
||||
return count_;
|
||||
}
|
||||
|
||||
void cv::ocl::FAST_OCL::release()
|
||||
{
|
||||
kpLoc_.release();
|
||||
score_.release();
|
||||
|
||||
d_keypoints_.release();
|
||||
}
|
1331
modules/ocl/src/opencl/featdetect_fast.cl
Normal file
1331
modules/ocl/src/opencl/featdetect_fast.cl
Normal file
File diff suppressed because it is too large
Load Diff
93
modules/ocl/test/test_fast.cpp
Normal file
93
modules/ocl/test/test_fast.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*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) 2013, OpenCV Foundation, 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 materials 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 implied warranties, including, but not limited to, the implied
|
||||
// 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.
|
||||
//
|
||||
// Authors:
|
||||
// * Peter Andreas Entschev, peter@entschev.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// FAST
|
||||
|
||||
namespace
|
||||
{
|
||||
IMPLEMENT_PARAM_CLASS(FAST_Threshold, int)
|
||||
IMPLEMENT_PARAM_CLASS(FAST_NonmaxSupression, bool)
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(FAST, FAST_Threshold, FAST_NonmaxSupression)
|
||||
{
|
||||
int threshold;
|
||||
bool nonmaxSupression;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
threshold = GET_PARAM(0);
|
||||
nonmaxSupression = GET_PARAM(1);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(FAST, Accuracy)
|
||||
{
|
||||
cv::Mat image = readImage("gpu/perf/aloe.png", cv::IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(image.empty());
|
||||
|
||||
cv::ocl::FAST_OCL fast(threshold);
|
||||
fast.nonmaxSupression = nonmaxSupression;
|
||||
|
||||
cv::ocl::oclMat ocl_image = cv::ocl::oclMat(image);
|
||||
|
||||
std::vector<cv::KeyPoint> keypoints;
|
||||
fast(ocl_image, cv::ocl::oclMat(), keypoints);
|
||||
|
||||
std::vector<cv::KeyPoint> keypoints_gold;
|
||||
cv::FAST(image, keypoints_gold, threshold, nonmaxSupression);
|
||||
|
||||
ASSERT_KEYPOINTS_EQ(keypoints_gold, keypoints);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(OCL_Features2D, FAST, testing::Combine(
|
||||
testing::Values(FAST_Threshold(25), FAST_Threshold(50)),
|
||||
testing::Values(FAST_NonmaxSupression(false), FAST_NonmaxSupression(true))));
|
||||
|
||||
#endif
|
@ -259,4 +259,70 @@ void showDiff(const Mat& src, const Mat& gold, const Mat& actual, double eps, bo
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
bool keyPointsEquals(const cv::KeyPoint& p1, const cv::KeyPoint& p2)
|
||||
{
|
||||
const double maxPtDif = 1.0;
|
||||
const double maxSizeDif = 1.0;
|
||||
const double maxAngleDif = 2.0;
|
||||
const double maxResponseDif = 0.1;
|
||||
|
||||
double dist = cv::norm(p1.pt - p2.pt);
|
||||
|
||||
if (dist < maxPtDif &&
|
||||
fabs(p1.size - p2.size) < maxSizeDif &&
|
||||
abs(p1.angle - p2.angle) < maxAngleDif &&
|
||||
abs(p1.response - p2.response) < maxResponseDif &&
|
||||
p1.octave == p2.octave &&
|
||||
p1.class_id == p2.class_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
struct KeyPointLess : std::binary_function<cv::KeyPoint, cv::KeyPoint, bool>
|
||||
{
|
||||
bool operator()(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2) const
|
||||
{
|
||||
return kp1.pt.y < kp2.pt.y || (kp1.pt.y == kp2.pt.y && kp1.pt.x < kp2.pt.x);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
testing::AssertionResult assertKeyPointsEquals(const char* gold_expr, const char* actual_expr, std::vector<cv::KeyPoint>& gold, std::vector<cv::KeyPoint>& actual)
|
||||
{
|
||||
if (gold.size() != actual.size())
|
||||
{
|
||||
return testing::AssertionFailure() << "KeyPoints size mistmach\n"
|
||||
<< "\"" << gold_expr << "\" : " << gold.size() << "\n"
|
||||
<< "\"" << actual_expr << "\" : " << actual.size();
|
||||
}
|
||||
|
||||
std::sort(actual.begin(), actual.end(), KeyPointLess());
|
||||
std::sort(gold.begin(), gold.end(), KeyPointLess());
|
||||
|
||||
for (size_t i = 0; i < gold.size(); ++i)
|
||||
{
|
||||
const cv::KeyPoint& p1 = gold[i];
|
||||
const cv::KeyPoint& p2 = actual[i];
|
||||
|
||||
if (!keyPointsEquals(p1, p2))
|
||||
{
|
||||
return testing::AssertionFailure() << "KeyPoints differ at " << i << "\n"
|
||||
<< "\"" << gold_expr << "\" vs \"" << actual_expr << "\" : \n"
|
||||
<< "pt : " << testing::PrintToString(p1.pt) << " vs " << testing::PrintToString(p2.pt) << "\n"
|
||||
<< "size : " << p1.size << " vs " << p2.size << "\n"
|
||||
<< "angle : " << p1.angle << " vs " << p2.angle << "\n"
|
||||
<< "response : " << p1.response << " vs " << p2.response << "\n"
|
||||
<< "octave : " << p1.octave << " vs " << p2.octave << "\n"
|
||||
<< "class_id : " << p1.class_id << " vs " << p2.class_id;
|
||||
}
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
|
||||
} // namespace cvtest
|
||||
|
@ -54,6 +54,9 @@ extern int LOOP_TIMES;
|
||||
|
||||
namespace cvtest {
|
||||
|
||||
testing::AssertionResult assertKeyPointsEquals(const char* gold_expr, const char* actual_expr, std::vector<cv::KeyPoint>& gold, std::vector<cv::KeyPoint>& actual);
|
||||
#define ASSERT_KEYPOINTS_EQ(gold, actual) EXPECT_PRED_FORMAT2(assertKeyPointsEquals, gold, actual)
|
||||
|
||||
void showDiff(const Mat& src, const Mat& gold, const Mat& actual, double eps, bool alwaysShow = false);
|
||||
|
||||
cv::ocl::oclMat createMat_ocl(cv::RNG& rng, Size size, int type, bool useRoi);
|
||||
|
Loading…
Reference in New Issue
Block a user