我刚刚找到解决方案(ohh yeahhhhhhhh):)
首先,我需要将我的C#Mat(帧)转换为字节数组 . 然后我创建了一个指针,以指向字节数组地址(这是图像数据) . 在此之后,我调用了C dll方法并将指针作为参数(以及图像的宽度和高度)传递 . 最后在C dll中,我使用C#中的字节数组重建了C Mat .
Unity3D中的代码(C#):
//frame is the C# Mat and byte_array our array of byes
//to initialize the size of our byte array (image pixels * channels)
byte_array= new byte[frame.cols () * frame.rows () * frame.channels ()];
//copy the frame data to our array
Utils.copyFromMat (frame,byte_array);
//initialize a pointer with the apropriate size (array size)
IntPtr pointer = Marshal.AllocHGlobal(byte_array.Length);
Marshal.Copy (byte_array, 0, pointer , byte_array.Length);
//here i call the C++ method (I imported a C++ dll)
myCplusplusMethod(pointer ,frame.height(),frame.width());
//free the pointer
Marshal.FreeHGlobal(pointer );
现在,为了使用来自C#的传递数据在C中重建图像:
void myCplusplusMethod(unsigned char* data,int height,int width){
//btw you have to get the correct type. In my situation I use debug from C# and I found out that my image is CV_8UC3 type.
Mat constructed= Mat(height, width, CV_8UC3, data);
//..do whatever using the image.. (calculations , etc)..
}