将数组从c#传递给c ++ like参数

时间:2017-08-29 10:21:41

标签: c# c++ opencv

我在C#中使用本机代码。我正在尝试使用Pinvoke将数组从C#传递给C ++。一旦进入C ++,我想填充我作为参数传递的数组,其中包含cv :: Mat的值。问题是我正在使用复制功能,我认为参数不会发生这种情况。有谁能够帮我?问候,谢谢。

C ++代码:

__declspec(dllexport)
void ProcessFrame(unsigned char* arr) {
VideoCapture camera;
if (!camera.open(0))
{
    return;
}

Mat frame;
camera >> frame;
if (frame.empty()) {
    return;
}
int tam = frame.cols * frame.rows;
copy(frame.begin, frame.end, arr);
}

C#代码:

[DllImport("NativoPrincipio.dll")]
public static extern void ProcessFrame(out byte[] img);

        byte[] imgData = new byte[webcamTexture.width * webcamTexture.height];
        ProcessFrame(out imgData);

        Debug.Log(imgData.Length);
        Texture2D tex = new Texture2D(webcamTexture.width, webcamTexture.height, TextureFormat.RGB24, false);
        tex.LoadRawTextureData(imgData);
        tex.Apply();
        GetComponent<Renderer>().material.mainTexture = tex;

0 个答案:

没有答案