Rakshith G B
Rakshith G B

Reputation: 826

Use OpenCV's OpenCL feature detector

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,std::allocator

    &

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?

Upvotes: 3

Views: 1664

Answers (1)

Rakshith G B
Rakshith G B

Reputation: 826

Turns out that for some reason the OpenCL cache folder wasn't getting generated (It should be here - C:\Users\User\AppData\Local\Temp\opencv). I created another project and ran a simple OpenCL program:

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

This generated the required cache folder, I'm now able to run the OpenCL version of AKAZE. Just to be clear for people who are referring this, OpenCL version of AKAZE is not fully implemented as of OpenCV 4.0.0-dev. Only some parts of the algorithm is running on OpenCL and hence the performance is more or less the same compared to original OpenCV AKAZE, the detection is still running on single thread.

There is a cuda verion available here. And a highly multithreaded version available here, which can run at 60 fps on 8 threads. Both these versions are built for OpenCV 3.0.0 and should work with newer releases with small changes.

Upvotes: 1

Related Questions