【问题标题】:IOS CoreImage Facial Detection at All OrientationsIOS CoreImage 全方位人脸检测
【发布时间】:2017-08-03 21:15:02
【问题描述】:

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

脸确实很大很明显,但是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])

【问题讨论】:

  • 面部检测仅适用于指定的方向,如果您想允许处理任何类型的方向,您可能必须从图像元数据本身读取方向,然后将该方向传递给您的过滤器。

标签: ios core-image


【解决方案1】:

你可以这样做

   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 可以为每个图像获取 UIImageOrientation 吗?甚至是用户上传的?
  • iOS 应该能够确定方向。你可以试试这个代码,看看它是否有效。或者,您可以遍历所有值,直到您能够找到一张脸。
猜你喜欢
  • 2013-07-16
  • 2016-06-02
  • 2016-03-10
  • 2013-04-14
  • 2012-02-25
  • 1970-01-01
  • 2013-03-07
  • 1970-01-01
  • 2019-11-18
相关资源
最近更新 更多