openCV Mat to Urho3D Texture2D


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,; //where mycvmat is from cap = cv::VideoCapture(0); cap >> mycvmat;
But SetData keeps returning false.

Any ideas?

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.

1 Like

Indeed, it works with setSize.