OpenCV Featuredetection with OpenCL

asked 2017-04-12 03:54:01 -0600

TADRIAN gravatar image

updated 2017-04-28 06:35:33 -0600

Hello,

I recently start experimenting with OpenCV, especially with the featuredetectors (eg. SIFT, SURF ...) Now i´m starting to look into OpenCL and I wanted to ask if there is OpenCL "support" for these featuredetectors, because i would like to run these algorithm on a parallel device (Altera Cyclone V SoC)

While browsing through the OpenCV doc I found following a link saying:

"All specialized ocl implemetations has been hidden behind general C++ algorithm interface. Now the function execution path can be selected dynamically at runtime: CPU or OpenCL; this mechanism is also called Transparent API. New class cv::UMat is intended to hide data exchange with OpenCL device in a convinient way."

So if I use UMat instead of Mat with OpenCL enabled the code, which can be run via OpenCL is excecutet on the parallel device? For OpenCV 3.2 I´m not able to find a list which lists the OpenCV functions with are usable with OpenCL (or are the functions the same as in 2.4). So when i declare things with UMat it could be run on the GPU or maybe the CPU but i don´t know exactly what is run on which component?

What would happen if I use this codeexample? 1. Not working 2. Run on CPU because detect isn´t supportet in OpenCL 3. parts from the sift algorithm which are supported in OpenCL run on gpu and other parts run on cpu?

UMat img =imread("..");     
cv::Ptr<cv::xfeatures2d::SiftFeatureDetector> siftDetector = 
      cv::xfeatures2d::SiftFeatureDetector::create();
std::vector<cv::KeyPoint> siftKeypoints;
siftDetector->detect(img, siftKeypoints);

Already asked a quite similar question on stackoverflow a few days ago, but thought this might be a better place for asking this question.

Thanks for reading :)

edit retag flag offensive close merge delete

Comments

Only SURF feature has a proper OpenCL kernel implementation. You can still benefit to the GPU processing for classical operations (color to grayscale conversion, matrix multiplication, etc.) that can be used in the feature detection / description methods.

The best option is to test to see what happens concretely. For your example, I guess that it should work and only operations that have an OpenCL kernel will run on the device (GPU) other operations will run on the host (CPU).

Eduardo gravatar imageEduardo ( 2017-04-28 08:29:03 -0600 )edit

Hello, thanks for the answer. I tried to use OpenCL with the Surf detector, but the time needed for the Mat and the UMat version is nearly the same. Did you test the Surf OpenCL by yourself and noticed the same behaviour? To verify that OpenCL "works" I tried to use "Canny" and "Convert from Color to Grayscale" which runs faster using the UMat version.

TADRIAN gravatar imageTADRIAN ( 2017-05-02 05:45:29 -0600 )edit

I cannot test right now. You should test with a high resolution image for SURF to increase the potential benefit of the GPU. Also, the first call to an OpenCL kernel will "compile" the kernel (see 4.2 Online/Offline Compilation). To properly measure the time, you should average the running time with multiple iterations.

Anyway, I don't know how much the SURF algorithm can benefit of a massively parallel architecture. Maybe what you observe is normal behavior.

Eduardo gravatar imageEduardo ( 2017-05-03 04:12:28 -0600 )edit