Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数组从c#传递到c++;相似参数_C#_C++_Opencv - Fatal编程技术网

将数组从c#传递到c++;相似参数

将数组从c#传递到c++;相似参数,c#,c++,opencv,C#,C++,Opencv,我在C#中使用本机代码。我试图通过Pinvoke将C数组从C++传递到C++。一次在C++中,我想填充我作为参数传递的数组。​​指一个cv::Mat。问题是我使用的是copy函数,我不认为这在参数中发生得很好。有人能帮我吗?你好,谢谢你 C++代码: __declspec(dllexport) void ProcessFrame(unsigned char* arr) { VideoCapture camera; if (!camera.open(0)) { return; } Mat

我在C#中使用本机代码。我试图通过Pinvoke将C数组从C++传递到C++。一次在C++中,我想填充我作为参数传递的数组。​​指一个cv::Mat。问题是我使用的是copy函数,我不认为这在参数中发生得很好。有人能帮我吗?你好,谢谢你

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(“nativoprinciio.dll”)]
公共静态外部void ProcessFrame(out字节[]img);
byte[]imgData=新字节[webcamTexture.width*webcamTexture.height];
ProcessFrame(输出imgData);
Debug.Log(imgData.Length);
Texture2D tex=新的Texture2D(webcamTexture.width、webcamTexture.height、TextureFormat.RGB24、false);
tex.LoadRawTextureData(imgData);
tex.Apply();
GetComponent().material.mainTexture=tex;

您不能使用
新字节
。您必须调用封送拆收器并使签名为
IntPtr
公共静态extedn void ProcessFrame(IntPtr img)GCHandle-hArray=GCHandle.Alloc(byteArray,GCHandleType.pinted);IntPtr ptrArray=hArray.AddrOfPinnedObject();进程帧(ptrArray);自由的不要忘记在C++调用中添加<代码>外部> C >代码,以防止名称的篡改。另一方面,统一瀑布。问题出现在c++复制函数中。我的搭档告诉我不要用memcpy
[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;