CIFaceFeature Bounds

泄露秘密 提交于 2019-12-04 18:17:47

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!