Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to bind a OpenCV GpuMat as an OpenGL texture?

I haven't been able to find any reference except for:

http://answers.opencv.org/question/9512/how-to-bind-gpumat-to-texture/

which discusses a CUDA approach.

Ideally I'd like to update an OpenGL texture with the contents of a cv::gpu::GpuMat without copying back to CPU, and without directly using CUDA (although i presume this may be necessary until this feature is added).

like image 907
Elliot Woods Avatar asked Aug 06 '13 17:08

Elliot Woods


1 Answers

OpenCV has OpenGL support. See opencv2/core/opengl_interop.hpp header file. You can copy the content of GpuMat to Texture:

cv::gpu::GpuMat d_mat(768, 1024, CV_8UC3);
cv::ogl::Texture2D tex;
tex.copyFrom(d_mat);
tex.bind();
// draw something

You can also use cv::ogl::Buffer class. It is a wrapper for OpenGL buffer memory. This memory can be mapped to CUDA memory without memory copy:

cv::ogl::Buffer ogl_buf(1, 1000, CV_32FC3);
cv::gpu::GpuMat d_mat = ogl_buf.mapDevice();
// fill d_mat with CUDA
ogl_buf.unmapDevice();
// use ogl_buf in OpenGL
ogl_buf.bind(cv::ogl::Buffer::ARRAY_BUFFER);
glDrawArray(...);
like image 193
jet47 Avatar answered Sep 18 '22 17:09

jet47