Archive 17/01/2023.

openCV Mat to Urho3D Texture2D

SteveU3D

Hi,

I would like to get images from a camera with openCV and then convert those images to display them on a 3D object in Urho3D. So I need to convert a cvMat to Texture2D.
I tried :
Texture2D *videoTexture = new Texture2D(context_);
bool success = videoTexture->SetData(0,0,0,mycvmat.cols, mycvmat.rows,mycvmat.data); //where mycvmat is from cap = cv::VideoCapture(0); cap >> mycvmat;
But SetData keeps returning false.

Any ideas?
Thanks

cadaver

You need to call Texture2D::SetSize to create the actual GPU texture with the specified size & format. Otherwise SetData will always fail, as there’s nowhere to set the data to.

SteveU3D

Indeed, it works with setSize.
Thanks!