【问题标题】:UnityKinectDepthExplorer - how can I use this example with Kinect v1?UnityKinectDepthExplorer - 我如何将这个示例与 Kinect v1 一起使用?
【发布时间】:2017-01-18 12:42:21
【问题描述】:

我有兴趣在 Unity 中使用 Kinect for Windows 显示深度数据。不幸的是,我有 Kinect v1.8,我知道这很容易通过 Kinect V2 (Kinect Fusion) 完成。

我找到了这个例子:https://github.com/rickbarraza/UnityKinectDepthExplorer 我安装了所有必要的组件,现在得到 DLLNOTFOUNDEXCEPTION:

未能加载“资产/插件/x86_64/KinectUnityAddin.dll”

关于我目前阅读的所有帖子和论坛,这是因为我使用的是 SDK 1.8(而不是 SDK 2.0)。

有什么方法可以将这个示例与 Kinect v1.8 一起使用?我也尝试联系作者,但他没有回复。

非常感谢!

【问题讨论】:

    标签: unity3d kinect


    【解决方案1】:

    我在大学项目中遇到了同样的问题,也许对你来说还不晚。 这是我制作的 Kinect v1.8 Wrapper,仅用于读取 kinect 深度图像。我使用 Unity-Assetstore 中的带有 MS-SDK 的 Kinect 作为指导,您不必下载它。您所需要的只是本准则。 使用 Init() 方法启动,使用 GetDepthArray() 函数获取深度帧。 希望它对你有用!

    您必须安装 Kinect 1.8 sdk 或在 Windows/System32 文件夹中至少包含 1.8 sdk 中的 Kinect10.dll

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System.Runtime.InteropServices;
    using System;
    using System.Runtime.CompilerServices;
    
    public class OwnKinectWrapper : MonoBehaviour {
    
    DepthBuffer db;
    
    #region Nui Variables/Structs/Intefraces
    IntPtr streamReferenz;
    
    public struct NuiImageViewArea
    {
        public int eDigitalZoom;
        public int lCenterX;
        public int lCenterY;
    }
    
    public struct NuiSurfaceDesc
    {
        uint width;
        uint height;
    }
    
    public struct DepthBuffer
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 640 * 480, ArraySubType = UnmanagedType.U2)]
        public ushort[] pixels;
    }
    
    public struct NuiLockedRect
    {
        public int pitch;
        public int size;
        public IntPtr pBits;
    
    }
    public struct NuiImageFrame
    {
        public Int64 liTimeStamp;
        public uint dwFrameNumber;
        public int eImageType;
        public int eResolution;
        public IntPtr pFrameTexture;
        public uint dwFrameFlags_NotUsed;
        public NuiImageViewArea ViewArea_NotUsed;
    }
    
    
    
    [Guid("13ea17f5-ff2e-4670-9ee5-1297a6e880d1")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    [ComImport()]
    public interface INuiFrameTexture
    {
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        [PreserveSig]
        int BufferLen();
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        [PreserveSig]
        int Pitch();
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        [PreserveSig]
        int LockRect(uint Level, ref NuiLockedRect pLockedRect, IntPtr pRect, uint Flags);
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        [PreserveSig]
        int GetLevelDesc(uint Level, ref NuiSurfaceDesc pDesc);
        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
        [PreserveSig]
        int UnlockRect(uint Level);
    }
    #endregion
    // Use this for initialization
    public int Init() {
        int init = 0;
        try {
            init = NuiInitialize(0x00000020);
            Debug.Log("init : " + init);
    
            streamReferenz = IntPtr.Zero;
            NuiImageStreamOpen(4, 2, 0, 2, IntPtr.Zero, ref streamReferenz);
    
    
    
        }
        catch (DllNotFoundException e)
        {
            string message = "Please check the Kinect SDK installation.";
            Debug.LogError(message);
            Debug.LogError(e.ToString());
    
            return -1;
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
    
            return -1;
        }
    
        return init;
    }
    
    // Update is called once per frame
    void Update()
    {
        IntPtr imageStreamFrameReferenz = IntPtr.Zero;
        int test = NuiImageStreamGetNextFrame(streamReferenz, 0, ref imageStreamFrameReferenz);
        if (test == 0) {
            NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageStreamFrameReferenz, typeof(NuiImageFrame));
            INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture);
    
            NuiLockedRect lockedRectPtr = new NuiLockedRect();
            IntPtr r = IntPtr.Zero;
            frameTexture.LockRect(0, ref lockedRectPtr, r, 0);
            db = (DepthBuffer)Marshal.PtrToStructure(lockedRectPtr.pBits, typeof(DepthBuffer));
            frameTexture.UnlockRect(0);
            NuiImageStreamReleaseFrame(streamReferenz, imageStreamFrameReferenz);
        }
    }
    
    void OnDisable() {
        NuiShutdown();
    }
    
    public ushort[] GetDepthArray(){
        return db.pixels;
    }
    
    
    [DllImportAttribute(@"Kinect10.dll",EntryPoint="NuiInitialize")]
    public static extern int NuiInitialize (uint dwFlags);
    
    
    [DllImportAttribute(@"Kinect10.dll", EntryPoint = "NuiImageStreamOpen")]
    public static extern int NuiImageStreamOpen(int enumImageType,int enumImgageResolution, uint image_Flags, uint frameBufferLimit, IntPtr nextFrameEvent, ref IntPtr streamHandle );
    
    
    [DllImportAttribute(@"Kinect10.dll", EntryPoint = "NuiImageStreamGetNextFrame")]
    public static extern int NuiImageStreamGetNextFrame(IntPtr streamReferenz, uint dwMillisecondsToWait, ref IntPtr ImageFrameReferenz);
    
    
    [DllImportAttribute(@"Kinect10.dll", EntryPoint = "NuiImageStreamReleaseFrame")]
    public static extern int NuiImageStreamReleaseFrame(IntPtr phStreamHandle, IntPtr ppcImageFrame);
    
    
    [DllImportAttribute(@"Kinect10.dll",EntryPoint="NuiDepthPixelToDepth")]
    public static extern ushort NuiDepthPixelToDepth (ushort depthPixel);
    
    
    [DllImportAttribute(@"Kinect10.dll", EntryPoint = "NuiShutdown")]
    public static extern void NuiShutdown();
    
    
    }
    

    如果出现问题或需要帮助,请随时写几行

    【讨论】:

      猜你喜欢
      • 2013-11-22
      • 2012-01-12
      • 2015-05-10
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 2015-05-06
      相关资源
      最近更新 更多