Kinect for windowsでのグリップ(Grip)とリリース(GripRelease)


Kinect for windows SDK 1.7版では、左右の手のつかみと置きが認識され、手の形の認識には深さストリームとボーンストリームのデータが必要なので、使用時にはこの2つのストリームの受信をオンにすることが望ましいグリップの新機能が追加されています.
握る場合はKinectのToolKitを参照し、インストールディレクトリの下、例えばC:Program FilesMicrosoft SDKsKinectDeveloper Toolkit v 1.7.0\Assemblies\Microsoft.Kinect.Toolkit.Interaction.dll.もちろんMicrosoftも引用しなければなりません.Kinect.グリップの識別は、MicrosoftにおけるInteractionストリームによって実現される.Kinect.ToolKit.Interactionのネーミングスペースの下.
次の例はwinformで実現されるグリップ実践である.
まず、Winformプロジェクトを新規作成します.バックグラウンドコードは次のとおりです.
 
   
   
   
   
  1. using Microsoft.Kinect;  
  2. using Microsoft.Kinect.Toolkit.Interaction;  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.ComponentModel;  
  6. using System.Diagnostics;  
  7. using System.IO;  
  8. using System.Text;  
  9. using System.Windows.Forms;  
  10.  
  11. namespace Grip  
  12. {  
  13.     public partial class Form1 : Form  
  14.     {  
  15.         public Form1()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.         KinectSensor ks = null;  
  20.         InteractionClient ic;  
  21.         InteractionStream its;  
  22.         private void Form1_Load(object sender, EventArgs e)  
  23.         {  
  24.             foreach (var kss in KinectSensor.KinectSensors)  
  25.             {  
  26.                 if (kss.Status == KinectStatus.Connected)  
  27.                 {  
  28.                     ks = kss;  
  29.                 }  
  30.             }  
  31.             if (ks != null)  
  32.             {  
  33.                 //  
  34.                 ks.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);  
  35.                 //  
  36.                 ks.SkeletonStream.Enable();  
  37.                 //  
  38.                 ks.DepthFrameReady += kinectSensor_DepthFrameReady;  
  39.                 //  
  40.                 ks.SkeletonFrameReady += kinectSensor_SkeletonFrameReady;  
  41.                 //  
  42.                 ic = new InteractionClient();  
  43.                 //  
  44.                 its = new InteractionStream(ks, ic);  
  45.                 //  
  46.                 its.InteractionFrameReady += its_InteractionFrameReady;  
  47.                 // Kinect,  
  48.                 ks.Start();  
  49.             }  
  50.         }  
  51.  
  52.         private UserInfo[] UserInfos = null;//  
  53.         void its_InteractionFrameReady(object sender, InteractionFrameReadyEventArgs e)  
  54.         {  
  55.             using (InteractionFrame frame = e.OpenInteractionFrame())  
  56.             {  
  57.                 if (frame != null)  
  58.                 {  
  59.                     if (this.UserInfos == null)  
  60.                     {                        
  61.                         //  
  62.                         this.UserInfos = new UserInfo[InteractionFrame.UserInfoArrayLength];  
  63.                     }  
  64.                     // UserInfo  
  65.                     frame.CopyInteractionDataTo(this.UserInfos);  
  66.                 }  
  67.                 else 
  68.                 {  
  69.                     return;  
  70.                 }  
  71.             }  
  72.             //  
  73.             foreach (UserInfo userInfo in this.UserInfos)  
  74.             {  
  75.                 //  
  76.                 foreach (InteractionHandPointer handPointer in userInfo.HandPointers)  
  77.                 {  
  78.                     string action = null;  
  79.                     //  
  80.                     switch (handPointer.HandEventType)  
  81.                     {  
  82.                         case InteractionHandEventType.Grip:  
  83.                             action = " ";  
  84.                             break;  
  85.                         case InteractionHandEventType.GripRelease:  
  86.                             action = " ";  
  87.                             break;  
  88.                     }  
  89.                     if (action != null)  
  90.                     {  
  91.                         string handSide = "unknown";  
  92.                         //  
  93.                         switch (handPointer.HandType)  
  94.                         {  
  95.                             case InteractionHandType.Left:  
  96.                                 handSide = " ";  
  97.                                 break;  
  98.                             case InteractionHandType.Right:  
  99.                                 handSide = " ";  
  100.                                 break;  
  101.                         }  
  102.                         //  
  103.                         if (this.Text != " " + action + " " + handSide + " .")  
  104.                         {  
  105.                             this.Text = (" " + action + " " + handSide + " .");  
  106.                             string content = "CreateObject(\"SAPI.SpVoice\").Speak\"" + Text + "\"";  
  107.                             try 
  108.                             {  
  109.                                 File.WriteAllText(@"F:/test/a.vbs", content, Encoding.Default);  
  110.                                 Process.Start(@"F:/test/a.vbs");  
  111.                             }  
  112.                             catch 
  113.                             { }  
  114.                         }  
  115.                     }  
  116.  
  117.                 }  
  118.             }  
  119.  
  120.         }  
  121.  
  122.         private void kinectSensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)  
  123.         {  
  124.             using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())  
  125.             {  
  126.                 if (depthImageFrame != null)  
  127.                 {  
  128.                     //  
  129.                     its.ProcessDepth(depthImageFrame.GetRawPixelData(), depthImageFrame.Timestamp);  
  130.                 }  
  131.             }  
  132.         }  
  133.  
  134.         private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)  
  135.         {  
  136.             using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())  
  137.             {  
  138.                 if (skeletonFrame != null)  
  139.                 {  
  140.                     Skeleton[] skeletonData = new Skeleton[ks.SkeletonStream.FrameSkeletonArrayLength];  
  141.                     skeletonFrame.CopySkeletonDataTo(skeletonData);  
  142.                     //  
  143.                     its.ProcessSkeleton(skeletonData, ks.AccelerometerGetCurrentReading(), skeletonFrame.Timestamp);  
  144.                 }  
  145.             }  
  146.         }  
  147.         // Kiect  
  148.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)  
  149.         {  
  150.             if (ks != null)  
  151.             {  
  152.                 ks.Stop();  
  153.             }  
  154.         }  
  155.     }  
  156.  
  157.  
  158.     //  
  159.     public class InteractionClient : IInteractionClient  
  160.     {  
  161.         //  
  162.         public InteractionInfo GetInteractionInfoAtLocation(int skeletonTrackingId, InteractionHandType handType, double x, double y)  
  163.         {          
  164.             return new InteractionInfo  
  165.             {  
  166.                 IsPressTarget = true,  
  167.                 IsGripTarget = true,  
  168.             };  
  169.         }  
  170.     }  
  171. }  

左手や右手を握り、解放すると、フォームのタイトルバーのヒントだけでなく、音声のヒントも聞こえます.
また、KinectInteraction 170_32.dll、およびKinectInteraction 170_64.dllこの2つのファイルはexeの同じディレクトリの下に置かれ、32は32ビットシステムで使用され、64は64ビットシステムで使用されます.
KinectInteraction170_32.dllダウンロードアドレス:
http://down.51cto.com/data/771643
KinectInteraction 170_64.dllダウンロードアドレス:
http://down.51cto.com/data/771644