Example #1
0
 private static extern bool ProcessImage(NativeEngine engine, byte[] pixelDataGrayscale, int width, int height, Coordinates2D[] faces, int numFaces, int[] identities);
Example #2
0
 private static extern bool ProcessImageWithDistances(NativeEngine engine, byte[] pixelData, int width, int height, Coordinates2D[] faces, int numFaces, int[] identities, int numDistances, double[] distances);
Example #3
0
 public bool ProcessImage(byte[] pixelDataGrayscale, int width, int height,short [] depthMap, int dWidth,int dHeight, Coordinates2D[] faces, int[] identities, double[] distances)
 {
     //if(faces.Length > 0)
     //    Console.WriteLine("Coords: {0},{1},{2},{3}", faces[0].LeftEyeX, faces[0].LeftEyeY, faces[0].RightEyeX, faces[0].RightEyeY);
     return ProcessImageWithDepth(
         _nativeEngine,
         pixelDataGrayscale,
         width,
         height,
         depthMap,
         dWidth,
         dHeight,
         faces,
         faces.Length,
         identities,
         (faces.Length == 0 ? 0 : distances.Length / faces.Length),
         distances);
 }
Example #4
0
 public void ProcessImage(byte[] pixelDataGrayscale, int width, int height, Coordinates2D[] faces, int[] identities, double[] distances)
 {
     //if(faces.Length > 0)
     //    Console.WriteLine("Coords: {0},{1},{2},{3}", faces[0].LeftEyeX, faces[0].LeftEyeY, faces[0].RightEyeX, faces[0].RightEyeY);
     ProcessImageWithDistances(
         _nativeEngine,
         pixelDataGrayscale,
         width,
         height,
         faces,
         faces.Length,
         identities,
         (faces.Length == 0 ? 0 : distances.Length / faces.Length),
         distances);
 }
Example #5
0
 public void ProcessImage(byte[] pixelDataGrayscale,int width, int height, Coordinates2D [] faces, int [] identities)
 {
     ProcessImage(_nativeEngine, pixelDataGrayscale, width, height, faces, faces.Length, identities );
 }
Example #6
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);
             //       }
            }
        }
Example #7
0
 public Coordinates2D? GetFaceCoordinates()
 {
     if (this.trackSucceeded)
     {
         Coordinates2D c = new Coordinates2D();
         c.X = frame.FaceRect.Left;
         c.Y = frame.FaceRect.Top;
         c.Width = frame.FaceRect.Right - frame.FaceRect.Left;
         c.Height = frame.FaceRect.Right - frame.FaceRect.Left;
         EnumIndexableCollection<FeaturePoint, PointF> facePoints = frame.GetProjected3DShape();
         c.LeftEyeX = (int)((facePoints[FeaturePoint.BelowThreeFourthLeftEyelid].X + facePoints[FeaturePoint.AboveOneFourthLeftEyelid].X) / 2);
         c.LeftEyeY = (int)((facePoints[FeaturePoint.BelowThreeFourthLeftEyelid].Y + facePoints[FeaturePoint.AboveOneFourthLeftEyelid].Y) / 2);
         c.RightEyeX = (int)((facePoints[FeaturePoint.BelowThreeFourthRightEyelid].X + facePoints[FeaturePoint.AboveOneFourthRightEyelid].X) / 2);
         c.RightEyeY = (int)((facePoints[FeaturePoint.BelowThreeFourthRightEyelid].Y + facePoints[FeaturePoint.AboveOneFourthRightEyelid].Y) / 2);
         return c;
     }
     return null;
 }