CIFaceFeature Bounds

编程入门 行业动态 更新时间:2024-10-23 15:26:57
本文介绍了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 nacho4d-nacho4d.blogspot/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

本文发布于:2023-10-27 22:59:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534792.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CIFaceFeature   Bounds

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!