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プロジェクトを新規作成します.バックグラウンドコードは次のとおりです.
左手や右手を握り、解放すると、フォームのタイトルバーのヒントだけでなく、音声のヒントも聞こえます.
また、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
握る場合は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プロジェクトを新規作成します.バックグラウンドコードは次のとおりです.
- using Microsoft.Kinect;
- using Microsoft.Kinect.Toolkit.Interaction;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
-
- namespace Grip
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- KinectSensor ks = null;
- InteractionClient ic;
- InteractionStream its;
- private void Form1_Load(object sender, EventArgs e)
- {
- foreach (var kss in KinectSensor.KinectSensors)
- {
- if (kss.Status == KinectStatus.Connected)
- {
- ks = kss;
- }
- }
- if (ks != null)
- {
- //
- ks.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
- //
- ks.SkeletonStream.Enable();
- //
- ks.DepthFrameReady += kinectSensor_DepthFrameReady;
- //
- ks.SkeletonFrameReady += kinectSensor_SkeletonFrameReady;
- //
- ic = new InteractionClient();
- //
- its = new InteractionStream(ks, ic);
- //
- its.InteractionFrameReady += its_InteractionFrameReady;
- // Kinect,
- ks.Start();
- }
- }
-
- private UserInfo[] UserInfos = null;//
- void its_InteractionFrameReady(object sender, InteractionFrameReadyEventArgs e)
- {
- using (InteractionFrame frame = e.OpenInteractionFrame())
- {
- if (frame != null)
- {
- if (this.UserInfos == null)
- {
- //
- this.UserInfos = new UserInfo[InteractionFrame.UserInfoArrayLength];
- }
- // UserInfo
- frame.CopyInteractionDataTo(this.UserInfos);
- }
- else
- {
- return;
- }
- }
- //
- foreach (UserInfo userInfo in this.UserInfos)
- {
- //
- foreach (InteractionHandPointer handPointer in userInfo.HandPointers)
- {
- string action = null;
- //
- switch (handPointer.HandEventType)
- {
- case InteractionHandEventType.Grip:
- action = " ";
- break;
- case InteractionHandEventType.GripRelease:
- action = " ";
- break;
- }
- if (action != null)
- {
- string handSide = "unknown";
- //
- switch (handPointer.HandType)
- {
- case InteractionHandType.Left:
- handSide = " ";
- break;
- case InteractionHandType.Right:
- handSide = " ";
- break;
- }
- //
- if (this.Text != " " + action + " " + handSide + " .")
- {
- this.Text = (" " + action + " " + handSide + " .");
- string content = "CreateObject(\"SAPI.SpVoice\").Speak\"" + Text + "\"";
- try
- {
- File.WriteAllText(@"F:/test/a.vbs", content, Encoding.Default);
- Process.Start(@"F:/test/a.vbs");
- }
- catch
- { }
- }
- }
-
- }
- }
-
- }
-
- private void kinectSensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
- {
- using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
- {
- if (depthImageFrame != null)
- {
- //
- its.ProcessDepth(depthImageFrame.GetRawPixelData(), depthImageFrame.Timestamp);
- }
- }
- }
-
- private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
- {
- using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
- {
- if (skeletonFrame != null)
- {
- Skeleton[] skeletonData = new Skeleton[ks.SkeletonStream.FrameSkeletonArrayLength];
- skeletonFrame.CopySkeletonDataTo(skeletonData);
- //
- its.ProcessSkeleton(skeletonData, ks.AccelerometerGetCurrentReading(), skeletonFrame.Timestamp);
- }
- }
- }
- // Kiect
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (ks != null)
- {
- ks.Stop();
- }
- }
- }
-
-
- //
- public class InteractionClient : IInteractionClient
- {
- //
- public InteractionInfo GetInteractionInfoAtLocation(int skeletonTrackingId, InteractionHandType handType, double x, double y)
- {
- return new InteractionInfo
- {
- IsPressTarget = true,
- IsGripTarget = true,
- };
- }
- }
- }
左手や右手を握り、解放すると、フォームのタイトルバーのヒントだけでなく、音声のヒントも聞こえます.
また、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