ios - 核心图像人脸检测器无结果
问题描述
我正在尝试使用CIDetector检测图像中的人脸
但是似乎没有任何效果。
这是代码:
if let inputImage = UIImage(named: "taylor-swift") {
let ciImage = CIImage(cgImage: inputImage.cgImage!)
let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options)!
let faces = faceDetector.features(in: ciImage)
if let face = faces.first as? CIFaceFeature {
print("Found face at \(face.bounds)")
if face.hasLeftEyePosition {
print("Found left eye at \(face.leftEyePosition)")
}
if face.hasRightEyePosition {
print("Found right eye at \(face.rightEyePosition)")
}
if face.hasMouthPosition {
print("Found mouth at \(face.mouthPosition)")
}
}
}
我已经测试了这些图像:
解决方案
发生这种情况是因为我在模拟器上运行它。它在设备上正常工作。
请注意,这也适用于Vision框架
推荐阅读
- javascript - 如何在我的反应 js 页面中显示来自 json 数据的 html 代码?
- python - 如何解决django模型中的循环导入?
- openlayers - OpenLayers 计算两个坐标之间的距离给出了错误的答案
- c - 调用堆栈函数序言混乱
- jmeter - Jmeter-如何捕获从请求发送到在数据库中更新的时间?
- php - 检查变量是否不同,回显然后更新变量以重新检查
- java - 构造函数在 JUnit 测试期间为类方法返回 null
- java - Java不返回超类的值,将对象作为json传输时将字段返回为null
- python - 迁移到 heroku postgres db 时出错:为列“id”指定了多个默认值
- javascript - 条纹。TypeError:document.querySelectorAll 不是函数