CIFaceFeature Bounds [英] CIFaceFeature Bounds

查看:345
本文介绍了CIFaceFeature Bounds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 CIFaceFeature 进行面部检测时,我遇到了边界问题。在试图在识别出的脸部周围放置一个盒子时,框架总是放错地方。 Stack Overflow上的其他问题指出Core Image和UIKit坐标系是倒置的。



CoreImage坐标系



UIKit坐标系



(这些图片来自

解决方案

首先,将除以2除去。通过设置 origin.y image.size.height - face.bounds.origin.y 。你会注意到框架的顶部只是接触下巴。我们需要做的只是考虑脸部的高度:

  image.size.height  -  face.bounds.height  - face.bounds.origin.y 

每次都为您提供完美对齐的帧。



问题仍然存在 - 为什么那些/ 2答案错了?这个坐标问题在2012-2013左右的Stack Overflow上很受欢迎。人们会回答这段代码: image.size.height - face.bounds.origin.y 。正如我们之前讨论的那样,这个框架的顶部触及下巴。沿着这条线的某处,有人建议将整个值除以2.这似乎使得框架在脸上很好地居中。这最终成为很多问题的接受答案。



在我的测试中,我发现这有时会奏效。然而,其他时候,框架将大幅度脱落。做了一点思考后,我找到了正确的答案。希望这可以解决问题并帮助其他有相同问题的人。


While doing face detection work with CIFaceFeature, I ran into an issue with the bounds. While trying to put a box around the recognized face, the frame would always be misplaced. Other questions on Stack Overflow point out that the Core Image and UIKit coordinate systems are inverted.

CoreImage Coordinate System

UIKit Coordinate System

(These images are from https://nacho4d-nacho4d.blogspot.com/2012/03/coreimage-and-uikit-coordinates.html)

Obviously, this coordinate system difference is the reason for the frame misplacement. Now, the x-axis, width, and height remain the same. The only difference is the y. Other answers on Stack Overflow suggest (image height - face y) / 2 as the solution. This generally works, but for some faces, you'll find that it's wildly wrong.

解决方案

First, remove that divide by 2. Set the origin.y by doing image.size.height - face.bounds.origin.y. You'll notice that the top of the frame just touches the chin. All we need to do is account for the height of the face:

image.size.height - face.bounds.height - face.bounds.origin.y

This gives you perfectly aligned frames every time.

The question remains – why are those / 2 answers wrong? This coordinate question was popular on Stack Overflow around 2012-2013. People would answer with this code: image.size.height - face.bounds.origin.y. As we discussed earlier, the top of this frame touches the chin. Somewhere along the line, some suggested dividing the whole value by 2. That seemed to center the frame pretty well on the face. That ended up becoming the accepted answer on quite a few questions.

In my testing, I found that this sometimes worked. Other times, however, the frame would be wildly off. After doing a little thinking, I came upon the right answer. Hopefully, this sets things straight and helps anyone else who has the same issue.

这篇关于CIFaceFeature Bounds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆