Hello, I’m a Japanese university student.
I’m using Zed-2i with Unity.
The versions I’m using are listed below.
・ZED-2i
・ZED Unity Plugin : v3.8.0
・Unity Editor : 2021.3.12
・OpenCV for Unity : 2.5.7
I’m trying to dynamically resize the depth image that obtained by ZED-2i using OpenCV for unity, and output them as Texture2D.
I tried to use the “copyToMat()” function to copy the image’s “Ptr” data into the OpenCV Mat. Because the zed and OpenCV has different mat type, I changed the zed mat type to OpenCV mat type (Referenced sites: ZEDMat to OpenCvMat · Issue #73 · stereolabs/zed-unity · GitHub).
Then use the “resize()” from OpenCV for Unity to resize the image. After resize the OpenCV Mat, I use the “matToTexture2D()” function to copy OpenCV Mat into Texture2D.
My problem is that when I run the system, I get the error “No texture data provided to LoadRawTextureData”.
I want to know where should I fix, or is there any other way to resize the image that ZED-2i obtained.
Here is a part of my code.
void Update()
{
if (zed.IsCameraReady)
{
zed.RetrieveImage(image, VIEW.DEPTH);
Utils.copyToMat(image.GetPtr(), srcMat);
Imgproc.resize(srcMat, dstMat, dstMat.size(), Imgproc.INTER_CUBIC);
_texture2D = new Texture2D(DISP_RESO_X, DISP_RESO_Y, TextureFormat.RGBA32, false);
Utils.matToTexture2D(dstMat, _texture2D, true);
/*Save Image as png*/
byte[] pngData = _texture2D.EncodeToPNG();
string filePath = EditorUtility.SaveFilePanel("Save Texture", "D:\\home\\0065_Mr_One\\Zed2_test3\\Assets", _texture2D.name + "★test_texture.png", "png");
if (filePath.Length > 0)
{
File.WriteAllBytes(filePath, pngData);
}
}
}
Thank you.