0

I'm using vision framework to detect face landmark and it's working fine but i need to transform the face landmarks like nose, eyes and for that i need to get nose, eyes position in frame coordinate as face landmark is drawing using VNFaceLandmarkRegion2D points.

Please let me know how to convert VNFaceLandmarkRegion2D points to frame coordinate. So i can get the location in view for transformation or suggest any other way to to transform face landmark.

Shubham
  • 570
  • 3
  • 12

2 Answers2

1

This code from Joshua Newnham solves your problem.

 func getTransformedPoints(
                landmark:VNFaceLandmarkRegion2D,
                faceRect:CGRect,
                imageSize:CGSize) -> [CGPoint]{

                // last point is 0.0
                return landmark.normalizedPoints.map({ (np) -> CGPoint in
                    return CGPoint(
                        x: faceRect.origin.x + np.x * faceRect.size.width,
                        y: imageSize.height - (np.y * faceRect.size.height + faceRect.origin.y))
                })
            }
Ozgur Sahin
  • 1,305
  • 16
  • 24
0

As a newbie this is what I could find to get face marks as a CGPoint:

  1. First converted the selected image to CIImage
  2. Used faceDetector on the image
  3. Parsed the image for each face in case it has more than one

Code:

let chosenPicture = CIImage(data: (self.selectedimage.image?.tiffRepresentation)!)
let selectedFace = faceDetector?.features(in: chosenPicture!, options: [CIDetectorSmile:true])
for person in selectedFace as! [CIFaceFeature] {
    let p1LeftEye = person.leftEyePosition
    let p1RightEye = person.rightEyePosition
    let p1Mouth = person.mouthPosition
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Marchal
  • 286
  • 2
  • 16