人脸检测功能迅速

时间:2018-11-02 14:44:15

标签: iphone swift face-detection core-image cidetector

我正在尝试像

这样的用户面部检测
  • 脸在微笑
  • 左眼闭上
  • 右眼闭上

许多其他类型 但是我真的很困惑如何检测用户的面部粉刺(黑眼圈)或皱纹。 这是我的代码检测到用户的脸

func detect() {
    guard let personciImage = CIImage(image: personPic.image!) else {
        return
}
    let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
    let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy)
    let faces = faceDetector?.features(in: personciImage)

    // Convert Core Image Coordinate to UIView Coordinate
    let ciImageSize = personciImage.extent.size
    var transform = CGAffineTransform(scaleX: 1, y: -1)
    transform = transform.translatedBy(x: 0, y: -ciImageSize.height)

for face in faces as! [CIFaceFeature] {
        print("Found bounds are\(face.bounds)")

        // Apply the transform to convert the coordinates
        var faceViewBounds = face.bounds.applying(transform)

        // Calculate the actual position and size of the rectangle in the image view
        let viewSize = personPic.bounds.size
        let scale = min(viewSize.width / ciImageSize.width,
                        viewSize.height / ciImageSize.height)
        let offsetX = (viewSize.width - ciImageSize.width * scale) / 2
        let offsetY = (viewSize.height - ciImageSize.height * scale) / 2

     faceViewBounds = faceViewBounds.applying(CGAffineTransform(scaleX: scale, y: scale))
        faceViewBounds.origin.x += offsetX
        faceViewBounds.origin.y += offsetY

        let faceBox = UIView(frame: faceViewBounds)
        faceBox.layer.borderWidth = 3
        faceBox.layer.borderColor = UIColor.red.cgColor
        faceBox.backgroundColor = UIColor.clear
        personPic.addSubview(faceBox)

    // Output
    print("1. hasMouthPosition \(face.hasMouthPosition)")
    print("2. face is smiling \(face.hasSmile)")
    print("3. Left eye bounds are \(face.leftEyePosition)")
    print("4. Right eye bounds are \(face.rightEyePosition)")
    print("5. hasFaceAngle \(face.hasFaceAngle)")
    print("6. hasTrackingFrameCount \(face.hasTrackingFrameCount)")
    print("7. hasTrackingID \(face.hasTrackingID)")
    print("8. leftEyeClosed \(face.leftEyeClosed)")
    print("9. rightEyeClosed \(face.rightEyeClosed)")
   }
}

有没有众所周知的算法?如果有一些快速的sdk能够解释它们或一些实现它们的示例,那就太好了。

有人可以帮我设置人脸检测

请与我分享您的想法。

预先感谢...

0 个答案:

没有答案