顯示具有 Kinect SDK 標籤的文章。 顯示所有文章
顯示具有 Kinect SDK 標籤的文章。 顯示所有文章

2012年12月30日 星期日

Kinect SDK - (1) Kinect Sensor安裝及使用

  1. 下載及安裝the Kinect for Windows SDK
  2. Kinect Sensor硬體簡介
    • Kinect Sensor包含以下功能:
      • RGB Camera - 支援解析度640x480 at 30 FPS的鏡頭
      • 3D Depth Sensors - 透過左右兩圈紅外線偵測器,取得目標前後移動的距離
      • Motorized Tilt -  傾斜度調整,可上下調整27度,以最佳方式偵測目標整體
      • Multi-Array Microphone - 包含四個角度的麥克風陣列,藉以判斷聲音的來源方向及遠近
  3. Device manager- 裝置管理員
    • 安裝完Kinect for Windows SDK及從USB端接上Kinect 硬體後,裝置管理員會出現以下三個裝置:
      • Audio Microphone
        • 可透過控制台→音效 管理,錄音的分頁裡,看到四個麥克風陣列
        • 可以透過 "錄音機" 程式測試麥克風的收音狀況
      • 增加語音辨識功能
      • 由於Kinect為陣列麥克風,因此將其它麥克風裝置設置成 "Other"
      • 當語音辨識功能啟動時,畫面會出現以下小工具:

完整說明:http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware

    2012年12月29日 星期六

    Kinect SDK - (2) 設定開發環境-Setting Up Your Development Environment

    1. Download Sample Requirements
    2. Setting up a new Visual Studio 2010 Project
      • 於VS2010 新增 以Windows Presentation Foundation為版本的new project
      • Add references
        • For C#
        • For Visual Basic
      • 在Add Reference對話框,切換至.NET分頁,選取Microsoft.Research.Kinect (版本:1.0.0.45)
      • 新增 using statement
        • C#
          • using Microsoft.Research.Kinect.Nui;
            using Microsoft.Research.Kinect.Audio;
        • Visual Basic
          • Imports Microsoft.Research.Kinect.Nui
            Imports Microsoft.Research.Kinect.Audio
      • Optional: Using the Coding4Fun Kinect Toolkit
        • 下載Coding4Fun - http://c4fkinect.codeplex.com
        • 載入DLL檔: (WPF 或 Windows Form application應載入不同檔案)
          • WPF Applications: use the Coding4Fun.Kinect.Wpf.dll
            • // if you're using WPF
              using Coding4Fun.Kinect.Wpf;
              // if you're using WinForms
              using Coding4Fun.Kinect.WinForm;
          • Windows Form Applications: use the Coding4Fun.Kinect.WinForm.dll
            • ' if you're using WPF
              Imports Coding4Fun.Kinect.Wpf
              ' if you're using WinForms
              Imports Coding4Fun.Kinect.WinForm
    3. 初始化及解除 - Initializing and Uninitializing the runtime
      • For NUI (Nature User Interface),需要初始化物件,以下的範例利用"Window_Loaded event"來初始化及"Windows_Closed event"解除:
        • Create the Window_Loaded event
          • 到屬性視窗(properties window - F4),選擇"MainWindow"→"Events tab"→雙擊"Loaded"物件來新增"Window_Loaded event"。
          • Initializing the runtime
            • Create a new Runtime variable named “nui” outside of the Window_Loaded event. When the Window_Loaded event fires, we will call the SetupKinect method that checks to see if there is at least one Kinect plugged in, and if there is, it uses the first Kinect (0 representing the first Kinect) and initializes the Runtime (more details on that later). 
            • C#
              //Kinect Runtime
              Runtime nui;private void Window_Loaded(object sender, RoutedEventArgs e)
              {
              SetupKinect();
              }private void SetupKinect()
              {
              if (Runtime.Kinects.Count == 0)
              {
              this.Title = "No Kinect connected";
              }
              else
              {
              //use first Kinect
              nui = Runtime.Kinects[0];
              nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking);
              }
              }
            • Visual Basic
              'Kinect Runtime
              Private nui As Runtime
              Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
              SetupKinect() AddHandler Runtime.Kinects.StatusChanged, AddressOf Kinects_StatusChanged
              End Sub Private Sub SetupKinect()
              If Runtime.Kinects.Count = 0 Then
              Me.Title = "No Kinect connected"
              Else
              'use first Kinect
              nui = Runtime.Kinects(0)
              nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking)
              End If
              End Sub
          • Handling multiple Kinects
            • You can see how many Kinects are connected by getting the count of Kinects as shown in the code below. Note that for multiple Kinects, you can only have one Kinect do skeletal tracking at a time (color and depth camera work for all) and each Kinect needs to be in its own USB hub, otherwise it won’t have enough USB bandwidth.
            • C#
              [code lang=”csharp”]
              int KinectCount = Runtime.Kinects.Count;
              [/code]
            • Visual Basic
            • [code lang=”vb”]
              Dim KinectCount as Integer = Runtime.Kinects.Count
              [/code]
          • Handling Kinect Status Change events
            • You can also handle events when the status changes for Kinects that are plugged in. To do this, first register for the StatusChanged event as shown below. When this event fires, it returns a KinectStatus enum with the following possible values: Connected, Error, Disconnected, NotReady, or NotPowered.
            • C#
              [code lang=”csharp”]
              Runtime.Kinects.StatusChanged += new EventHandler<StatusChangedEventArgs>(Kinects_StatusChanged);
              void Kinects_StatusChanged(object sender, StatusChangedEventArgs e)
              {
              string message = "Status Changed: ";
              switch (e.Status)
              {
              case KinectStatus.Connected:
              message += "Connected";
              break;
              case KinectStatus.Disconnected:
              message += "Disconnected";
              break;
              case KinectStatus.Error:
              message += "Error";
              break;
              case KinectStatus.NotPowered:
              message += "Not Powered";
              break;
              case KinectStatus.NotReady:
              message += "Not Ready";
              break;
              default:
              if (e.Status.HasFlag(KinectStatus.Error))
              {
              message += "Kinect error";
              }
              break;
              }
              this.Title = message;
              }
              [/code]
            • Visual Basic
              [code lang=”vb”]
              AddHandler Runtime.Kinects.StatusChanged, AddressOf Kinects_StatusChanged

              Private Sub Kinects_StatusChanged(sender As Object, e As StatusChangedEventArgs)
              Dim message As String = "Status Changed: "
              Select Case e.Status
              Case KinectStatus.Connected
              message += "Connected"
              Exit Select
              Case KinectStatus.Disconnected
              message += "Disconnected"
              Exit Select
              Case KinectStatus.[Error]
              message += "Error"
              Exit Select
              Case KinectStatus.NotPowered
              message += "Not Powered"
              Exit Select
              Case KinectStatus.NotReady
              message += "Not Ready"
              Exit Select
              Case Else
              If e.Status.HasFlag(KinectStatus.[Error]) Then
              message += "Kinect error"
              End If
              Exit Select
              End Select
              Me.Title = message

              End Sub

              [/code]
          • Setting Runtime Options
            In the Window_Loaded event, initialize the runtime with the options you want to use. For this example, set RuntimeOptions.UseColor to use the RGB camera:
            C#
            nui.Initialize(RuntimeOptions.UseColor);
            Visual Basic
            nui.Initialize(RuntimeOptions.UseColor)
            RuntimeOptions is a Flag enumeration, this means you can set multiple options as parameters in the Initialize method by separating them with the pipe "|" character (the "or" operator) in c# or the "Or" operator in Visual Basic. The example below sets the runtime to use the color camera, a depth camera, and skeletal tracking:
            C#
            nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking
            Visual Basic
            nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking
        • Uninitializing the Runtime
          • Remember that when you are done using the Kinect Runtime, you should call the Uninitialize method. For a WPF application, you would typically do this in the Windows_Closed event:
            C#
            nui.Uninitialize();
            Visual Basic
            nui.Uninitialize()
      Reference to: http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started