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).
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(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With