mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
modified OpenCL SURF API and the tests in 2.4.x to prove that it gives different from CPU results
This commit is contained in:
@@ -63,6 +63,20 @@ CV_INIT_ALGORITHM(SIFT, "Feature2D.SIFT",
|
||||
obj.info()->addParam(obj, "edgeThreshold", obj.edgeThreshold);
|
||||
obj.info()->addParam(obj, "sigma", obj.sigma))
|
||||
|
||||
#ifdef HAVE_OPENCV_OCL
|
||||
|
||||
namespace ocl {
|
||||
CV_INIT_ALGORITHM(SURF_OCL, "Feature2D.SURF_OCL",
|
||||
obj.info()->addParam(obj, "hessianThreshold", obj.hessianThreshold);
|
||||
obj.info()->addParam(obj, "nOctaves", obj.nOctaves);
|
||||
obj.info()->addParam(obj, "nOctaveLayers", obj.nOctaveLayers);
|
||||
obj.info()->addParam(obj, "extended", obj.extended);
|
||||
obj.info()->addParam(obj, "upright", obj.upright))
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool initModule_nonfree(void)
|
||||
|
||||
@@ -305,6 +305,11 @@ int cv::ocl::SURF_OCL::descriptorSize() const
|
||||
return extended ? 128 : 64;
|
||||
}
|
||||
|
||||
int cv::ocl::SURF_OCL::descriptorType() const
|
||||
{
|
||||
return CV_32F;
|
||||
}
|
||||
|
||||
void cv::ocl::SURF_OCL::uploadKeypoints(const vector<KeyPoint> &keypoints, oclMat &keypointsGPU)
|
||||
{
|
||||
if (keypoints.empty())
|
||||
@@ -447,6 +452,81 @@ void cv::ocl::SURF_OCL::operator()(const oclMat &img, const oclMat &mask, vector
|
||||
downloadDescriptors(descriptorsGPU, descriptors);
|
||||
}
|
||||
|
||||
|
||||
void cv::ocl::SURF_OCL::operator()(InputArray img, InputArray mask,
|
||||
CV_OUT vector<KeyPoint>& keypoints) const
|
||||
{
|
||||
this->operator()(img, mask, keypoints, noArray(), false);
|
||||
}
|
||||
|
||||
void cv::ocl::SURF_OCL::operator()(InputArray img, InputArray mask, vector<KeyPoint> &keypoints,
|
||||
OutputArray descriptors, bool useProvidedKeypoints) const
|
||||
{
|
||||
oclMat _img, _mask;
|
||||
if(img.kind() == _InputArray::OCL_MAT)
|
||||
_img = *(oclMat*)img.obj;
|
||||
else
|
||||
_img.upload(img.getMat());
|
||||
if(_img.channels() != 1)
|
||||
{
|
||||
oclMat temp;
|
||||
cvtColor(_img, temp, COLOR_BGR2GRAY);
|
||||
_img = temp;
|
||||
}
|
||||
|
||||
if( !mask.empty() )
|
||||
{
|
||||
if(mask.kind() == _InputArray::OCL_MAT)
|
||||
_mask = *(oclMat*)mask.obj;
|
||||
else
|
||||
_mask.upload(mask.getMat());
|
||||
}
|
||||
|
||||
SURF_OCL_Invoker surf((SURF_OCL&)*this, _img, _mask);
|
||||
oclMat keypointsGPU;
|
||||
|
||||
if (!useProvidedKeypoints || !upright)
|
||||
((SURF_OCL*)this)->uploadKeypoints(keypoints, keypointsGPU);
|
||||
|
||||
if (!useProvidedKeypoints)
|
||||
surf.detectKeypoints(keypointsGPU);
|
||||
else if (!upright)
|
||||
surf.findOrientation(keypointsGPU);
|
||||
if(keypointsGPU.cols*keypointsGPU.rows != 0)
|
||||
((SURF_OCL*)this)->downloadKeypoints(keypointsGPU, keypoints);
|
||||
|
||||
if( descriptors.needed() )
|
||||
{
|
||||
oclMat descriptorsGPU;
|
||||
surf.computeDescriptors(keypointsGPU, descriptorsGPU, descriptorSize());
|
||||
Size sz = descriptorsGPU.size();
|
||||
if( descriptors.kind() == _InputArray::STD_VECTOR )
|
||||
{
|
||||
CV_Assert(descriptors.type() == CV_32F);
|
||||
std::vector<float>* v = (std::vector<float>*)descriptors.obj;
|
||||
v->resize(sz.width*sz.height);
|
||||
Mat m(sz, CV_32F, &v->at(0));
|
||||
descriptorsGPU.download(m);
|
||||
}
|
||||
else
|
||||
{
|
||||
descriptors.create(sz, CV_32F);
|
||||
Mat m = descriptors.getMat();
|
||||
descriptorsGPU.download(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cv::ocl::SURF_OCL::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask) const
|
||||
{
|
||||
(*this)(image, mask, keypoints, noArray(), false);
|
||||
}
|
||||
|
||||
void cv::ocl::SURF_OCL::computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors) const
|
||||
{
|
||||
(*this)(image, Mat(), keypoints, descriptors, true);
|
||||
}
|
||||
|
||||
void cv::ocl::SURF_OCL::releaseMemory()
|
||||
{
|
||||
sum.release();
|
||||
|
||||
Reference in New Issue
Block a user