0

我想使用此代码通过 CIFaceDetector 检测图像中的人脸。

    let Orientation: Int!

    switch ((info[UIImagePickerControllerOriginalImage] as? UIImage)?.imageOrientation)! {
    case UIImageOrientation.up:
        Orientation = 1
    case UIImageOrientation.down:
        Orientation = 3
    case UIImageOrientation.left:
        Orientation = 8
    case UIImageOrientation.right:
        Orientation = 6
    case UIImageOrientation.upMirrored:
        Orientation = 2
    case UIImageOrientation.downMirrored:
        Orientation = 4
    case UIImageOrientation.leftMirrored:
        Orientation = 5
    case UIImageOrientation.rightMirrored:
        Orientation = 7
    }

    let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorImageOrientation: Orientation] as [String : Any]
    let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options)
    let faces = faceDetector?.features(in: personciImage)

但是,这仅适用于横向。我不知道为什么它不适用于所有其他方向。我的意思是方向应该设置正确。我还将 UIImage 转换为 CIImage。

 guard let personciImage = CIImage(image: (info[UIImagePickerControllerOriginalImage] as? UIImage)!) else {
        return
    }

有问题吗?

4

1 回答 1

0

此处CIDetector的配置文档看来,方向键实际上并不是此类的选项。人脸检测类很可能实际上更喜欢您在传递图像之前对其进行旋转。

旋转图像相当简单,也可以在 SO 上搜索,我找到了一个简单的示例,但我相信还有更多!快速旋转搜索示例

于 2016-10-02T10:09:44.893 回答