Ejemplo n.º 1
0
        private Point GetPosition2DLocation(DepthImageFrame depthFrame, SkeletonPoint skeletonPoint)
        {
            DepthImagePoint depthPoint = depthFrame.MapFromSkeletonPoint(skeletonPoint);

            ColorImagePoint colorPoint = depthFrame.MapToColorImagePoint(depthPoint.X, depthPoint.Y, this._sensor.ColorStream.Format);

            // map back to skeleton.Width & skeleton.Height
            //return new Point(
            //    (int)(this.RenderSize.Width * colorPoint.X / this._sensor.ColorStream.FrameWidth),
            //    (int)(this.RenderSize.Height * colorPoint.Y / this._sensor.ColorStream.FrameHeight));
            return new Point(
                (int)(canvas1.Width * colorPoint.X / this._sensor.ColorStream.FrameWidth),
                (int)(canvas1.Height * colorPoint.Y / this._sensor.ColorStream.FrameHeight));
        }
        /// <summary>
        /// Convert real-world positions to 2D image coords.
        /// </summary>
        /// <param name="depthFrame">Datth frame used to conversion.</param>
        /// <param name="skeletonPosition">Point which position should be converted.</param>
        /// <returns>Point in 2D image.</returns>
        private Point GetPosition2DLocation(DepthImageFrame depthFrame, SkeletonPoint skeletonPosition)
        {
            DepthImagePoint depthPoint = depthFrame.MapFromSkeletonPoint(skeletonPosition);
            ColorImagePoint colorPoint = depthFrame.MapToColorImagePoint(depthPoint.X, depthPoint.Y, kinect.ColorStream.Format);

            // map back to skeleton.Width & skeleton.Height
            return new Point(colorPoint.X, colorPoint.Y);
        }
Ejemplo n.º 3
0
        public void ProcessFrame(KinectSensor sensor, byte[] colorImage, ColorImageFormat colorImageFormat, DepthImageFrame depthFrame, short[] depthImage, DepthImageFormat depthImageFormat, Skeleton[] skeletonData, SkeletonFrame skeletonFrame)
        {
            //Console.WriteLine("N: ---------");
            coordinates.Clear();
            int detectedFace = 0;
            int trackedSkeletonsCount = 0;

            int playerIndex = -1;
            for (int i = 0; i < skeletonData.Length; i++)
            //foreach (Skeleton skeleton in skeletonData)
            {
                Skeleton skeleton = skeletonData[i];
                if (skeleton.TrackingState == SkeletonTrackingState.Tracked
                    || skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                {
                    // We want keep a record of any skeleton, tracked or untracked.
                    if (!trackedSkeletons.ContainsKey(skeleton.TrackingId))
                    {
                        trackedSkeletons.Add(skeleton.TrackingId, new SkeletonFaceTracker());
                    }

                    DepthImagePoint depthPoint = depthFrame.MapFromSkeletonPoint(skeleton.Joints[JointType.Head].Position);
                    ColorImagePoint colorPoint = depthFrame.MapToColorImagePoint(depthPoint.X, depthPoint.Y, colorImageFormat);

                    Coordinates2D c = new Coordinates2D();

                    playerIndex = i + 1;

                    c.X = colorPoint.X;
                    c.Y = colorPoint.Y;
                    c.Width = 0;
                    c.Height = 0;
                    c.LeftEyeX = 0;
                    c.LeftEyeY = 0;
                    c.RightEyeX = 0;
                    c.RightEyeY = 0;
                    c.PlayerIndex = playerIndex;

                    trackedSkeletonsCount++;

                    // Give each tracker the upated frame.
                    SkeletonFaceTracker skeletonFaceTracker;
                    if (!scannedIdentities.Contains(skeleton.TrackingId) &&
                        detectedFace < 1 &&
                        trackedSkeletons.TryGetValue(skeleton.TrackingId, out skeletonFaceTracker))
                    {
                        detectedFace++;
                        scannedIdentities.Add(skeleton.TrackingId);

                        skeletonFaceTracker.OnFrameReady(sensor, colorImageFormat, colorImage, depthImageFormat, depthImage, skeleton);
                        skeletonFaceTracker.LastTrackedFrame = skeletonFrame.FrameNumber;
                        Coordinates2D? realCoords = skeletonFaceTracker.GetFaceCoordinates();
                        if (realCoords.HasValue)
                        {
                            c = realCoords.Value;
                            c.PlayerIndex = playerIndex;
                        }
                    }

                    c.TrackingId = skeleton.TrackingId;
                    coordinates.Add(c);
                }
            }

            if (scannedIdentities.Count > 0 && scannedIdentities.Count >= trackedSkeletonsCount)
            {
                scannedIdentities.Clear();
                //Console.WriteLine("Clearing");
            }

            RemoveOldTrackers(skeletonFrame.FrameNumber);

            //if (coordinates.Count > 0)
            {
                int[] identities = new int[coordinates.Count];

              //  stopwatch.Reset();
              //  stopwatch.Start();
                double[] distances = new double[coordinates.Count * 8];
                this.
                 ProcessImage(colorImage, GetWidth(colorImageFormat), GetHeight(colorImageFormat), depthImage, 640, 480, coordinates.ToArray(), identities, distances);
              //  stopwatch.Stop();
             //       foreach (int i in identities)
             //       {
             //           Console.WriteLine("Recognized: {0} (in {1} millis - {2} ticks)", i, stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks);
             //       }
            }
        }
 public Point MapToPoint(SkeletonPoint s, DepthImageFrame depth)
 {
     DepthImagePoint dp = depth.MapFromSkeletonPoint(s);
     ColorImagePoint cp = depth.MapToColorImagePoint(dp.X, dp.Y, ColorImageFormat.RgbResolution640x480Fps30);
     return new Point(cp.X, cp.Y);
 }