gpt4 book ai didi

IOS CoreImage 全方位人脸检测

转载 作者:可可西里 更新时间:2023-11-01 03:56:33 25 4
gpt4 key购买 nike

我在 IOS 上使用 CoreImage 来检测图像中的人脸。当有多个面孔时它工作正常,但不适用于像这样的简单面孔:

enter image description here

人脸真的很大很明显,但是CoreImage检测不到。我想这可能是因为我的 kCGImagePropertyOrientation

我将其设置为 5,仅仅是因为在线教程就是这样做的。但是,我正在处理的图像是用户上传的,所以我事先不知道脸部的方向。有没有办法尝试所有方向?当图像事先未知时,实现 CoreImage 面部检测的正确方法是什么?

这是我的代码:

var imageOptions = Dictionary<String,Any>()
imageOptions[CIDetectorImageOrientation] = 5
imageOptions[CIDetectorSmile] = true

let image = CIImage(cgImage: imageView.image!.cgImage!)
let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh]

let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy)
let faces = faceDetector?.features(in: image, options: imageOptions as? [String : AnyObject])

最佳答案

你可以这样做

   var imageOrienttion = 0
switch (YourUIImage.imageOrientation) {
case UIImageOrientation.up:
imageOrienttion = 1
break;
case UIImageOrientation.down:
imageOrienttion = 3
break;
case UIImageOrientation.left:
imageOrienttion = 8
break;
case UIImageOrientation.right:
imageOrienttion = 6
break;
case UIImageOrientation.upMirrored:
imageOrienttion = 2
break;
case UIImageOrientation.downMirrored:
imageOrienttion = 4
break;
case UIImageOrientation.leftMirrored:
imageOrienttion = 5
break;
case UIImageOrientation.rightMirrored:
imageOrienttion = 7
break;
}
imageOptions[CIDetectorImageOrientation] = imageOrienttion

关于IOS CoreImage 全方位人脸检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45247591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com