How to convert OpenCV texture to ofTexture

Hi everyone! I’m currently working with OpenCV and I have a GpuMat I want to directly convert to a texture. In opencv, I can create a cv::ogl::Texture2D tex and then call tex.copyFrom(GpuMat). At this point, I know it is somewhere in the VRAM but I’m not so sure how to access it from OF.

Since ofTexture is also a wrapper around openGL’s texture, is there a way I can pass it to OF to draw?

Thanks!

I think so!

Two possible approaches.
1 - use this function of ofTexture. With this call cv::ogl::Texture2D::texId()
( I am not sure if it will work though due to OpenCV maybe having its own GL context? )
2 - Use cv::ogl::Texture2D::copyTo, to copy to a cv::Mat and then load that data to ofPixels and then to a texture.

Thanks for the suggestions! I tried both methods. I even tried to use the loadData + ofTextureData with GpuMat’s data pointer. Still, I couldn’t get it to work as I’ve run into a few errors on the openCV side. It may be a bug or a platform specific thing, though my code could compile, I get a runtime error when I use openCV’s texture2D copyFrom() from a GpuMat. I’ll have to investigate further…