none
kinect sensor interrupt while playing video RRS feed

  • Question

  • Hello!
     when i put hand infront of kinect sensor my video  which is loaded in wpf window is start and if removed hand video stopped working. video is just like a still image when hands are removed infront of kinect sensor. Don't know whats wrong 
                <MediaElement Margin="0,450,0,0" Height="499" Width="550" VerticalAlignment="Center" HorizontalAlignment="Center"
                Name="Video" LoadedBehavior="Manual" Canvas.Top="-179">
                </MediaElement>

    Video.Source= new Uri(@"C:\Users\Danyal Haider\Documents\Visual Studio 2010\Projects\Stroke Recovery\Stroke Recovery\Video\exerightarm.avi", UriKind.Absolute);
                      Video.Play();
                      

    Tuesday, November 11, 2014 6:04 PM

Answers

  • Got it . and solved.  

                      

        if (checkvideo == false)
                    {
                      Video.Source= new Uri(@"C:\Users\Danyal Haider\Documents\Visual Studio 2010\Projects\Stroke Recovery\Stroke Recovery\Video\exerightarm.avi", UriKind.Absolute);

                          Video.Play();
                          checkvideo = true;
                      }

    *checkvideo is static bool variable

    • Marked as answer by DanyalHaider Thursday, November 13, 2014 8:16 PM
    Thursday, November 13, 2014 7:54 PM

All replies

  • Kinect has no control of the system, so how you are playing and stopping video using Kinect is application dependent. You have only shown how you are playing the video, where is Kinect being used?

    Carmine Sirignano - MSFT

    Tuesday, November 11, 2014 8:33 PM
  • This is what i am doing
      KinectSensor sensor = KinectSensor.KinectSensors[0];
            Skeleton[] skeletons;
            string CopyBtnName;
            public Exercise(string BtnName)
            {
                CopyBtnName = BtnName;
                InitializeComponent();
    
          
                var parameters = new TransformSmoothParameters
                {
                    Smoothing = 0.3f,
                    Correction = 0.0f,
                    Prediction = 0.0f,
                    JitterRadius = 1.0f,
                    MaxDeviationRadius = 0.04f
                };
                sensor.SkeletonStream.Enable(parameters);
                sensor.SkeletonFrameReady += TrackSkeleton;
                sensor.Start();
            }
            void MainWindow_Unloaded(object sender, RoutedEventArgs e)
            {
                sensor.Stop();
            }
           public void SetPosition(Ellipse ellipse, Joint LHJoint, Joint RHJoint, Joint LEJoint, Joint REJoint, Joint Head, Joint BodyOrign)
            {
                
                var scaledJointLH = LHJoint.ScaleTo(1920, 1080, .5f, .5f);
                var scaledJointRH = RHJoint.ScaleTo(1920, 1080, .5f, .5f);
                var scaledJointLE = LEJoint.ScaleTo(1920, 1080, .5f, .5f);
                var scaledJointRE = REJoint.ScaleTo(1920, 1080, .5f, .5f);
                var scaledJointHead = Head.ScaleTo(1920, 1080, .5f, .5f);
                var scaledJointOrign = BodyOrign.ScaleTo(1920, 1080, .5f, .5f);
                switch (CopyBtnName)
                {
                    case "Right Arm Exercise":
             
                    TemplateImage.BeginInit();
                    TemplateImage.Source= new BitmapImage(new Uri(@"C:\Users\Danyal Haider\Documents\Visual Studio 2010\Projects\Stroke Recovery\Stroke Recovery\Images\RightArmExercise.JPG"));
                    //TemplateImage.CacheOption = BitmapCacheOption.OnLoad;
                    TemplateImage.EndInit();
                      Video.Source= new Uri(@"C:\Users\Danyal Haider\Documents\Visual Studio 2010\Projects\Stroke Recovery\Stroke Recovery\Video\exerightarm.avi", UriKind.Absolute);
                      Video.Play();
                      
                        var disX = scaledJointRH.Position.X- scaledJointOrign.Position.X;
                        var disY = scaledJointRH.Position.Y - scaledJointOrign.Position.Y;
                        if ((disX > 375 && disX < 837) && (disY > -890 && disY < -645))
                        {
                            Slider.Background = System.Windows.Media.Brushes.Blue;
    
                        }
                        else
                        {
                            Slider.Background = System.Windows.Media.Brushes.FloralWhite;
                        }
                        break;
                    case "Arm Exercise":
                    TemplateImage.BeginInit();
                    TemplateImage.Source= new BitmapImage(new Uri(@"C:\Users\Danyal Haider\Documents\Visual Studio 2010\Projects\Stroke Recovery\Stroke Recovery\Images\BothArm.JPG"));
                    //TemplateImage.CacheOption = BitmapCacheOption.OnLoad;
                    TemplateImage.EndInit();
                      Video.Source= new Uri(@"C:\Users\Danyal Haider\Documents\Visual Studio 2010\Projects\Stroke Recovery\Stroke Recovery\Video\TWOARMS.avi", UriKind.Absolute);
                      Video.Play();
                      
                        var RdisX = scaledJointRH.Position.X- scaledJointOrign.Position.X;
                        var RdisY = scaledJointRH.Position.Y - scaledJointOrign.Position.Y;
                        var LdisX = scaledJointLH.Position.X- scaledJointOrign.Position.X;
                        var LdisY = scaledJointLH.Position.Y - scaledJointOrign.Position.Y;
                        if ((RdisX > 200 && RdisX < 420) && (RdisY > -450 && RdisY < -300) && (LdisY > -230 && LdisY < 220) && (LdisY > -450 && LdisY < -290))
                        {
                            
                            
                            Slider.Background = System.Windows.Media.Brushes.Blue;
                        }
                        else
                        {
                            Slider.Background = System.Windows.Media.Brushes.FloralWhite;
                        }
                        break;
                    case "Left Arm Exercise":
                          var distX = scaledJointLH.Position.X- scaledJointOrign.Position.X;
                        var distY = scaledJointLH.Position.Y - scaledJointOrign.Position.Y;
                        break;
                    case "Left Elbo Exercise":
    
                        break;
                    case "Right Elbo Exercise":
    
                        break;
                }
                Canvas.SetLeft(ellipse, scaledJointLH.Position.X);
                Canvas.SetTop(ellipse, scaledJointLH.Position.Y);
            }
            void TrackSkeleton(object sender, SkeletonFrameReadyEventArgs e)
            {
                bool receivedData = false;
    
                using (SkeletonFrame SFrame = e.OpenSkeletonFrame())
                {
                    if (SFrame == null)
                    {
    
                    }
                    else
                    {
    
                        skeletons = new Skeleton[SFrame.SkeletonArrayLength];
                        SFrame.CopySkeletonDataTo(skeletons);
                        receivedData = true;
                    }
                }
    
                if (receivedData)
                {
                    // sub query expression .
                    Skeleton currentSkeleton = (from skl in skeletons
                                                where skl.TrackingState == SkeletonTrackingState.Tracked
                                                select skl).FirstOrDefault();
    
                    if (currentSkeleton != null)
                    {
    
                        SetPosition(leftHand, currentSkeleton.Joints[JointType.HandLeft], currentSkeleton.Joints[JointType.HandRight], currentSkeleton.Joints[JointType.ElbowLeft], currentSkeleton.Joints[JointType.ElbowRight], currentSkeleton.Joints[JointType.Head], currentSkeleton.Joints[JointType.HipCenter]);
                        //SetPosition(rightHand, currentSkeleton.Joints[JointType.HandRight]);
    
    
    
                    }
                }
            }
    
    
        }
    }
    

        <DockPanel LastChildFill="True">
    
            <StackPanel DockPanel.Dock="Left" Background="Transparent" Width="300" Height="500" Name="Template" Panel.ZIndex="2">
                <StackPanel >
                   
                </StackPanel>
            </StackPanel>
    
    
    
            <StackPanel DockPanel.Dock="Right" Width="365" VerticalAlignment="Center" HorizontalAlignment="Center" Height="500" Name="Slider" Panel.ZIndex="2" Background ="Transparent" >
                
                <Image Name="TemplateImage" Height="500" Width="365"></Image>
                
            </StackPanel>
            <Canvas Name="can" Panel.ZIndex="3">
           
            <Ellipse Name="leftHand" Margin="10,10,10,10" Height="20" Width="46" Canvas.Top="39" Panel.ZIndex="3">
                    <Ellipse.Fill>
                        <ImageBrush ImageSource="C:\Users\Danyal Haider\documents\visual studio 2010\Projects\Stroke Recovery\Stroke Recovery\Images\myhand.png"/>
                    </Ellipse.Fill>
                </Ellipse>
                <Ellipse Name="rightHand" Margin="10,10,10,10" Height="32" Width="41" Canvas.Top="39" Panel.ZIndex="3">
                    <Ellipse.Fill>
                        <ImageBrush ImageSource="C:\Users\Danyal Haider\documents\visual studio 2010\Projects\Stroke Recovery\Stroke Recovery\Images\myhand.png"></ImageBrush>
                    </Ellipse.Fill>
                </Ellipse>
                <MediaElement Margin="0,450,0,0" Height="499" Width="550" VerticalAlignment="Center" HorizontalAlignment="Center"
                Name="Video" LoadedBehavior="Manual" Canvas.Top="-179">
                </MediaElement>
            </Canvas>
        </DockPanel>
    

    Wednesday, November 12, 2014 3:57 PM
  • Why are you continuously trying to set the source property on the SetPosition function. Based on your code, this is being call for each joint that it is drawing. Is that the logic you want?

    Kinect api's will only provide you the data from the sensor. It is up to you one the logic you need based on the joint positions and take action on that. You will need to evaluate whether this is the right logic or algorithm you want and adjust to match the scenario.


    Carmine Sirignano - MSFT


    Wednesday, November 12, 2014 10:38 PM
  • Got it . and solved.  

                      

        if (checkvideo == false)
                    {
                      Video.Source= new Uri(@"C:\Users\Danyal Haider\Documents\Visual Studio 2010\Projects\Stroke Recovery\Stroke Recovery\Video\exerightarm.avi", UriKind.Absolute);

                          Video.Play();
                          checkvideo = true;
                      }

    *checkvideo is static bool variable

    • Marked as answer by DanyalHaider Thursday, November 13, 2014 8:16 PM
    Thursday, November 13, 2014 7:54 PM