2012-02-13 20 views
0

我已經編寫了一個外部C#dll,它接受一個圖像並執行用於檢測手部姿勢的圖像處理。 我目前使用ZigFu統一綁定獲取kinect數據。現在我想要將來自Kinect的圖像/深度數據傳遞給我的C#dll。將來自Unity C#的圖像/深度數據傳遞給外部C#dll

以下是代碼提取物:

C#在Unity

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

其中h1是我的C#DLL類

和代碼在C#DLL的instace

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: A null reference or invalid value was found [GDI+ status: InvalidParameter] System.Drawing.GDIPlus.CheckStatus (Status status) System.Drawing.Bitmap..ctor (Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0) (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (int,int,int,System.Drawing.Imaging.PixelFormat,intptr) handDetectionDLL.handDetection.detectHandPose (IntPtr srcptr, Int32 w, Int32 h) OpenNIDepthmapViewer.FixedUpdate() (at Assets/OpenNI/Scripts/OpenNIDepthmapViewer.cs:152)

任何幫助表示讚賞。

感謝, 庫馬爾

+0

您是否嘗試過http://answers.unity3d.com?這可能需要幾個小時,但很可能你會在那裏得到更好的答案。 – 2012-02-13 07:19:54

回答

0

在Bitmap()構造的步幅參數錯誤 - 步幅應該是字節的圖像連續佔據必要的數量(因爲一些格式,如BMP要求像素的每一行從一個DWORD對齊的地址或其他類似的需求開始)