I have a small problem that I hope you can help me.
I have this code in c++
:
__declspec(dllexport)
unsigned char* ProcessFrame() {
VideoCapture cam;
cam.open(0);
Mat imagen;
unsigned char* result;
cam >> imagen;
flip(imagen, imagen, 0);
result = new unsigned char[imagen.cols*imagen.rows*4];
memcpy(result, imagen.data, imagen.cols*imagen.rows*4);
return result;
}
I want to use it in Unity, with the following code:
byte[] imgData = ProcessFrame();
Debug.Log(imgData.Length);
Texture2D tex = new Texture2D(320, 240, TextureFormat.RGB24, false);
tex.LoadRawTextureData(imgData);
tex.Apply();
GetComponent<Renderer>().material.mainTexture = tex;
The problem is that he always answers me:
No texture data provided to LoadRawTextureData.
It seems that from C ++ you can not pass pointers as is to C #.