简体   繁体   English

Android Camera Preview回调非常缓慢地绘制叠加视图

[英]android camera preview callback is drawing overlay view very slowly

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. 一切正常,但是到视图更改时滞后了2或3秒钟,绘制的圆圈显示得太晚了。 I am calling invalidate on the overlay view in the onPreviewFrame method. 我在onPreviewFrame方法中的叠加视图上调用了invalidate。

Any ideas what is wrong? 任何想法有什么问题吗? Is the android FaceDetector's findFaces method just really slow? android FaceDetector的findFaces方法真的很慢吗? It seems to take ~about .5 seconds max when I check with system time, which is a lot less than 3 seconds. 当我检查系统时间时,似乎最多需要约0.5秒,这比3秒要少得多。

Any help would be appreciated. 任何帮助,将不胜感激。 Thank you! 谢谢!

FaceDetector is built to detect faces in arbitrary bitmaps. FaceDetector用于检测任意位图中的面部。 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: 由于要在活动的相机预览中检测面部,因此您可以尝试使用Camera.FaceDetectionListener实现面部检测,如下所述:

http://developer.android.com/guide/topics/media/camera.html#face-detection 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. 同样,请尝试在设备上打开库存的Android相机应用,并观察其检测到的脸部。 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.) 作为参考,我的Nexus 4上的股票应用中的人脸检测平均大约为0.2秒(每秒5次),而我的Nexus 10上的人脸检测则稍慢一些,大约为0.33秒(每秒3次)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM