简体   繁体   English

核心图像人脸检测器无结果

[英]Core Image Face Detector No Result

I am trying to detect faces in an image using CIDetector我正在尝试使用CIDetector检测图像中的人脸

However nothing seems to work.但是似乎没有任何效果。

Here is the code:这是代码:

if let inputImage = UIImage(named: "taylor-swift") {
    let ciImage = CIImage(cgImage: inputImage.cgImage!)

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

    let faces = faceDetector.features(in: ciImage)

    if let face = faces.first as? CIFaceFeature {
        print("Found face at \(face.bounds)")

        if face.hasLeftEyePosition {
            print("Found left eye at \(face.leftEyePosition)")
        }

        if face.hasRightEyePosition {
            print("Found right eye at \(face.rightEyePosition)")
        }

        if face.hasMouthPosition {
            print("Found mouth at \(face.mouthPosition)")
        }
    }
}

I have tested these images:我已经测试了这些图像:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

This happened because I was running it on a simulator.发生这种情况是因为我在模拟器上运行它。 It works correctly on device.它在设备上正常工作。

Note, this also applies to the Vision framework请注意,这也适用于Vision框架

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM