我用核心图像来检测人脸,也很成功,
但我看不出眼睛是闭着的。:(
我想检测一下脸,看看眼睛是否闭着,
非常感谢你!!
代码:

    func detect(ciimage:CIImage) {
    let imageOptions =  NSDictionary(object: NSNumber(value: 5) as NSNumber, forKey: CIDetectorImageOrientation as NSString)
    let personciImage = ciimage
    let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
    let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy)
    let faces = faceDetector?.features(in: personciImage, options: imageOptions as? [String : AnyObject])

    //success
    if let face = faces?.first as? CIFaceFeature {


        hasFace = true

        // face.leftEyeClosed not work,It always outputs false
        if face.leftEyeClosed {
            lefteyeclosed = true
        }else{
            lefteyeclosed = false
        }

        // face.leftEyeClosed not work
        if face.rightEyeClosed{
            lefteyeclosed = true
        }else{
            lefteyeclosed = false
        }
    } else {
        hasFace = false
    }
}

我修改了以下代码:
    let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
    let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy)
    let faces = faceDetector?.features(in: ciimage, options: [CIDetectorEyeBlink : true, CIDetectorImageOrientation: 5])

最佳答案

leftEyeClosed documentation开始:
对于要检测的闭眼,关键cidetectoreyblink必须在传递给检测器的features(in:options:)方法的字典中显示true值。
因此,您的选择应该是:

let options = [
   CIDetectorAccuracy: CIDetectorAccuracyHigh,
   CIDetectorEyeBlink: true
]
let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options)

07-28 06:39