android 相机预览回调正在非常缓慢地绘制覆盖视图

发布于 2024-10-29 08:12:19 字数 284 浏览 3 评论 0原文

我正在使用面部检测器,它会在检测到的面部移动时跟踪它们,使用相机预览回调并在预览显示顶部绘制覆盖视图(在面部周围绘制圆圈)。

这一切都有效,但是当视图发生变化时,它会滞后 2 或 3 秒,绘制的圆圈显示得太晚了。我在 onPreviewFrame 方法中的覆盖视图上调用 invalidate 。

任何想法有什么问题吗? android FaceDetector 的 findFaces 方法真的很慢吗?当我检查系统时间时,似乎最多需要大约 0.5 秒,这比 3 秒要少得多。

任何帮助将不胜感激。谢谢你!

I am using a face detector which follows detected faces as they move, using the Camera preview callback and drawing an overlay view on top of the preview display (where it draws circles around the faces).

It all works, but it lags by 2 or 3 seconds by the time the view has changed, the drawn circles show up too late. I am calling invalidate on the overlay view in the onPreviewFrame method.

Any ideas what is wrong? Is the android FaceDetector's findFaces method just really slow? It seems to take ~about .5 seconds max when I check with system time, which is a lot less than 3 seconds.

Any help would be appreciated. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心凉 2024-11-05 08:12:19

0.5 - 1 秒是 FaceDetector.findFaces 方法检测到面部的时间。

0.5 - 1 sec is the time a face is detected by FaceDetector.findFaces method.

醉态萌生 2024-11-05 08:12:19

FaceDetector 旨在检测任意位图中的人脸。由于您想要在活动相机预览中检测人脸,也许您可​​以尝试使用人脸检测的 Camera.FaceDetectionListener 实现,如下所述:

http://developer.android.com/guide/topics/media/camera.html#face-detection

很可能这种检测人脸的方法针对与活动相机预览帧协同工作进行了优化。

另外,尝试在您的设备上打开原生 Android 相机应用程序,并观察它检测面部的情况。它检测它们的速度是否与应用程序中面部检测的速度相同?如果速度更快,那么您可能可以采取一些措施来使您的应用程序更快。如果不是,那么您的应用程序可能已经与该设备上的速度一样快。

作为参考,我的 Nexus 4 上的库存应用程序中的人脸检测平均时间约为 0.2 秒(每秒 5 次),而我的 Nexus 10 上的速度稍慢一些,可能约为 0.33 秒(每秒 3 次)。

FaceDetector is built to detect faces in arbitrary bitmaps. Since you are wanting to detect faces in an active camera preview perhaps you might try using the Camera.FaceDetectionListener implementation of face detection as described here:

http://developer.android.com/guide/topics/media/camera.html#face-detection

It is likely that this method of detecting faces is optimized for working in concert with an active camera preview frame.

As well, try opening the stock Android camera app on your device and watch as it detects faces. Does it detect them at the same speed as the face detection in your app? If it's faster, then there's likely something you can do to make your app faster. If not, then your app is likely already as fast as it will get on that device.

For reference, face detection in the stock app on my Nexus 4 averages probably about 0.2s (5 per second) and on my Nexus 10 is a bit slower, probably at about 0.33s (3 per second.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文