7

I want to reshape the face coordinate like showing in the video: https://www.dropbox.com/s/vsttylwgt25szha/IMG_6590.TRIM.MOV?dl=0 (Sorry, unfortunetly the video is about 11 MB in size).

I've just capture the face coordinate using iOS Vision API:

// Facial landmarks are GREEN.
fileprivate func drawFeatures(onFaces faces: [VNFaceObservation], onImageWithBounds bounds: CGRect) {
    CATransaction.begin()
    for faceObservation in faces {

        let faceBounds = boundingBox(forRegionOfInterest: faceObservation.boundingBox, withinImageBounds: bounds)

        guard let landmarks = faceObservation.landmarks else {
            continue
        }

        // Iterate through landmarks detected on the current face.
        let landmarkLayer = CAShapeLayer()
        let landmarkPath = CGMutablePath()
        let affineTransform = CGAffineTransform(scaleX: faceBounds.size.width, y: faceBounds.size.height)

        // Treat eyebrows and lines as open-ended regions when drawing paths.
        let openLandmarkRegions: [VNFaceLandmarkRegion2D?] = [
            //landmarks.leftEyebrow,
            //landmarks.rightEyebrow,
            landmarks.faceContour,
            landmarks.noseCrest,
          //  landmarks.medianLine
        ]

        // Draw eyes, lips, and nose as closed regions.
        let closedLandmarkRegions = [
            landmarks.nose
            ].compactMap { $0 } // Filter out missing regions.

        // Draw paths for the open regions.
        for openLandmarkRegion in openLandmarkRegions where openLandmarkRegion != nil {
            landmarkPath.addPoints(in: openLandmarkRegion!,
                                   applying: affineTransform,
                                   closingWhenComplete: false)
        }

        // Draw paths for the closed regions.
        for closedLandmarkRegion in closedLandmarkRegions {
            landmarkPath.addPoints(in: closedLandmarkRegion ,
                                   applying: affineTransform,
                                   closingWhenComplete: true)
        }

        // Format the path's appearance: color, thickness, shadow.
        landmarkLayer.path = landmarkPath
        landmarkLayer.lineWidth = 1
        landmarkLayer.strokeColor = UIColor.green.cgColor

        landmarkLayer.fillColor = nil

        landmarkLayer.shadowOpacity = 1.0
        landmarkLayer.shadowRadius = 1

        // Locate the path in the parent coordinate system.
        landmarkLayer.anchorPoint = .zero
        landmarkLayer.frame = faceBounds
        landmarkLayer.transform = CATransform3DMakeScale(1, -1, 1)

        pathLayer?.addSublayer(landmarkLayer)
    }

    CATransaction.commit()
}

How to step forward from here? Can anyone guide me please?

SandeepM
  • 2,601
  • 1
  • 22
  • 32
  • Check with : https://stackoverflow.com/questions/45298639/ios11-vision-framework-mapping-all-face-landmarks – A J Dec 31 '18 at 11:30
  • I'm at work and don't have access to DropBox. Can you describe the video in words? – Duncan C Dec 31 '18 at 13:29
  • Yes sure. What I need to achieve is to detect all the points of the face (Which I already doing) and then reshape the face to thin or fate as per the user scroll the bar. Any help is appreciate. – SandeepM Jan 01 '19 at 05:44
  • @Sandeep-Systematix did you figure out how to do it? –  May 08 '20 at 14:57

0 Answers0