我正在试着用相机拍一张照片,然后检测里面的人脸。但它不起作用。results数组返回的计数为零。我已经用互联网上某人的照片测试了这段代码,它返回了1个找到的脸。下面是我的代码:
// MARK: - UIImagePickerControllerDelegate Methods
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
Idea.CurrentIdea.idea.mockups.append(PFFile(data: UIImageJPEGRepresentation(pickedImage, 0.5)!))
//Face Detection
let cid:CIDetector = CIDetector(ofType:CIDetectorTypeFace, context:nil, options:[CIDetectorAccuracy: CIDetectorAccuracyHigh]);
let cii = CIImage(CGImage: pickedImage.CGImage!)
let results:NSArray = cid.featuresInImage(cii)
print(results.count)
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);
}
}
dismissViewControllerAnimated(true, completion: nil)
}有什么想法吗?谢谢!最近网络上关于它的报道并不多。
发布于 2015-09-26 00:13:35
确保您的图像方向与探测器的预期图像方向相同。有关更多详细信息,请参阅此答案:https://stackoverflow.com/a/17019107/919790
https://stackoverflow.com/questions/32785732
复制相似问题