需要帮助更新旧的Kinect SDK代码。

时间:2014-03-13 02:30:30

标签: c# windows sdk kinect

我们一直无法找到Kinect SDK 1.8的最新教程。我们在网上找到的所有教程都是针对较旧版本的SDK。如果有人可以提供帮助,请有人告诉我们这段代码编写的Kinect SDK的版本以及如何将代码更新为最新的SDK代码(版本1.8)。

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.Research.Kinect.Nui; namespace KinectSkeletonApplication3 { public partial class MainWindow : Window { //Instantiate the Kinect runtime. Required to initialize the device. //IMPORTANT NOTE: You can pass the device ID here, in case more than one Kinect device is connected. Runtime runtime = Runtime.Kinects[0]; public MainWindow() { InitializeComponent(); //Runtime initialization is handled when the window is opened. When the window //is closed, the runtime MUST be unitialized. this.Loaded += new RoutedEventHandler(MainWindow_Loaded); this.Unloaded += new RoutedEventHandler(MainWindow_Unloaded); runtime.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(runtime_SkeletonFrameReady); } void runtime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { SkeletonFrame skeletonSet = e.SkeletonFrame; SkeletonData data = (from s in skeletonSet.Skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); if (data != null) { SetEllipsePosition(Head, data.Joints[JointID.Head]); SetEllipsePosition(leftHand, data.Joints[JointID.HandLeft]); SetEllipsePosition(rightHand, data.Joints[JointID.HandRight]); ProcessGesture(data.Joints[JointID.Head], data.Joints[JointID.HandLeft], data.Joints[JointID.HandRight]); } } private void ProcessGesture(Joint head, Joint handLeft, Joint handRight) { if ((handRight.position.Y > head.position.Y) || (handLeft.position.Y > head.position.Y)) { MessageBox.Show("Your hand is above your head, bitch."); } else if ((handRight.position.Y < 0) || (handLeft.position.Y < 0)) { MessageBox.Show("Your hand is below your waist, bitch."); } else if (handRight.position.X < handLeft.position.X) { MessageBox.Show("Your hands are crossed, bitch."); } } private void SetEllipsePosition(Ellipse ellipse, Joint joint) { Microsoft.Research.Kinect.Nui.Vector vector = new Microsoft.Research.Kinect.Nui.Vector(); vector.X = ScaleVector(640, joint.Position.X); vector.Y = ScaleVector(480, -joint.Position.Y); vector.Z = joint.Position.Z; Joint updatedJoint = new Joint(); updatedJoint.ID = joint.ID; updatedJoint.TrackingState = JointTrackingState.Tracked; updatedJoint.Position = vector; Canvas.SetLeft(ellipse, updatedJoint.Position.X); Canvas.SetTop(ellipse, updatedJoint.Position.Y); } private float ScaleVector(int length, float position) { float value = (((((float)length) / 1f) / 2f) * position) + (length / 2); if (value > length) { return (float)length; } if (value < 0f) { return 0f; } return value; } void MainWindow_Unloaded(object sender, RoutedEventArgs e) { runtime.Uninitialize(); } void MainWindow_Loaded(object sender, RoutedEventArgs e) { //Since only a color video stream is needed, RuntimeOptions.UseColor is used. runtime.Initialize(Microsoft.Research.Kinect.Nui.RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking); } } }

1 个答案:

答案 0 :(得分:0)

我会看到blog postthis one。它们都描述了从beta到v1.0的主要变化。 v1.0与1.8具有相同的结构,有关转换代码的示例,请参阅Converting Kinect Methods from Beta 2, to Version 1。虽然转换为v1.8可能看起来令人生畏并且不值得工作,但要坚持下去,它会更加高效和有效。