CIDetector:始终为零边界的CIFaceFeature

时间:2014-12-08 17:09:50

标签: ios swift core-image

我不知道为什么CIFaceFeature总是返回零Rectangle:

import Cocoa
import QuartzCore

let url = NSURL(string:"http://cs620522.vk.me/v620522149/12b59/ijvZ6XJWrw0.jpg");
let ciimg:CIImage = CIImage(contentsOfURL:url);
let cid:CIDetector = CIDetector(ofType:CIDetectorTypeFace, context:nil, options:[CIDetectorAccuracy: CIDetectorAccuracyHigh]);
let results:NSArray = cid.featuresInImage(ciimg, options: NSDictionary());
for r in results {
    let face:CIFaceFeature = r as CIFaceFeature;
    NSLog("Face found at (%f,%f) of dimensions %fx%f", face.bounds.origin.x, face.bounds.origin.y, face.bounds.width, face.bounds.height);
}

enter image description here

根据NSLogs的数量,似乎CIDetector.featuresInImage可以工作。

2 个答案:

答案 0 :(得分:2)

您应该使用println来记录信息。或者您可以使用以下内容,

NSLog("%@ face", face.bounds.origin.x.description)

答案 1 :(得分:0)

可能会给出答案的几个问题:

  • 对CIImage(contentsOfURL:url)的调用是否产生有效图像? 例如,结果图像范围是非空矩形吗?
  • 图片是否有方向元数据?