Use OpenCL feature detector.

asked 2018-12-12 02:10:26 -0600

Rakshith gravatar image

updated 2018-12-12 02:11:22 -0600

How to use OpenCL based feature detector? According to the source code (here) There is opencl version of AKAZE,FAST and ORB. I want to know how to use them in C++ ?

I tried importing #include <opencv2/core/ocl.hpp> and then I also set cv::ocl::setUseOpenCL(true); and for sanity check I did cv::ocl::haveOpenCL(). Doing these I can confirm I've built OpenCV with OpenCL support.

That being said I tried converting all cv::Mat to cv::UMat. Now the program crashes at detector->detectAndCompute(umat, cv::noArray(), kp1, des1);. I'm using AKAZE.

The error on the console is:

OpenCV(4.0.0-dev) Error: Requested object was not found (could not open directory: C:\Users\PC\AppData\Local\Temp\opencv) in glob_rec, file e:\cv4.0\opencv\modules\core\src\glob.cpp, line 267

The callstack error says :

  • _err "could not open directory: C:\Users\PC\AppData\Local\Temp\opencv" const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &

I've initialised it like this:

detector = cv::AKAZE::create();
detector->setThreshold(akaze_thresh);

Is this is the right way to use OpenCL version of AKAZE? If yes, how do I fix the error? If not, how do I use OpenCL version of AKAZE?

edit retag flag offensive close merge delete

Comments

1

I tried this :

Mat z = imread("lena.jpg", IMREAD_GRAYSCALE);
UMat zz;
z.copyTo(zz);
Ptr<cv::AKAZE> detector = cv::AKAZE::create();
std::vector< KeyPoint >  kp1;
Mat des1;
detector->detectAndCompute(zz, cv::noArray(), kp1, des1);

No exception. Can you give platform and opencv version used?

LBerger gravatar imageLBerger ( 2018-12-12 02:49:34 -0600 )edit

Windows 10, Visual Studio 2017, OpenCV 4.0. Shouldn't des1 also be a UMat?

Rakshith gravatar imageRakshith ( 2018-12-12 02:58:01 -0600 )edit

what a weird error. can you take a look, if C:\Users\PC\AppData\Local\Temp\opencv exists ? it should contain a .lock file, and a folder named similar to Intel_R__Corporation--Intel_R__HD_Graphics--10_18_10_4276 (hw vendor) ?

berak gravatar imageberak ( 2018-12-12 03:08:49 -0600 )edit

That folder doesn't exist.

Rakshith gravatar imageRakshith ( 2018-12-12 03:11:23 -0600 )edit

opencv tries to cache compiled opencl kernels there. do you (your program) have write access to it ?

berak gravatar imageberak ( 2018-12-12 03:16:55 -0600 )edit

How do I check this or make sure it does?

Rakshith gravatar imageRakshith ( 2018-12-12 03:18:15 -0600 )edit

"That folder doesn't exist." ? Have you got C:\Users\PC\AppData\Local\Temp\opencv?

or Have you got C:\Users\PC\AppData\Local\Temp\?

or

Have you got C:\Users\PC\AppData\Local?

LBerger gravatar imageLBerger ( 2018-12-12 06:29:44 -0600 )edit

I've got "C:\Users\PC\AppData\Local\Temp\"

Rakshith gravatar imageRakshith ( 2018-12-12 06:43:18 -0600 )edit

Can you check security attribuet in folder properties ? stack trace is here

LBerger gravatar imageLBerger ( 2018-12-12 07:10:52 -0600 )edit

@LBerger, how did you get that trace ?

@Rakshith, maybe run a little test prog like:

UMat m(100,100,CV_8UC3, Scalar(100,200,0));
UMat r;
GaussianBlur(m,r,Size(5,5),0);

in DEBUG mode, you should see output like this:

[ INFO:0] Initialize OpenCL runtime...
[ INFO:0] Successfully initialized OpenCL cache directory: C:\Users\ppp\AppData\Local\Temp\opencv\4.0-dev\opencl_cache\
[ INFO:0] Preparing OpenCL cache configuration for context: Intel_R__Corporation--Intel_R__HD_Graphics--10_18_10_4276
berak gravatar imageberak ( 2018-12-12 07:26:06 -0600 )edit