Facial Recognition with Kinect

后端 未结 3 1726
梦如初夏
梦如初夏 2021-02-01 09:47

Lately I have been working on trying facial recognition with the Kinect, using the new Developer Toolkit (v1.5.1). The API for the FaceTracking tools can be found here: http://m

3条回答
  •  时光取名叫无心
    2021-02-01 10:41

    If you use a EnumIndexableCollection so you can use a FaceTrackFrame's GetProjected3DShape() method. You use it like this:

      private byte[] colorImage;
    
      private ColorImageFormat colorImageFormat = ColorImageFormat.Undefined;
    
      private short[] depthImage;
    
      private DepthImageFormat depthImageFormat = DepthImageFormat.Undefined;
    
      KinectSensor Kinect = KinectSensor.KinectSensors[0];
    
      private Skeleton[] skeletonData;
    
      colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame();
      depthImageFrame = allFramesReadyEventArgs.OpenDepthImageFrame();
      skeletonFrame = allFramesReadyEventArgs.OpenSkeletonFrame();
      colorImageFrame.CopyPixelDataTo(this.colorImage);
      depthImageFrame.CopyPixelDataTo(this.depthImage);
      skeletonFrame.CopySkeletonDataTo(this.skeletonData);
      skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
    
      foreach(Skeleton skeletonOfInterest in skeletonData)
      {
           FaceTrackFrame frame = faceTracker.Track(
               colorImageFormat, colorImage, depthImageFormat, depthImage, skeletonOfInterest);
      }
    
      private EnumIndexableCollection facePoints = frame.GetProjected3DShape();
    

    Then you can use each of the points in your image. I would have a const double preferedDistance that you can multiply the current depth and x and y of the different points to find the preferred version of the x and y's and the depth by the formula

    preferredDistance / currentDistance

    Example:

            const double preferredDistance = 500.0;//this can be any number you want.
    
            double currentDistance = //however you are calculating the distance
    
            double whatToMultiply = preferredDistance / currentDistance;
    
            double x1 = this.facePoints[39].X;
            double y1 = this.facePoints[39].Y;
            double x2 = this.facePoints[8].X;
            double y2 = this.facePoints[8].Y;
    
            double result = whatToMultiply * //however you are calculating distance.
    

    Then you can have a List<> of what the distances are to search. I would also suggest that you have a List<> of bool which coorispond to the distances to set to true if the result matches, so you can keep track of which bool is true/false.
    Example:

            List DistanceFromEyeToNose = new List
            {
                1,
                2,
                3 //etc
            };
    
    
            List IsMatch = new List
            {
                false,
                false,
                false //etc
            };
    

    Then search it by using a for loop.

            for (int i = 0; i < DistanceFromEyeToNose.Count; i++)
            {
                if (result == DistanceFromEyeToNose[i]) IsMatch[i] = true;
            } 
    

    Hope this Helps!

提交回复
热议问题