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

后端 未结 2 1805
慢半拍i
慢半拍i 2021-02-03 12:14

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.

2条回答
  •  旧时难觅i
    2021-02-03 12:43

    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(...);
    

提交回复
热议问题