none
Kinect IR sensor turns off after a few seconds RRS feed

  • Question

  •  

    I am running a basic WPF program to experiment with Kinect. It consists of 3 basic circles that should move according to your head and two hands. It works for a few seconds then it stops. The circles freeze and I notice the IR sensor turns off. I set up a counter on the event handler for skeleton ready and it always runs 169,170 times before it goes out. Here is my code.

    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;
    using Microsoft.Research.Kinect.Audio;
    using Coding4Fun.Kinect.Wpf;
    
    namespace KinectTest1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            
            
            public MainWindow()
            {
                InitializeComponent();
                
            }
    
            //Runtime for the NIU APIs
            Runtime nui = new Runtime();
    
            private void SetupKinect()
            {
                if (Runtime.Kinects.Count == 0)
                    this.Title = "No Kinect Detected.";
                else
                {
                    nui = Runtime.Kinects[0];
                    nui.Initialize(RuntimeOptions.UseSkeletalTracking);
                }
                
     
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                SetupKinect();
                Runtime.Kinects.StatusChanged += new EventHandler<StatusChangedEventArgs>(Kinects_StatusChanged);
                nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);
            }
    
            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;
            }
    
            private void SetEllipsePosition(FrameworkElement ellipse, Joint joint)
            {
                var scaledJoint = joint.ScaleTo(640, 480, .5f, .5f);
    
                Canvas.SetLeft(ellipse, scaledJoint.Position.X);
                Canvas.SetTop(ellipse, scaledJoint.Position.Y);
            }
    
            int count = 0;
            void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
            {
                
                count++;
                this.Title = count.ToString();
                SkeletonFrame allSkeletons = e.SkeletonFrame;
    
                //get the first tracked skeleton
                SkeletonData skeleton = (from s in allSkeletons.Skeletons
                                         where s.TrackingState == SkeletonTrackingState.Tracked
                                         select s).FirstOrDefault();
    
                SetEllipsePosition(headEllipse, skeleton.Joints[JointID.Head]);
                SetEllipsePosition(leftEllipse, skeleton.Joints[JointID.HandLeft]);
                SetEllipsePosition(rightEllipse, skeleton.Joints[JointID.HandRight]);
    
            }
    
            private void Window_Closed(object sender, EventArgs e)
            {
                nui.Uninitialize();
            }
        }
    }
    
    

     

        XAML:

    <Window x:Class="KinectTest1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" Closed="Window_Closed" WindowState="Maximized">
        <Grid>
            <Canvas Name="MainCanvas">
                <Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse" Stroke="Black" Width="50" Fill="Orange" />
                <Ellipse Canvas.Left="50" Canvas.Top="0" Height="50" Name="rightEllipse" Stroke="Black" Width="50" Fill="SlateGray" />
                <Ellipse Canvas.Left="100" Canvas.Top="0" Fill="SpringGreen" Height="50" Name="leftEllipse" Stroke="Black" Width="50" />
            </Canvas>
        </Grid>
    </Window>
    


    Saturday, December 24, 2011 4:46 AM