微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Core Image Face Detector 无结果

如何解决Core Image Face Detector 无结果

我正在尝试使用 CIDetector

检测图像中的人脸

但是似乎没有任何效果

代码如下:

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)")
        }
    }
}

我已经测试了这些图像:

enter image description here

enter image description here

enter image description here

解决方法

发生这种情况是因为我在模拟器上运行它。它在设备上正常工作。

注意,这也适用于 Vision 框架

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。