예제 #1
0
        private Vector2 SkeletonToColorMap(SkeletonPoint point)
        {
            if ((null != sensor) && (null != sensor.ColorStream))
            {
                // This is used to map a skeleton point to the color image location
                ColorImagePoint colorPt = mapper.MapSkeletonPointToColorPoint(point, sensor.ColorStream.Format);
                return(new Vector2(colorPt.X, colorPt.Y));
            }

            return(Vector2.Zero);
        }
예제 #2
0
        //fills the skeleton info with infromation from the last skeleton frame
        private void _populateSkelInfo(int iter, GameState state)
        {
            SkeletonInfo tmp = new SkeletonInfo();

            tmp.TrackingID = _skeletonList[iter].TrackingId;
            tmp.Tracked    = _skeletonList[iter].TrackingState;

            var rightHand = _skeletonList[iter].Joints[JointType.HandRight];

            tmp.DisplayPosition = _coordMapper.MapSkeletonPointToColorPoint(_skeletonList[iter].Joints[JointType.ShoulderCenter].Position, ColorImageFormat.RgbResolution640x480Fps30);
            tmp.LeftHand        = _coordMapper.MapSkeletonPointToColorPoint(_skeletonList[iter].Joints[JointType.HandLeft].Position, ColorImageFormat.RgbResolution640x480Fps30);
            tmp.RightHand       = _coordMapper.MapSkeletonPointToColorPoint(rightHand.Position, ColorImageFormat.RgbResolution640x480Fps30);
            tmp.RightShoulder   = _coordMapper.MapSkeletonPointToColorPoint(_skeletonList[iter].Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30);

            if ((state ^ GameState.SinglePlayer) == GameState.Running ||
                (state ^ GameState.MultiPlayer) == GameState.Running)
            {
                _cursor.ToggleDisplay(false);
                var rightVec = new Vector2();
                var leftVec  = new Vector2();

                _calculateVectors(ref rightVec, ref leftVec, tmp);

                _selectNextColor(rightVec, leftVec, ref tmp);
                _getIndividualRot(rightVec, leftVec, ref tmp);
            }
            else if (iter < 1)
            {
                _cursor.ToggleDisplay(true);

                var world    = new Vector2(640, 480);
                var width    = world.X * .4f;
                var height   = world.Y * .4f;
                var bounding = new Rectangle(tmp.RightShoulder.X - (int)(width / 2),
                                             tmp.RightShoulder.Y - (int)(height / 2),
                                             (int)width, (int)height);

                var location = new ColorImagePoint();
                if (bounding.Contains(tmp.RightHand.X, tmp.RightHand.Y))
                {
                    location.X = tmp.RightHand.X - bounding.X;
                    location.Y = tmp.RightHand.Y - bounding.Y;
                    location   = location.BoundingToWorldSpace(new Vector2(width, height), world);
                }
                _cursor.Pos = new Vector2(location.X, location.Y);
                _cursor.Update(state);
            }

            AssignSkeletonInfo(tmp, iter);
        }
예제 #3
0
        public void MapCameraPointsToColorSpace(Vector3[] cameraPoints, Vector2[] colorPoints)
        {
            for (int i = 0; i < cameraPoints.Length && i < colorPoints.Length; i++)
            {
                var colorSpacePoint =
                    _coordinateMapper.MapSkeletonPointToColorPoint(new SkeletonPoint
                {
                    X = cameraPoints[i].X,
                    Y = cameraPoints[i].Y,
                    Z = cameraPoints[i].Z
                }, _kinect360.ColorFrameStream == null ? ColorImageFormat.RgbResolution640x480Fps30 : _kinect360._colorFrameStream.ColorImageFormat);

                colorPoints[i] = new Vector2(colorSpacePoint.X, colorSpacePoint.Y);
            }
        }
    public static ColorImagePoint GetColorImagePointFromSkeletonPoint(KinectSensor kSensor, Skeleton skeletonToTrack, JointType jointTpe)
    {
        CoordinateMapper coordinateMapper = new CoordinateMapper(kSensor);
        SkeletonPoint    pos = skeletonToTrack.Joints[jointTpe].Position;

        return(coordinateMapper.MapSkeletonPointToColorPoint(pos, ColorImageFormat.RgbResolution1280x960Fps12));
    }
예제 #5
0
        private void KSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (var frame = e.OpenColorImageFrame())
                if (frame != null)
                {
                    pbKinectStream.Image = CreateBitmapFromSensor(frame);
                }
            //pour récupérer l'image de la kinect il faut créer un bitmap

            using (var frame = e.OpenSkeletonFrame())
            {
                //pour récupérer le squelette
                if (frame != null)
                {
                    var skeletons = new Skeleton[frame.SkeletonArrayLength];
                    frame.CopySkeletonDataTo(skeletons);

                    var TrackedSkeleton = skeletons.FirstOrDefault(s => s.TrackingState == SkeletonTrackingState.Tracked);


                    if (TrackedSkeleton != null)
                    {
                        //récupérer la position de la main droite
                        var position = TrackedSkeleton.Joints[JointType.HandRight].Position;
                        //récupérer les coordonées
                        var coordinateMapper = new CoordinateMapper(kSensor);
                        var colorPoint       = coordinateMapper.MapSkeletonPointToColorPoint(position, ColorImageFormat.InfraredResolution640x480Fps30);
                        this.lblPosition.Text = string.Format(" Hand Position X : {0}, Y : {1}", colorPoint.X, colorPoint.Y);
                        //liaison de la souris au mouvement de la main droite
                        Cursor.Position = new Point(colorPoint.X, colorPoint.Y);
                        Cursor.Clip     = new Rectangle(this.Location, this.Size);
                    }
                }
            }
        }
예제 #6
0
        /*
         * Tracks a hand by marking it with a light blue ellipse.
         */
        public static void DrawTrackedHands(this Canvas canvas, Joint hand, CoordinateMapper mapper)
        {
            if (hand.TrackingState == JointTrackingState.NotTracked)
            {
                return;
            }

            Point point = new Point();

            // Use CoordinateMapper to map the point of the hand's position to the appropriate point in the color stream
            // Need to do this because resolution varies between skeleton stream and color stream
            ColorImagePoint colorPoint = mapper.MapSkeletonPointToColorPoint(hand.Position, ColorImageFormat.RgbResolution1280x960Fps12);

            point.X = colorPoint.X;
            point.Y = colorPoint.Y;

            Ellipse ellipse = new Ellipse
            {
                Width           = 50,
                Height          = 50,
                Stroke          = new SolidColorBrush(Colors.LightBlue),
                StrokeThickness = 4
            };

            Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
            Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);

            canvas.Children.Add(ellipse);
        }
예제 #7
0
파일: Tools.cs 프로젝트: K-Cully/SticKart
        /// <summary>
        /// Maps a 3D skeleton point to a 2D vector.
        /// </summary>
        /// <param name="sensor">The Kinect sensor.</param>
        /// <param name="position">The skeleton point to map.</param>
        /// <param name="coordinateMapper">The coordinate mapper.</param>
        /// <returns>The 2D mapped position.</returns>
        public static Vector2 Convert(KinectSensor sensor, SkeletonPoint position, CoordinateMapper coordinateMapper)
        {
            float width  = 0;
            float height = 0;
            float x      = 0;
            float y      = 0;

            if (sensor.ColorStream.IsEnabled)
            {
                var colorPoint = coordinateMapper.MapSkeletonPointToColorPoint(position, sensor.ColorStream.Format);
                x = colorPoint.X;
                y = colorPoint.Y;

                switch (sensor.ColorStream.Format)
                {
                case ColorImageFormat.RawYuvResolution640x480Fps15:
                case ColorImageFormat.RgbResolution640x480Fps30:
                case ColorImageFormat.YuvResolution640x480Fps15:
                    width  = 640;
                    height = 480;
                    break;

                case ColorImageFormat.RgbResolution1280x960Fps12:
                    width  = 1280;
                    height = 960;
                    break;
                }
            }
            else if (sensor.DepthStream.IsEnabled)
            {
                var depthPoint = coordinateMapper.MapSkeletonPointToDepthPoint(position, sensor.DepthStream.Format);
                x = depthPoint.X;
                y = depthPoint.Y;

                switch (sensor.DepthStream.Format)
                {
                case DepthImageFormat.Resolution80x60Fps30:
                    width  = 80;
                    height = 60;
                    break;

                case DepthImageFormat.Resolution320x240Fps30:
                    width  = 320;
                    height = 240;
                    break;

                case DepthImageFormat.Resolution640x480Fps30:
                    width  = 640;
                    height = 480;
                    break;
                }
            }
            else
            {
                width  = 1;
                height = 1;
            }

            return(new Vector2(x / width, y / height));
        }
예제 #8
0
        void sensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            depthImagePixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];
            using (var frame = e.OpenDepthImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                frame.CopyDepthImagePixelDataTo(depthImagePixels);
            }

            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                var bitmap = CreateBitmap(frame);
                VideoCanvas.Background = new ImageBrush(bitmap);
            }

            using (var frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                var skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);
                var skeleton = skeletons.FirstOrDefault(sk => sk.TrackingState == SkeletonTrackingState.Tracked);
                if (skeleton == null)
                {
                    return;
                }

                var rigthHandPosition     = skeleton.Joints[JointType.HandRight].Position;
                var leftHandPosition      = skeleton.Joints[JointType.HandLeft].Position;
                var headPosition          = skeleton.Joints[JointType.Head].Position;
                var armsPosition          = skeleton.Joints[JointType.ShoulderCenter].Position;
                var shoulderLeftPosition  = skeleton.Joints[JointType.ShoulderLeft].Position;
                var shoulderRigthPosition = skeleton.Joints[JointType.ShoulderRight].Position;
                var hipCenterPosition     = skeleton.Joints[JointType.HipCenter].Position;

                var mapper = new CoordinateMapper(sensor);

                var rightHandCoord     = mapper.MapSkeletonPointToColorPoint(rigthHandPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var headCoord          = mapper.MapSkeletonPointToColorPoint(headPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var armsCenterCoord    = mapper.MapSkeletonPointToColorPoint(armsPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var shoulderLeftCoord  = mapper.MapSkeletonPointToColorPoint(shoulderLeftPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var shoulderRightCoord = mapper.MapSkeletonPointToColorPoint(shoulderRigthPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var leftHandCoord      = mapper.MapSkeletonPointToColorPoint(leftHandPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var hipCenterCoord     = mapper.MapSkeletonPointToColorPoint(hipCenterPosition, ColorImageFormat.RgbResolution640x480Fps30);

                this.DetectGestures(headCoord, rightHandCoord, leftHandCoord, armsCenterCoord, shoulderLeftCoord, shoulderRightCoord, hipCenterCoord);
            }
        }
예제 #9
0
        void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs allFrame)
        {
            if (null == this._KinectDevice)
            {
                return;
            }
            using (ColorImageFrame colorFrame = allFrame.OpenColorImageFrame())
            {
                rawColorPixelData = new byte[this._KinectDevice.ColorStream.FramePixelDataLength];


                if (null != colorFrame)
                {                   // Copy the pixel data from the image to a temporary array
                                    //colorFrame.CopyPixelDataTo(secondColorPixelData);
                    colorFrame.CopyPixelDataTo(rawColorPixelData);

                    // texture = new Texture2D(graphics.GraphicsDevice, 1280, 960);
                    //  texture.SetData(playerImage);
                }
                using (SkeletonFrame skeletonFrame = allFrame.OpenSkeletonFrame())
                {
                    if (null != skeletonFrame)
                    {
                        skeletonFrame.CopySkeletonDataTo(this._SkeletonData);
                        first = (from s in this._SkeletonData where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
                        if (first == null)
                        {
                            return;
                        }
                        JointType joint = JointType.Head;
                        headPosition           = new Vector3(first.Joints[joint].Position.X, first.Joints[joint].Position.Y, first.Joints[joint].Position.Z);
                        joint                  = JointType.ShoulderCenter;
                        shoulderCenterPosition = new Vector3(first.Joints[joint].Position.X, first.Joints[joint].Position.Y, first.Joints[joint].Position.Z);
                        joint                  = JointType.HipCenter;
                        hipCenterPosition      = new Vector3(first.Joints[joint].Position.X, first.Joints[joint].Position.Y, first.Joints[joint].Position.Z);
                        joint                  = JointType.HandLeft;
                        handLeftPosition       = new Vector3(first.Joints[joint].Position.X, first.Joints[joint].Position.Y, first.Joints[joint].Position.Z);

                        joint = JointType.ShoulderLeft;
                        shoulderLeftPosition = new Vector3(first.Joints[joint].Position.X, first.Joints[joint].Position.Y, first.Joints[joint].Position.Z);
                        joint = JointType.ShoulderRight;
                        shoulderRightPosition = new Vector3(first.Joints[joint].Position.X, first.Joints[joint].Position.Y, first.Joints[joint].Position.Z);
                        joint = JointType.HandRight;


                        handRightPosition = coordinateMapper.MapSkeletonPointToColorPoint(first.Joints[joint].Position, ColorImageFormat.RgbResolution1280x960Fps12);
                        using (DepthImageFrame depthFrame = allFrame.OpenDepthImageFrame())
                        {
                            if (null != depthFrame)
                            {
                                depthFrame.CopyPixelDataTo(this._DepthPixelData);
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
파일: Tools.cs 프로젝트: K-Cully/SticKart
        /// <summary>
        /// Maps a 3D skeleton point to a 2D vector.
        /// </summary>
        /// <param name="sensor">The Kinect sensor.</param>
        /// <param name="position">The skeleton point to map.</param>
        /// <param name="coordinateMapper">The coordinate mapper.</param>
        /// <returns>The 2D mapped position.</returns>
        public static Vector2 Convert(KinectSensor sensor, SkeletonPoint position, CoordinateMapper coordinateMapper)
        {
            float width = 0;
            float height = 0;
            float x = 0;
            float y = 0;

            if (sensor.ColorStream.IsEnabled)
            {
                var colorPoint = coordinateMapper.MapSkeletonPointToColorPoint(position, sensor.ColorStream.Format);
                x = colorPoint.X;
                y = colorPoint.Y;

                switch (sensor.ColorStream.Format)
                {
                    case ColorImageFormat.RawYuvResolution640x480Fps15:
                    case ColorImageFormat.RgbResolution640x480Fps30:
                    case ColorImageFormat.YuvResolution640x480Fps15:
                        width = 640;
                        height = 480;
                        break;
                    case ColorImageFormat.RgbResolution1280x960Fps12:
                        width = 1280;
                        height = 960;
                        break;
                }
            }
            else if (sensor.DepthStream.IsEnabled)
            {
                var depthPoint = coordinateMapper.MapSkeletonPointToDepthPoint(position, sensor.DepthStream.Format);
                x = depthPoint.X;
                y = depthPoint.Y;

                switch (sensor.DepthStream.Format)
                {
                    case DepthImageFormat.Resolution80x60Fps30:
                        width = 80;
                        height = 60;
                        break;
                    case DepthImageFormat.Resolution320x240Fps30:
                        width = 320;
                        height = 240;
                        break;
                    case DepthImageFormat.Resolution640x480Fps30:
                        width = 640;
                        height = 480;
                        break;
                }
            }
            else
            {
                width = 1;
                height = 1;
            }

            return new Vector2(x / width, y / height);
        }
예제 #11
0
        private void posicionEllipse(Ellipse ellipse, Joint joint)
        {
            CoordinateMapper mapping = miKinect.CoordinateMapper;

            var point = mapping.MapSkeletonPointToColorPoint(joint.Position, miKinect.ColorStream.Format);

            Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
            Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
        }
예제 #12
0
        private void MoveToCameraPosition(FrameworkElement element, Joint joint)
        {
            ColorImagePoint point =
                _coorMapper.MapSkeletonPointToColorPoint(joint.Position, _kinect.ColorStream.Format);

            //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);
        }
예제 #13
0
        public static Vector2 Convert(CoordinateMapper mapper, SkeletonPoint position,
                                  Object format = null)
        {
            float width = 0;
              float height = 0;
              float x = 0;
              float y = 0;

              if (format != null) {
            if (format is ColorImageFormat) {
              var colorFormat = (ColorImageFormat)format;
              var colorPoint = mapper.MapSkeletonPointToColorPoint(position, colorFormat);
              x = colorPoint.X;
              y = colorPoint.Y;

              switch (colorFormat) {
            case ColorImageFormat.RawYuvResolution640x480Fps15:
            case ColorImageFormat.RgbResolution640x480Fps30:
            case ColorImageFormat.YuvResolution640x480Fps15:
              width = 640;
              height = 480;
              break;
            case ColorImageFormat.RgbResolution1280x960Fps12:
              width = 1280;
              height = 960;
              break;
              }
            } else if (format is DepthImageFormat) {
              var depthFormat = (DepthImageFormat)format;
              var depthPoint = mapper.MapSkeletonPointToDepthPoint(position, depthFormat);
              x = depthPoint.X;
              y = depthPoint.Y;

              switch (depthFormat) {
            case DepthImageFormat.Resolution80x60Fps30:
              width = 80;
              height = 60;
              break;
            case DepthImageFormat.Resolution320x240Fps30:
              width = 320;
              height = 240;
              break;
            case DepthImageFormat.Resolution640x480Fps30:
              width = 640;
              height = 480;
              break;
              }
            } else {
              width = 1;
              height = 1;
            }
              }

              return new Vector2(x / width, y / height);
        }
        /// <summary>
        /// Map PointSkeleton3D to Point2D
        /// </summary>
        /// <param name="pointSkleton3D"></param>
        /// <param name="colorImageFormat"></param>
        /// <returns></returns>
        public Point2D MapSkeletonPointToColorPoint(PointSkeleton3D pointSkleton3D, ColorImageFormat colorImageFormat)
        {
            SkeletonPoint point = new SkeletonPoint();

            point.X = pointSkleton3D.X;
            point.Y = pointSkleton3D.Y;
            point.Z = pointSkleton3D.Z;
            ColorImagePoint ImgPoint = mapper.MapSkeletonPointToColorPoint(point, colorImageFormat);

            return(new Point2D(ImgPoint.X, ImgPoint.Y));
        }
예제 #15
0
        public void DrawBone(Joint first, Joint second, Brush brush, double thickness)
        {
            if (first.TrackingState == JointTrackingState.NotTracked || second.TrackingState == JointTrackingState.NotTracked)
            {
                return;
            }

            Point firstPoint  = new Point(_ratioX, _ratioY);
            Point secondPoint = new Point(_ratioX, _ratioY);

            switch (FrameType)
            {
            case VisualizationMode.Color:
            {
                ColorImagePoint colorFirstPoint = CoordinateMapper.MapSkeletonPointToColorPoint(first.Position, ColorImageFormat.RgbResolution640x480Fps30);
                firstPoint.X *= float.IsInfinity(colorFirstPoint.X) ? 0.0 : colorFirstPoint.X;
                firstPoint.Y *= float.IsInfinity(colorFirstPoint.Y) ? 0.0 : colorFirstPoint.Y;

                ColorImagePoint colorSecondPoint = CoordinateMapper.MapSkeletonPointToColorPoint(second.Position, ColorImageFormat.RgbResolution640x480Fps30);
                secondPoint.X *= float.IsInfinity(colorSecondPoint.X) ? 0.0 : colorSecondPoint.X;
                secondPoint.Y *= float.IsInfinity(colorSecondPoint.Y) ? 0.0 : colorSecondPoint.Y;
            }
            break;

            case VisualizationMode.Depth:
            case VisualizationMode.Infrared:
            {
                DepthImagePoint depthFirstPoint = CoordinateMapper.MapSkeletonPointToDepthPoint(first.Position, DepthImageFormat.Resolution320x240Fps30);
                firstPoint.X *= float.IsInfinity(depthFirstPoint.X) ? 0.0 : depthFirstPoint.X;
                firstPoint.Y *= float.IsInfinity(depthFirstPoint.Y) ? 0.0 : depthFirstPoint.Y;

                DepthImagePoint depthSecondPoint = CoordinateMapper.MapSkeletonPointToDepthPoint(second.Position, DepthImageFormat.Resolution320x240Fps30);
                secondPoint.X *= float.IsInfinity(depthSecondPoint.X) ? 0.0 : depthSecondPoint.X;
                secondPoint.Y *= float.IsInfinity(depthSecondPoint.Y) ? 0.0 : depthSecondPoint.Y;
            }
            break;

            default:
                break;
            }

            Line line = new Line
            {
                Tag             = TAG,
                X1              = firstPoint.X,
                Y1              = firstPoint.Y,
                X2              = secondPoint.X,
                Y2              = secondPoint.Y,
                StrokeThickness = thickness,
                Stroke          = brush
            };

            canvas.Children.Add(line);
        }
예제 #16
0
        public static string Serialize(this List <Skeleton> skeletons, CoordinateMapper mapper)
        {
            JSONSkeleton jsonSkeleton = new JSONSkeleton
            {
                head  = new JSONArea(),
                hands = new List <JSONJoint>()
            };
            JSONJoint        headTop    = new JSONJoint();
            JSONJoint        headBottom = new JSONJoint();
            var              skeleton   = skeletons.First();
            List <JSONJoint> Joints     = new List <JSONJoint>();

            foreach (Joint joint in skeleton.Joints)
            {
                Point point = new Point();

                ColorImagePoint colorPoint = mapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                point.X = colorPoint.X;
                point.Y = colorPoint.Y;

                JSONJoint jointToAdd = new JSONJoint
                {
                    X = point.X,
                    Y = point.Y,
                    Z = joint.Position.Z
                };
                switch (joint.JointType.ToString().ToLower())
                {
                case "handleft":
                    jsonSkeleton.hands.Add(jointToAdd);
                    break;

                case "handright":
                    jsonSkeleton.hands.Add(jointToAdd);
                    break;

                case "head":
                    headTop = jointToAdd;
                    break;

                case "shouldercenter":
                    headBottom = jointToAdd;
                    break;
                }
            }
            double headSize = headBottom.Y - headTop.Y;

            jsonSkeleton.head.X  = headBottom.X - (headSize / 2);
            jsonSkeleton.head.Y  = headBottom.Y;
            jsonSkeleton.head.DX = headSize;
            jsonSkeleton.head.DY = -headSize;
            jsonSkeleton.head.Z  = (headTop.Z + headBottom.Z) / 2;
            return(objToJson(jsonSkeleton));
        }
예제 #17
0
 protected void Map2DJoints(Skeleton sk, CoordinateMapper mapper)
 {
     if (null == sk)
     {
         return;
     }
     foreach (Joint jt in sk.Joints)
     {
         var pts = mapper.MapSkeletonPointToColorPoint(jt.Position, ColorFormat);
         Joints2D[jt.JointType] = new System.Drawing.Point(pts.X, pts.Y);
     }
 }
        private ColorImagePoint GetPointToUse(Skeleton skel)
        {
            /* Get the points of the right and left shoulders */
            CoordinateMapper coordMapper   = new CoordinateMapper(sensorChooser.Kinect);
            ColorImagePoint  rightShoulder = coordMapper.MapSkeletonPointToColorPoint(skel.Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30);
            ColorImagePoint  leftShoulder  = coordMapper.MapSkeletonPointToColorPoint(skel.Joints[JointType.ShoulderLeft].Position, ColorImageFormat.RgbResolution640x480Fps30);

            if (rightShoulder == null || leftShoulder == null)
            {
                throw new ArgumentNullException("Could not find one or both shoulders");
            }

            if (rightShoulder.X > leftShoulder.X)
            {
                return(rightShoulder);
            }
            else
            {
                return(leftShoulder);
            }
        }
예제 #19
0
        void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            depthImagePixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];
            using (var frame = e.OpenDepthImageFrame())
            {
                if (frame == null)
                {
                    return;
                }
                frame.CopyDepthImagePixelDataTo(depthImagePixels);
            }

            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }
                var bitmap = CreateBitmapFromFrame(frame);
                imageCanvas.Background = new ImageBrush(bitmap);
            }

            using (var frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // get all skeletons seaned by kinect sensors
                var skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);

                // get actually tracked skeleton
                var skeleton = skeletons.FirstOrDefault(x => x.TrackingState == SkeletonTrackingState.Tracked);
                if (skeleton == null)
                {
                    return;
                }

                //get position of right hand
                var position = skeleton.Joints[JointType.HandRight].Position;

                //recalculate coordinates from skeleton coordinates to screen coordinates
                var mapper     = new CoordinateMapper(sensor);
                var colorPoint = mapper.MapSkeletonPointToColorPoint(position, ColorImageFormat.RgbResolution640x480Fps30);

                // draw circle at point where player right hand is
                var circle = CreateCircle(colorPoint);
                imageCanvas.Children.Add(circle);
            }
        }
예제 #20
0
        private void SetEllipsePosition(Ellipse ellipse, Joint joint)
        {
            ellipse.Width  = 10;
            ellipse.Height = 10;
            ellipse.Fill   = new SolidColorBrush(Colors.Red);

            CoordinateMapper mapper = sensor.CoordinateMapper;

            var point = mapper.MapSkeletonPointToColorPoint(joint.Position, sensor.ColorStream.Format);

            Canvas.SetLeft(ellipse, point.X - ellipse.ActualWidth / 2);
            Canvas.SetTop(ellipse, point.Y - ellipse.ActualHeight / 2);
        }
        static void AllFramesReady(Object sender, AllFramesReadyEventArgs e)
        {
            //  Console.WriteLine("AllFramesReady() called");
            if (e != null)
            {
                SkeletonFrame sFrame = e.OpenSkeletonFrame();


                CoordinateMapper cm = new CoordinateMapper(sensor);
                if (sFrame != null)
                {
                    //  Console.WriteLine("Got Skeleton");
                    Skeleton[] skeletons = new Skeleton[sFrame.SkeletonArrayLength];
                    sFrame.CopySkeletonDataTo(skeletons);
                    SkeletonPoint sLoc = new SkeletonPoint();
                    foreach (Skeleton s in skeletons)
                    {
                        if (s.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            sLoc = s.Joints[JointType.Head].Position;
                            DepthFrameReady(sender, e.OpenDepthImageFrame(), e.OpenColorImageFrame(), sLoc);
                            //  Console.WriteLine("Head coordinates: " + sLoc.X + "," + sLoc.Y + "," + sLoc.Z);
                            ColorImagePoint cLoc = cm.MapSkeletonPointToColorPoint(sLoc, ColorImageFormat.RgbResolution640x480Fps30);
                            DepthImagePoint dLoc = cm.MapSkeletonPointToDepthPoint(sLoc, DepthImageFormat.Resolution640x480Fps30);
                            Console.WriteLine("Head coordinates: " + dLoc.X + "," + dLoc.Y);
                        }
                    }
                    sFrame.Dispose();
                }

                if (block == false)
                {
                    dp   = new DepthImagePoint();
                    cp   = new ColorImagePoint();
                    cp.X = 320;
                    cp.Y = 240;
                    dp.X = 320;
                    dp.Y = 240;
                    ////cp = cLoc;
                    //cp = cm.MapDepthPointToColorPoint(DepthImageFormat.Resolution640x480Fps30, dp, ColorImageFormat.RgbResolution640x480Fps30);
                    Console.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + cp.X + "    " + cp.Y);
                    //dp = dLoc;
                }
                // ColorImagePoint cLoc = sensor.MapSkeletonPointToColor(sLoc, e.OpenColorImageFrame().Format);
                // nearX = dLoc.X;
                // nearY = dLoc.Y;
                nearX = dp.X;
                nearY = dp.Y;
                ImageFrameReady(sender, e.OpenColorImageFrame());
            }
        }
예제 #22
0
        void DrawBoneLine(SkeletonPoint skeletonFrom, SkeletonPoint skeletonTo, JointTrackingState trackingState)
        {
            var colorImagePointFrom = mapper.MapSkeletonPointToColorPoint(skeletonFrom, ColorImageFormat.RgbResolution640x480Fps30);
            var colorImagePointTo   = mapper.MapSkeletonPointToColorPoint(skeletonTo, ColorImageFormat.RgbResolution640x480Fps30);

            var color = Color.Red;

            switch (trackingState)
            {
            case JointTrackingState.Tracked:
                color = Color.Red;
                break;

            case JointTrackingState.Inferred:
                color = Color.Blue;
                break;
            }

            graphics.DrawLine(new Pen(color)
            {
                Width = 4
            }, colorImagePointFrom.X, colorImagePointFrom.Y, colorImagePointTo.X, colorImagePointTo.Y);
        }
예제 #23
0
        //Serializes an array of Kinect skeletons into an array of JSON skeletons.The Kinect skeletons.The coordinate mapper.Mode (color or depth)
        public static string Serialize(this List <Skeleton> skeletons, CoordinateMapper mapper, Mode mode)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID     = skeleton.TrackingId.ToString(),
                    Joints = new List <JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    Point point = new Point();

                    switch (mode)
                    {
                    case Mode.Color:
                        ColorImagePoint colorPoint = mapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                        point.X = colorPoint.X;
                        point.Y = colorPoint.Y;
                        break;

                    case Mode.Depth:
                        DepthImagePoint depthPoint = mapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution640x480Fps30);
                        point.X = depthPoint.X;
                        point.Y = depthPoint.Y;
                        break;

                    default:
                        break;
                    }

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = joint.JointType.ToString().ToLower(),
                        X    = joint.Position.X,
                        Y    = joint.Position.Y,
                        Z    = joint.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return(Serialize(jsonSkeletons));
        }
예제 #24
0
        /// <summary>
        /// 根据显示分辨率与彩色图像帧的分辨率的比例,来调整显示坐标
        /// </summary>
        /// <param name="joint"></param>
        /// <returns></returns>
        private Point TransferSkeletonPoint(Joint joint)
        {
            ColorImagePoint colorPoint = mapper.MapSkeletonPointToColorPoint(joint.Position, nui.ColorStream.Format);
            double          xScaleRate = (SystemParameters.PrimaryScreenWidth) / 640;
            double          yScaleRate = (SystemParameters.PrimaryScreenHeight) / 480;

            double x = (double)colorPoint.X;

            x *= xScaleRate;
            double y = (double)colorPoint.Y;

            y *= yScaleRate;

            return(new Point((int)x, (int)y));
        }
예제 #25
0
        public static void InteractionZoneToUserInterface(double izX, double izY, double izZ, double userInterfaceWidth, double userInterfaceHeight, byte[] mapperParameters, out double uiX, out double uiY)
        {
            var skelPoint = new SkeletonPoint()
            {
                X = (float)izX,
                Y = (float)izY,
                Z = (float)izZ
            };
            //joint.Position = skelPoint;
            //joint.ScaleTo((int)userInterfaceWidth, (int)userInterfaceHeight);
            var mapper     = new CoordinateMapper(mapperParameters);
            var colorPoint = mapper.MapSkeletonPointToColorPoint(skelPoint, ColorImageFormat.RgbResolution640x480Fps30);

            uiX = (int)((colorPoint.X / 640.0) * userInterfaceWidth);
            uiY = (int)((colorPoint.Y / 480.0) * userInterfaceHeight);
        }
예제 #26
0
        private Vector2 SkeletonToColorMap(Vector3 joint)
        {
            SkeletonPoint point = new SkeletonPoint();

            point.X = joint.X;
            point.Y = joint.Y;
            point.Z = joint.Z;
            if ((null != sensor) && (null != sensor.ColorStream))
            {
                // This is used to map a skeleton point to the color image location
                ColorImagePoint colorPt = mapper.MapSkeletonPointToColorPoint(point, sensor.ColorStream.Format);
                return(new Vector2(colorPt.X + this.x, colorPt.Y + this.y));
            }

            return(Vector2.Zero);
        }
예제 #27
0
        private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            depthImagePixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];
            using (var frame = e.OpenDepthImageFrame())
            {
                if (frame == null)
                {
                    return;
                }
                frame.CopyDepthImagePixelDataTo(depthImagePixels);
            }

            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }
                var bitmap = CreateBitmap(frame);
                ImageCanvas.Background = new ImageBrush(bitmap);
            }

            using (var frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                var skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);

                var skeleton = skeletons.FirstOrDefault(s => s.TrackingState == SkeletonTrackingState.Tracked);
                if (skeleton == null)
                {
                    return;
                }

                var position   = skeleton.Joints[JointType.HandRight].Position;
                var mapper     = new CoordinateMapper(sensor);
                var colorPoint = mapper.MapSkeletonPointToColorPoint(position, ColorImageFormat.InfraredResolution640x480Fps30);
                var circle     = CreateCircle(colorPoint);


                DetectChop(colorPoint, circle);
            }
        }
예제 #28
0
        public void DrawJoint(Joint joint, Brush brush, double radius)
        {
            if (joint.TrackingState == JointTrackingState.NotTracked)
            {
                return;
            }

            Point point = new Point(_ratioX, _ratioY);

            switch (FrameType)
            {
            case VisualizationMode.Color:
            {
                ColorImagePoint colorPoint = CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                point.X *= float.IsInfinity(colorPoint.X) ? 0.0 : colorPoint.X;
                point.Y *= float.IsInfinity(colorPoint.Y) ? 0.0 : colorPoint.Y;
            }
            break;

            case VisualizationMode.Depth:
            case VisualizationMode.Infrared:
            {
                DepthImagePoint depthPoint = CoordinateMapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution320x240Fps30);
                point.X *= float.IsInfinity(depthPoint.X) ? 0.0 : depthPoint.X;
                point.Y *= float.IsInfinity(depthPoint.Y) ? 0.0 : depthPoint.Y;
            }
            break;

            default:
                break;
            }

            Ellipse ellipse = new Ellipse
            {
                Tag    = TAG,
                Width  = radius,
                Height = radius,
                Fill   = brush
            };

            Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
            Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);

            canvas.Children.Add(ellipse);
        }
        private void DrawSkeletonOnVideo(CoordinateMapper coordinateMapper, Skeleton skeleton)
        {
            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            foreach (Microsoft.Kinect.Joint joint in skeleton.Joints)
            {
                ColorImagePoint colorImagePoint = coordinateMapper.MapSkeletonPointToColorPoint(
                    joint.Position, ColorImageFormat.RgbResolution640x480Fps30);

                Point point = new Point(colorImagePoint.X, colorImagePoint.Y);
                drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), new Pen(new SolidColorBrush(Colors.White), 3), point, 7, 7);
            }

            drawingContext.Close();
            RenderTargetBitmap renderBmp = new RenderTargetBitmap(640, 480, 96d, 96d, PixelFormats.Pbgra32);

            renderBmp.Render(drawingVisual);
            skeletonFrame.Source = renderBmp;
        }
        /// <summary>
        /// スケルトン(3D)座標を2D座標に変換する
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        private Point SkeletonToPiont(SkeletonPoint position)
        {
            Point point;
            Point _2d;

            if (SkeletonConvert == Skeleton2DPoint.Color)
            {
                var p = mapper.MapSkeletonPointToColorPoint(position, kinect.ColorStream.Format);
                point = new Point(p.X, p.Y);
                _2d   = new Point(kinect.ColorStream.FrameWidth, kinect.ColorStream.FrameHeight);
            }
            else
            {
                var p = mapper.MapSkeletonPointToDepthPoint(position, kinect.DepthStream.Format);
                point = new Point(p.X, p.Y);
                _2d   = new Point(kinect.DepthStream.FrameWidth, kinect.DepthStream.FrameHeight);
            }

            return(KinectUtility.ScaleTo(point, _2d, new Point(canvas.ActualWidth, canvas.ActualHeight)));
        }
        private void DrawSkeleton(CoordinateMapper coordinateMapper, Skeleton skeleton)
        {
            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            foreach (Joint joint in skeleton.Joints)
            {
                ColorImagePoint colorImagePoint = coordinateMapper.MapSkeletonPointToColorPoint(
                    joint.Position, ColorImageFormat.RgbResolution640x480Fps30);

                Point point = new Point(colorImagePoint.X, colorImagePoint.Y);
                drawingContext.DrawEllipse(new SolidColorBrush(Color.FromArgb(255, 255, 255, 0)),
                                           null, point, 5, 5);
            }

            drawingContext.Close();
            RenderTargetBitmap renderBmp = new RenderTargetBitmap(640, 480, 96d, 96d, PixelFormats.Pbgra32);

            renderBmp.Render(drawingVisual);
            skeletonFrame.Source = renderBmp;
        }
예제 #32
0
        //This method is used to position the ellipses on the canvas
        //according to correct movements of the tracked joints.
        private void SetEllipsePosition(Ellipse ellipse, Joint joint, bool isHighlighted)
        {
            if (isHighlighted)
            {
                ellipse.Width  = 40;
                ellipse.Height = 40;
                ellipse.Fill   = activeBrush;
            }
            else
            {
                ellipse.Width  = 40;
                ellipse.Height = 40;
                ellipse.Fill   = inactiveBrush;
            }

            CoordinateMapper mapper = sensor.CoordinateMapper;

            var point = mapper.MapSkeletonPointToColorPoint(joint.Position, sensor.ColorStream.Format);

            Canvas.SetLeft(ellipse, (point.X / (1.697612732095491)) - ellipse.ActualWidth / 2);
            Canvas.SetTop(ellipse, (point.Y / (1.395348837209302)) - ellipse.ActualHeight / 2);
        }
예제 #33
0
        private void DrawJoints(Skeleton skeleton)
        {
            foreach (var name in Enum.GetNames(typeof(JointType)))
            {
                var jointType = (JointType)Enum.Parse(typeof(JointType), name);
                var coordinateMapper = new CoordinateMapper(_kinectSensor);
                var joint = skeleton.Joints[jointType];

                var skeletonPoint = joint.Position;
                if (joint.TrackingState == JointTrackingState.NotTracked)
                    continue;

                var colorPoint = coordinateMapper.MapSkeletonPointToColorPoint(skeletonPoint, ColorImageFormat.RgbResolution640x480Fps30);
                if (!_bodyEllipses.ContainsKey(jointType))
                {
                    _bodyEllipses[jointType] = new Ellipse { Width = 20, Height = 20, Fill = Brushes.SandyBrown };
                    FaceCanvas.Children.Add(_bodyEllipses[jointType]);
                }
                Canvas.SetLeft(_bodyEllipses[jointType], colorPoint.X - _bodyEllipses[jointType].Width / 2);
                Canvas.SetTop(_bodyEllipses[jointType], colorPoint.Y - _bodyEllipses[jointType].Height / 2);
            }
        }
예제 #34
0
        /// <summary>
        /// Returns the position of a 3D vector on a 2D surface in VGA space
        /// </summary>
        /// <param name="j">current instance</param>
        /// <param name="nui">NUI Runtime</param>
        /// <param name="panel">The image which to project the vector on</param>
        /// <returns>2D position</returns>
        public static Point GetDisplayPositionVGA(this NUIVector j, KinectSensor nui, Canvas panel)
        {
            CoordinateMapper cm = new CoordinateMapper(nui);
            ColorImagePoint cip = cm.MapSkeletonPointToColorPoint(j, nui.ColorStream.Format);
            //nui.SkeletonStream.SkeletonToDepthImage(j, out depthX, out depthY, out depthValue);
            int colorX = cip.X;
            int colorY = cip.Y;

            return new Point((int)(colorX * panel.ActualWidth / 640), (int)(colorY * panel.ActualHeight / 480));
        }
        void sensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            depthImagePixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];
            using (var frame = e.OpenDepthImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                frame.CopyDepthImagePixelDataTo(depthImagePixels);
            }

            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                var bitmap = CreateBitmap(frame);
                VideoCanvas.Background = new ImageBrush(bitmap);
            }

            using (var frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                var skeletons = new Skeleton[frame.SkeletonArrayLength];
                frame.CopySkeletonDataTo(skeletons);
                var skeleton = skeletons.FirstOrDefault(sk => sk.TrackingState == SkeletonTrackingState.Tracked);
                if (skeleton == null)
                {
                    return;
                }

                var rigthHandPosition = skeleton.Joints[JointType.HandRight].Position;
                var leftHandPosition = skeleton.Joints[JointType.HandLeft].Position;
                var headPosition = skeleton.Joints[JointType.Head].Position;
                var armsPosition = skeleton.Joints[JointType.ShoulderCenter].Position;
                var shoulderLeftPosition = skeleton.Joints[JointType.ShoulderLeft].Position;
                var shoulderRigthPosition = skeleton.Joints[JointType.ShoulderRight].Position;
                var hipCenterPosition = skeleton.Joints[JointType.HipCenter].Position;

                var mapper = new CoordinateMapper(sensor);

                var rightHandCoord = mapper.MapSkeletonPointToColorPoint(rigthHandPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var headCoord = mapper.MapSkeletonPointToColorPoint(headPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var armsCenterCoord = mapper.MapSkeletonPointToColorPoint(armsPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var shoulderLeftCoord = mapper.MapSkeletonPointToColorPoint(shoulderLeftPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var shoulderRightCoord = mapper.MapSkeletonPointToColorPoint(shoulderRigthPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var leftHandCoord = mapper.MapSkeletonPointToColorPoint(leftHandPosition, ColorImageFormat.RgbResolution640x480Fps30);
                var hipCenterCoord = mapper.MapSkeletonPointToColorPoint(hipCenterPosition, ColorImageFormat.RgbResolution640x480Fps30);

                this.DetectGestures(headCoord, rightHandCoord, leftHandCoord, armsCenterCoord, shoulderLeftCoord, shoulderRightCoord, hipCenterCoord);
            }
        }
        private KinectDataPoint getDataPointRelativeToBody(JointCollection joints,
            JointType joint, CoordinateMapper coordinateMapper)
        {
            ColorImagePoint colorPoint = coordinateMapper.MapSkeletonPointToColorPoint(
                joints[joint].Position, ColorImageFormat.RgbResolution640x480Fps30);

            return new KinectDataPoint(colorPoint, joints[joint].Position, joints[JointType.ShoulderCenter].Position);
        }
예제 #37
0
 protected void Map2DJoints(Skeleton sk, CoordinateMapper mapper) {
   if (null == sk) { return;  }
   foreach (Joint jt in sk.Joints) {
     var pts   = mapper.MapSkeletonPointToColorPoint(jt.Position, ColorFormat);
     Joints2D[jt.JointType] = new System.Drawing.Point(pts.X, pts.Y);
   }
 }
예제 #38
0
        public OpenTK.Vector3[] ToColorSpace(CoordinateMapper mapper, IEnumerable<DepthImagePoint> points, DepthImageFormat format, float zTune = 1)
        {
            var sps = points.Select(p => mapper.MapDepthPointToSkeletonPoint(format, p)).ToArray();
            var dist = sps.Select(p => mapper.MapSkeletonPointToColorPoint(p, ColorImageFormat.RgbResolution1280x960Fps12))
                .Select(cp => new PointF((1280 - cp.X), cp.Y)).ToArray();

            return StereoCalibration.Undistort(calib, dist).Zip(sps, (p, s) => new OpenTK.Vector3(p.X * s.Z * zTune, p.Y * s.Z * zTune, s.Z * zTune)).ToArray();
        }
예제 #39
0
 public float[] ToColorSpace(CoordinateMapper mapper, SkeletonPoint point, float zTune = 1)
 {
     var cp = mapper.MapSkeletonPointToColorPoint(point, ColorImageFormat.RgbResolution1280x960Fps12);
     var up = StereoCalibration.Undistort(calib, new PointF[] { new PointF((1280 - cp.X), cp.Y) }).First();
     var z = point.Z * zTune;
     return new float[] { up.X * z, up.Y * z, z, 1 };
 }
        //public void initialstore(ReplaySkeletonFrame frame, int framenumber)


        public void storeframe(ReplaySkeletonFrame frame, int framenumber, CoordinateMapper replayCoordinateMapper)
        {
            //int framenumber;
            double leftShoulderAngle, leftHipAngle, leftKneeAngle, headHeight;
            double headX, headY, leftHandX, leftHandY, rightHandX, rightHandY;
            double leftshoulderX, leftshoulderY, rightshoulderX, rightshoulderY;
            double hipX, hipY, leftKneeX, leftKneeY, rightKneeX, rightKneeY;
            double leftFootX, leftFootY, rightFootX, rightFootY;

            //side view

            double headYabs, headZabs, leftHandYabs, leftHandZabs;
            double leftshoulderYabs, leftshoulderZabs, hipYabs, hipZabs;
            double leftKneeYabs, leftKneeZabs, leftFootYabs, leftFootZabs;



            if (isStartingFrame == true)
            {
                initialFrameNumber = framenumber;
                System.Console.WriteLine("initialFrame = " + initialFrameNumber);
                isStartingFrame = false;

            }

            if (frame == null)
            {
                //currentFrameNumber = framenumber - initialFrameNumber;
                leftShoulderAngle = 999;
                leftHipAngle = 999;
                leftKneeAngle = 999;
                headHeight = 999;
                headX = 999;
                headY = 999;
                leftHandX = 999;
                leftHandY = 999;
                rightHandX = 999;
                rightHandY = 999;
                leftshoulderX = 999;
                leftshoulderY = 999;
                rightshoulderX = 999;
                rightshoulderY = 999;
                hipX = 999;
                hipY = 999;
                leftKneeX = 999; 
                leftKneeY = 999;
                rightKneeX = 999;
                rightKneeY = 999;
                leftFootX = 999;
                leftFootY = 999;
                rightFootX = 999;
                rightFootY = 999;

                //side view
                headYabs = 999;
                headZabs = 999;
                leftHandYabs = 999;
                leftHandZabs = 999;
                leftshoulderYabs = 999;
                leftshoulderZabs = 999;
                hipYabs = 999;
                hipZabs = 999;
                leftKneeYabs = 999;
                leftKneeZabs = 999;
                leftFootYabs = 999;
                leftFootZabs = 999;
                

                //currentFrameNumber++;
            }

            else
            {


                var trackedSkeleton = frame.Skeletons.FirstOrDefault(a => a.TrackingState == SkeletonTrackingState.Tracked);
                //IMPORTATNT: 23 occurences frame here for deadlift1.replay
                if (trackedSkeleton == null)
                    return;

                //set starting frame of the video to index 1
                //framenumber = frame.FrameNumber - initialFrameNumber + 1;
                //currentFrameNumber = framenumber;
                leftShoulderAngle = JointAngle(trackedSkeleton.Joints[JointType.ShoulderLeft], trackedSkeleton.Joints[JointType.WristLeft], trackedSkeleton.Joints[JointType.HipLeft]);
                leftHipAngle = JointAngle(trackedSkeleton.Joints[JointType.HipLeft], trackedSkeleton.Joints[JointType.ShoulderLeft], trackedSkeleton.Joints[JointType.KneeLeft]);
                leftKneeAngle = JointAngle(trackedSkeleton.Joints[JointType.KneeLeft], trackedSkeleton.Joints[JointType.FootLeft], trackedSkeleton.Joints[JointType.HipLeft]);
                headHeight = trackedSkeleton.Joints[JointType.Head].Position.Y;
                //frontal view
                headX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.Head].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                headY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.Head].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftHandX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftHandY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightHandX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightHandY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HandRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftshoulderX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftshoulderY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightshoulderX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightshoulderY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                hipX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HipCenter].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                hipY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.HipCenter].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftKneeX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftKneeY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightKneeX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightKneeY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.KneeRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                leftFootX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                leftFootY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootLeft].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;
                rightFootX = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootRight].Position, ColorImageFormat.RgbResolution640x480Fps30).X;
                rightFootY = replayCoordinateMapper.MapSkeletonPointToColorPoint(trackedSkeleton.Joints[JointType.FootRight].Position, ColorImageFormat.RgbResolution640x480Fps30).Y;


                //side view 22/03/2013
                headYabs = trackedSkeleton.Joints[JointType.Head].Position.Y;
                headZabs = trackedSkeleton.Joints[JointType.Head].Position.Z;
                leftHandYabs = trackedSkeleton.Joints[JointType.HandLeft].Position.Y;
                leftHandZabs = trackedSkeleton.Joints[JointType.HandLeft].Position.Z;
                leftshoulderYabs = trackedSkeleton.Joints[JointType.ShoulderLeft].Position.Y;
                leftshoulderZabs = trackedSkeleton.Joints[JointType.ShoulderLeft].Position.Z;
                hipYabs = trackedSkeleton.Joints[JointType.HipCenter].Position.Y;
                hipZabs = trackedSkeleton.Joints[JointType.HipCenter].Position.Z;
                leftKneeYabs = trackedSkeleton.Joints[JointType.KneeLeft].Position.Y;
                leftKneeZabs = trackedSkeleton.Joints[JointType.KneeLeft].Position.Z;
                leftFootYabs = trackedSkeleton.Joints[JointType.FootLeft].Position.Y;
                leftFootZabs = trackedSkeleton.Joints[JointType.FootLeft].Position.Z;
                

            }

            currentFrameNumber = framenumber - initialFrameNumber + 1;
            //System.Console.WriteLine("framenumber = " + framenumber);
            //System.Console.WriteLine("initialFrameNumber = " + initialFrameNumber);
            //System.Console.WriteLine("currentFrameNumber = " + currentFrameNumber);
            Framedata currentframe = new Framedata(currentFrameNumber, leftHipAngle, leftShoulderAngle, leftKneeAngle, headHeight, headX, headY, leftHandX, leftHandY, rightHandX, rightHandY, leftshoulderX, leftshoulderY, rightshoulderX, rightshoulderY, hipX, hipY, leftKneeX, leftKneeY, rightKneeX, rightKneeY, leftFootX, leftFootY, rightFootX, rightFootY, headYabs, headZabs, leftHandYabs, leftHandZabs, leftshoulderYabs, leftshoulderZabs, hipYabs, hipZabs, leftKneeYabs, leftKneeZabs, leftFootYabs, leftFootZabs);
            jointsdata.Add(currentframe);



        }
예제 #41
0
 /// <summary>
 /// Map Joint Position to ColorImagePoint 
 /// </summary>
 /// <param name="joint"></param>
 /// <returns></returns>
 private Point getDisplayPosition(Joint joint)
 {
     CoordinateMapper mapper = new CoordinateMapper(this.SensorPlus.Sensor);
     ColorImagePoint point = mapper.MapSkeletonPointToColorPoint(joint.Position, this.SensorPlus.Sensor.ColorStream.Format);
     return new Point(point.X, point.Y);
 }
 public static ColorImagePoint MapToColor(this SkeletonPoint skeletonPoint, CoordinateMapper mapper, ColorImageFormat format = ColorImageFormat.RgbResolution640x480Fps30)
 {
     return mapper.MapSkeletonPointToColorPoint(skeletonPoint, format);
 }