gpt4 book ai didi

swift - CIDetector 不使用 UIImagePickerController (Swift) 检测人脸

转载 作者:行者123 更新时间:2023-11-28 06:58:12 25 4
gpt4 key购买 nike

我正在尝试用相机拍照,然后检测其中的人脸。但它不起作用... 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)
}

有什么想法吗?谢谢!最近网上关于它的资料不多。

最佳答案

确保您的图像方向和检测器的预期图像方向相同。有关详细信息,请参阅此答案:https://stackoverflow.com/a/17019107/919790

关于swift - CIDetector 不使用 UIImagePickerController (Swift) 检测人脸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32785732/

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