Ask Your Question

Working on GPU in a generic way

asked 2019-09-12 07:39:17 -0500

alon3 gravatar image

Are there any tools or libraries that belong to opencv that enable GPU work in a generic way?

edit retag flag offensive close merge delete


No. For that you'd need something like OpenGL 4.3, which has compute shaders. Here is a link to a sample compute shader app:

Note that the code requires the GLUT and GLEW libraries.

sjhalayka gravatar imagesjhalayka ( 2019-09-12 12:00:01 -0500 )edit

Compute shaders were made official in 2012, with OpenGL 4.3. They're not new, and they are widely used.

sjhalayka gravatar imagesjhalayka ( 2019-09-13 09:55:32 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-09-13 04:27:40 -0500

kbarni gravatar image

There's a way to execute custom OpenCL code on the GPU from OpenCV using the cv::ocl classes and UMat type images.

Here you can find an example for doing this.

A word of warning: OpenCL code can be difficult to develop. It's massively parallel, has no concurrency checks (so it will crash for any bugs) and it's difficult to debug. OTOH OpenCL is very portable, it runs on most GPUs and on CPUs too (CUDA runs only on nVidia hardware).

I personally prefer using CPU parallelisation using TBB, it's much easier to implement.

Concerning CUDA, there is a cv::cuda namespace for CUDA-based operations. It has several image processing algorithms implemented, but I don't know if it's possible to run generic CUDA code.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-09-12 07:39:17 -0500

Seen: 77 times

Last updated: Sep 13 '19