Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.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++;使用OpenCV创建Unity3D? 我在把图像从C++转换成UNIIDE3D(C语言)时遇到了麻烦。我使用OpenCV读取Mat类型图像,并使用img.data获取数据点。当我构建了 DLL并调用相应函数时,我得到了错误,所有字节数组中的数据都是0,所以我想知道如何将图像从C++传递到C。多谢各位_C#_C++_Opencv_Unity3d - Fatal编程技术网

C# 如何从C++;使用OpenCV创建Unity3D? 我在把图像从C++转换成UNIIDE3D(C语言)时遇到了麻烦。我使用OpenCV读取Mat类型图像,并使用img.data获取数据点。当我构建了 DLL并调用相应函数时,我得到了错误,所有字节数组中的数据都是0,所以我想知道如何将图像从C++传递到C。多谢各位

C# 如何从C++;使用OpenCV创建Unity3D? 我在把图像从C++转换成UNIIDE3D(C语言)时遇到了麻烦。我使用OpenCV读取Mat类型图像,并使用img.data获取数据点。当我构建了 DLL并调用相应函数时,我得到了错误,所有字节数组中的数据都是0,所以我想知道如何将图像从C++传递到C。多谢各位,c#,c++,opencv,unity3d,C#,C++,Opencv,Unity3d,对不起,迟了答复, 代码如下所示: C++代码: DLL_API BYTE* _stdcall MatToByte() { Mat srcImg = imread("F:\\3121\\image\\image_0\\000000.png"); nHeight = srcImg.rows; nWidth = srcImg.cols; nBytes = nHeight * nWidth * nFlag / 8; if (pImg) del

对不起,迟了答复, 代码如下所示:
C++代码

DLL_API BYTE* _stdcall MatToByte()
{

    Mat srcImg = imread("F:\\3121\\image\\image_0\\000000.png");
    nHeight = srcImg.rows;
    nWidth = srcImg.cols;

    nBytes = nHeight * nWidth * nFlag / 8;
    if (pImg)
        delete[] pImg;

    pImg = new BYTE[nBytes];
    memcpy(pImg, srcImg.data, nBytes);
    return pImg;
}
C#code

    [DllImport("Display")]
    public static extern IntPtr MatToByte();

        byte[] Bytes = new byte[nBytes];
        IntPtr tmp =  MatToByte();
        Marshal.Copy(tmp, Bytes, 0, nBytes);
        Texture2D texture = new Texture2D(width, height);
        texture.LoadImage(Bytes);
        left_plane.GetComponent<Renderer>().material.mainTexture = texture;
[DllImport(“显示”)]
公共静态外部IntPtr MatToByte();
字节[]字节=新字节[N字节];
IntPtr tmp=MatToByte();
封送处理副本(tmp,字节,0,N字节);
纹理2D纹理=新纹理2D(宽度、高度);
加载图像(字节);
left_plane.GetComponent().material.mainTexture=纹理;

需要查看C++中使用的方法的定义,得到字节。提供C++和C语言的代码示例,并给出所得到的错误。首先,检查图像是否被OpenCV正确读取(可能在图片加载期间有错误的路径或任何问题)。然后,如果图像正常,请提供C#调用者的代码,因为我猜可能存在某些类型不匹配