Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Comments

myChan myChan
  • RC Helicopter, Arduino and of course, the Kinect

    Wow! It`s awesome!

  • Skeletal Tracking Fundamentals

    @kendrick0772: Maybe You can get a inspration in here. Check this out.

    http://social.msdn.microsoft.com/forums/en-US/wpf/thread/f2dbc76e-dd54-4be6-b7d8-a72b1f1296ac/

  • Skeletal Tracking Fundamentals

    @Blas: I think ScaleTo() is the built-in function of the joint.After you uncomment the line 180, you should comment the CameraPosition() (line 118~121),then you can get a right answer. Maybe CameraPosition() has a high priority than ScaledPosition(), I think..

  • Skeletal Tracking Fundamentals

    @Blas: Maybe I think, You should check the GetCameraPoint() method. To scale the position of skeleton, CameraPosition() method must be commented. And After you uncomment the ScaledPosition() method in sensor_AllFrameReady event, You can get a right result!

  • Skeletal Tracking Fundamentals

    I solve the problem. Thanks for your help!

  • Skeletal Tracking Fundamentals

    @Dan:Definitely. Can you explain why this happens? I can`t find the reason.. Thanks!  

  • Skeletal Tracking Fundamentals

    @Dan:Hmm. That`s strange. I didn`t modifiy the sample code. I re-downloaded it, but the same problem occured in that situation.Joint Information is right,but scaledjoint is still incorrect..

    anyways. here is the code.

    bool closing = false;
            const int skeletonCount = 6; 
            Skeleton[] allSkeletons = new Skeleton[skeletonCount];
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
    
            }
    
            void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
                KinectSensor old = (KinectSensor)e.OldValue;
    
                StopKinect(old);
    
                KinectSensor sensor = (KinectSensor)e.NewValue;
    
                if (sensor == null)
                {
                    return;
                }
    
                
    
    
                var parameters = new TransformSmoothParameters
                {
                    Smoothing = 0.3f,
                    Correction = 0.0f,
                    Prediction = 0.0f,
                    JitterRadius = 1.0f,
                    MaxDeviationRadius = 0.5f
                };
                sensor.SkeletonStream.Enable(parameters);
    
                sensor.SkeletonStream.Enable();
    
                sensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(sensor_AllFramesReady);
                sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); 
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
    
                try
                {
                    sensor.Start();
                }
                catch (System.IO.IOException)
                {
                    kinectSensorChooser1.AppConflictOccurred();
                }
            }
    
            void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
            {
                if (closing)
                {
                    return;
                }
    
                //Get a skeleton
                Skeleton first =  GetFirstSkeleton(e);
    
                if (first == null)
                {
                    return; 
                }
    
    
    
                //set scaled position
                //ScalePosition(headImage, first.Joints[JointType.Head]);
                ScalePosition(leftEllipse, first.Joints[JointType.HandLeft]);
                ScalePosition(rightEllipse, first.Joints[JointType.HandRight]);
    
                GetCameraPoint(first, e); 
    
            }
    
            void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e)
            {
    
                using (DepthImageFrame depth = e.OpenDepthImageFrame())
                {
                    if (depth == null ||
                        kinectSensorChooser1.Kinect == null)
                    {
                        return;
                    }
                    
    
                    //Map a joint location to a point on the depth map
                    //head
                    DepthImagePoint headDepthPoint =
                        depth.MapFromSkeletonPoint(first.Joints[JointType.Head].Position);
                    //left hand
                    DepthImagePoint leftDepthPoint =
                        depth.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position);
                    //right hand
                    DepthImagePoint rightDepthPoint =
                        depth.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position);
    
    
                    //Map a depth point to a point on the color image
                    //head
                    ColorImagePoint headColorPoint =
                        depth.MapToColorImagePoint(headDepthPoint.X, headDepthPoint.Y,
                        ColorImageFormat.RgbResolution640x480Fps30);
                    //left hand
                    ColorImagePoint leftColorPoint =
                        depth.MapToColorImagePoint(leftDepthPoint.X, leftDepthPoint.Y,
                        ColorImageFormat.RgbResolution640x480Fps30);
                    //right hand
                    ColorImagePoint rightColorPoint =
                        depth.MapToColorImagePoint(rightDepthPoint.X, rightDepthPoint.Y,
                        ColorImageFormat.RgbResolution640x480Fps30);
    
    
                    //Set location
                    CameraPosition(headImage, headColorPoint);
                    CameraPosition(leftEllipse, leftColorPoint);
                    CameraPosition(rightEllipse, rightColorPoint);
                }        
            }
    
    
            Skeleton GetFirstSkeleton(AllFramesReadyEventArgs e)
            {
                using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
                {
                    if (skeletonFrameData == null)
                    {
                        return null; 
                    }
    
                    
                    skeletonFrameData.CopySkeletonDataTo(allSkeletons);
    
                    //get the first tracked skeleton
                    Skeleton first = (from s in allSkeletons
                                             where s.TrackingState == SkeletonTrackingState.Tracked
                                             select s).FirstOrDefault();
    
                    return first;
    
                }
            }
    
            private void StopKinect(KinectSensor sensor)
            {
                if (sensor != null)
                {
                    if (sensor.IsRunning)
                    {
                        //stop sensor 
                        sensor.Stop();
    
                        //stop audio if not null
                        if (sensor.AudioSource != null)
                        {
                            sensor.AudioSource.Stop();
                        }
    
    
                    }
                }
            }
    
            private void CameraPosition(FrameworkElement element, ColorImagePoint point)
            {
                //Divide by 2 for width and height so point is right in the middle 
                // instead of in top/left corner
                Canvas.SetLeft(element, point.X - element.Width / 2);
                Canvas.SetTop(element, point.Y - element.Height / 2);
    
            }
    
            private void ScalePosition(FrameworkElement element, Joint joint)
            {
                //convert the value to X/Y
                Joint scaledJoint = joint.ScaleTo(1280, 720); 
                
                //convert & scale (.3 = means 1/3 of joint distance)
                //Joint scaledJoint = joint.ScaleTo(1280, 720, .3f, .3f);
    
                Canvas.SetLeft(element, scaledJoint.Position.X);
                Canvas.SetTop(element, scaledJoint.Position.Y); 
                
            }
    
    
            private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                closing = true; 
                StopKinect(kinectSensorChooser1.Kinect); 
            }

    only one that I modifiy is ScaledPosition Section.

    Thanks for your help!

  • Skeletal Tracking Fundamentals

    Hi! I have a question. In that sample code, scaledPosition method is not working.When I take a breakpoint at

    Joint scaledJoint = joint.ScaleTo(1280, 720); 

    in debug mode, scaledJointType is a HipCenter, not what I want. And trackingState fixed to 'NotTracked' mode.I don`t know what I have to do.please help. Thanks.

  • Setting up your Development Environment

    @Dan:Wow! It worked. Thanks a lot! I appreciate that.

  • Setting up your Development Environment

    @Dan: Thanks for replying.But still not working... I found the difference between the sample and mine is

    using Coding4Fun.Kinect.Wpf; and if(sensor.IsRunning){} section.

    Of course, the execution is fine. but when I unplug this(I try the way both usb cable and power adapter), NullreferenceException Ploblem is occured. Oh, and I got something to ask you. Is the usb cable using the main powerline of Xbox Kinect? I unplugged the usb cable, The Kinect`s power turned off and VS2010 got the error. 

    Anyways, I`ll try it as possible as i can. Thanks!