【问题标题】:Swift: CoreImage Face Detection will Detect Every round object as a FaceSwift:CoreImage 人脸检测会将每个圆形物体检测为人脸
【发布时间】:2020-08-31 21:48:16
【问题描述】:

在我的应用程序中,我想对 UIImage 使用人脸检测,所以我使用 CoreImage 内置库(我知道 Vision Library 也是最新的人脸检测库。但它仅支持 ios 11.0 及以上)。该库工作正常,直到我注意到任何具有圆形表面的图像都会被检测为人脸,即使不是。

这是我的代码:

func checkFaceDetection(image: UIImage) -> Bool {
        var isFace = false
        let personciImage = CIImage(image: image)

        let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
        let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy)
        let faces = faceDetector?.features(in: personciImage!)

        if let face = faces?.first as? CIFaceFeature {
            print("Found face at \(face.bounds)")
            if face.hasLeftEyePosition && face.hasRightEyePosition && face.hasMouthPosition && face.hasFaceAngle{
                isFace = true
            }else{
                isFace = false
            }
        }
        return isFace
    }

即使我用左眼、右眼、嘴巴和面部角度过滤该图像,它仍然无法解决我的问题。

【问题讨论】:

  • 任何失败的示例图像?
  • 我真的不知道如何通过图像向您展示,因为这不是错误而是错误,因为如果我的示例图像包含圆形对象或圆形,我上面显示的函数始终返回 true。 只有在找到左眼、右眼、嘴巴和 faceAngle 时才应该返回 true

标签: ios swift4 core-image


【解决方案1】:

您可以改为将 CIDetectorAccuracyHigh 更改为 Low。会更实用

【讨论】:

    【解决方案2】:

    让 imageOptions = NSDictionary(object: NSNumber(value: 5) as NSNumber, forKey: CIDetectorImageOrientation as NSString)

    【讨论】:

    • 您的回答实际上并未提供问题的答案。
    猜你喜欢
    • 2019-11-18
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多