将图像/深度数据从Unity C#传递到外部C#dll



我写了一个外部C#dll,它接收图像并进行图像处理以检测手的姿势。我目前正在使用ZigFu统一绑定来获取运动学数据。现在我想把图像/深度数据从Kinect传递到我的C#dll。

以下是代码摘录:

Unity中的C#

h1.detectHandPose(OpenNIContext.Instance.Depth.GetDepthMap().XRes,OpenNIContext.Instance.Depth.GetDepthMap().YRes);

其中h1是我的C#dll类的实例

和C#dll 中的代码

public int detectHandPose(IntPtr srcptr,Int32 w,Int32 h)
{
   int fingerNum = 0;
   Bitmap srcbmp = new Bitmap(w, h, 2,System.Drawing.Imaging.PixelFormat.Format16bppGrayScale, srcptr);
   ccDefects(srcbmp);
   return fingerNum;
}
public Image<Bgr, Byte> ccDefects(Bitmap b)
{
   //all image processing code for convexity defects    
}

然而,我无法运行此程序,并得到以下错误:

ArgumentException:找到了null引用或无效值[GDI+status:InvalidParameter]System.Drawing.GDIPlus.CheckStatus(statusstatus)System.Drawing.Bitmap.ctor(Int32宽度,Int32高度,Int32步幅,PixelFormat格式,IntPtr扫描0)(包装带check的远程调用)System.Drawing.Bitmap:.ctor(int,int,int。System.Drawing.Imaging。PixelFormat,intptr)handDetectionDLL.handDetectionDetectHandPose(IntPtr-srcptr,Int32 h)OpenNIDepthmapViewer.FixedUpdate()(位于Assets/OpenNI/Scripts/OpenNIDepthmapViewer.cs:152)

感谢您的帮助。

谢谢,Kumar

Bitmap()构造函数中的步幅参数是错误的-步幅应该是图像中一行占用的字节数(这是必要的,因为BMP等一些格式要求每行像素都从DWORD对齐的地址或其他一些要求开始)

最新更新