我已经在下面的链接中创建了Xcode项目,以便探索Apple使用Xcode9发布的新Vision Framework。它基于我在GitHub和Youtube上找到的代码进行的调整,但我无法理解为什么VNImageRequestHandler上的orientation参数的CGImagePropertyOrientation.right。有人可以阐明这一点吗?为什么脸部检测只能使用CGImagePropertyOrientation.right?
0
A
回答
0
我已经找到了答案,以我自己的问题去府通苹果对UIImage.imageOrientation和CGImagePropertyOrientation文档。在此处张贴以防其他人遇到相同问题: 底线是这两个属性与图像方向有关,但它们具有不同的实际值,分配给它们的枚举。例如,一个UIImage.imageOrientation.up将映射到值0,而一个CGImagePropertyOrientation.up将映射到1.我解决它的方式是构建这个自定义的“翻译”函数,该函数返回从UIImage.imageOrientation输入映射到相应CGImagePropertyOrientation值:
func getCGOrientationFromUIImage(_ image: UIImage) -> CGImagePropertyOrientation {
// returns que equivalent CGImagePropertyOrientation given an UIImage.
// This is required because UIImage.imageOrientation values don't match to CGImagePropertyOrientation values
switch image.imageOrientation {
case .down:
return .down
case .left:
return .left
case .right:
return .right
case .up:
return .up
case .downMirrored:
return .downMirrored
case .leftMirrored:
return .leftMirrored
case .rightMirrored:
return .rightMirrored
case .upMirrored:
return .upMirrored
}
}
更新GitHub的样品。无论使用何种方向拍摄照片,现在都可以识别人脸。
此致敬礼。
1
人脸检测需要知道人脸所需的方向,这通常与图像的预期显示方向相匹配。 (也就是说,大多数人在大多数情况下会在脸部正面朝上的地方拍照)。大多数人脸检测软件(包括Vision)都经过优化,可以查找正面朝上的脸,因为它更容易获得当你正在寻找任何方向的面孔时误报。
Vision的脸部检测功能更喜欢您指定方向。 AFAICT如果您没有指定一个,则它们使用默认的.up
方向。如果只有.right
为指定方向时才具有可正确识别的图像,则这些图像可能具有EXIF元数据,表明其首选显示方向不一定与它们捕捉的本机传感器方向相同。
如果您的图片开始从存储/ URL加载UIImage
,你可以问图像预期显示方向是什么UIImageOrientation
,并且将其转换成CGImagePropertyOrientation
传递到视力的方法。在苹果的Vision sample code中有这样做的方法。
相关问题
- 1. 为什么OpenCV人脸检测识别脸部未受过训练的脸部?
- 2. UIImage脸部检测
- 3. VNDetectFaceRectanglesRequest检测脸部
- 4. 在OpenCV中检测脸部并保存检测到的脸部
- 5. 如何使用jviolajones库检测脸部?
- 6. OpenCV只能检测脸部的左侧轮廓?
- 7. 使用基于CNN的人脸检测器检测脸部图案
- 8. Android - 脸部特征检测
- 9. 旋转脸部检测
- 10. 使用Java中的openCV检测脸部内的笑脸
- 11. 为什么nth-type检测只能在Firefox中失败?
- 12. 为什么SKSpriteNodes只能部分渲染?
- 13. Google脸部检测在转换为图像并尝试检测脸部时崩溃
- 14. 如何检测Android中的脸部和笑脸和脸部匹配?
- 15. 为什么clearInterval只能使用一次?
- 16. 为什么evaluateJavaScript只能使用一次?
- 17. 脸部和身体检测API
- 18. 检测视频文件中的脸部
- 19. 在ROI中检测脸部中心
- 20. 如何检查安卓人脸检测中的人脸检测
- 21. 头部检测不是我的应用程序的脸部检测
- 22. 使用猪特征的人脸检测
- 23. 使用Kinect进行人脸检测
- 24. 使用Affectiva检测真人脸
- 25. 人脸检测算法使用Emgu CV
- 26. 多人脸检测
- 27. opencv人脸检测
- 28. 在你的程序中使用脸部检测
- 29. 我们如何使用OpenCV检测脸部
- 30. 如何使用iphone SDK检测动物脸部?
这不起作用,因为您正尝试使用Int(来自imageOrientation),您希望提供一个UInt32(CGImagePropertyOrientation)。编译器在这种情况下会引发错误。 –
Apple的示例代码具有允许进行相同转换的扩展名。 https://developer.apple.com/documentation/vision/classifying_images_with_vision_and_core_ml –
'扩展UIImageOrientation {VAR cgImagePropertyOrientation:CGImagePropertyOrientation { 开关自{ 情况下.down: 回报.down 情况。左: 回报。左 情况.right: 返回.right 情况.UP: 返回.UP 情况.downMirrored: 返回.downMirrored 情况.leftMirrored: 返回.leftMirrored 情况.rightMirrored: 返回.rightMirrored 的情况。upMirrored: 返回.upMirrored } } }' –