问题描述
我尝试了适用于Android 3.4.1全新的 JavaCamera2View
的OpenCV,但速度太慢(仅显示摄像机视图,速度约为15fps).当我尝试使用较旧的 JavaCameraView
时,它给了我很好的结果(〜30fps,这是我的相机的极限).
I tried OpenCV for Android 3.4.1's brand new JavaCamera2View
but it was too slow(~15fps for just showing camera view). When I tried the older JavaCameraView
instead, it gave me good results(~30fps, which is the limit of my camera).
我想知道Camera2版本这么慢并研究实现的原因.我注释掉了图像的所有处理和渲染(只是让相机绘制到内部的 ImageReader
对象,然后使用 acquireLastImage()
方法读取它)仍然是15fps.但是,当我将目标表面从 ImageReader
对象更改为视图本身时,它突然给了我30 fps.
I wondered the reason why Camera2 version was so slow and looked into the implementation. I commented out all processings and renderings of the image (just letting the camera draw to internal ImageReader
object and then reading it off using acquireLastImage()
method) and it was still 15 fps. However, when I changed the target surface from ImageReader
object to the surface of the view itself, it suddenly gave me 30 fps.
所以问题是,为什么 ImageReader
类这么慢?我的猜测是ImageReader正在使用 glReadPixels()
从使用OpenGL的Surface读取图像,这非常慢,因为它需要将图像从GPU内存传输到CPU内存(或者可能是等待GPU刷新?),但我不能确定,因为 ImageReader
所做的全部隐藏在本机代码中.
So the question is, why is ImageReader
class so slow?My guess is that ImageReader is reading image from Surface, which uses OpenGL, with glReadPixels()
and this is very slow because it requires the image to be transferred from GPU memory to CPU memory (or possibly it is waiting for GPU flush?), but I cannot be sure because what ImageReader
does is all hidden in native code.
还是 ImageReader
很好,并且OpenCV是否缺少某些内容?
Or instead is ImageReader
just fine and is OpenCV missing something?
我正在使用ASUS Zenfone 4 Max,Android 7.1.1.
I'm using ASUS Zenfone 4 Max, Android 7.1.1.
推荐答案
我想这与LEGACY相机HAL有关.我最近也遇到了这个问题,实际上,如果您仅使用 glReadPixel
,则可以获得比ImageReader更好的帧速率.检查以下答案: https://stackoverflow.com/a/51083567/2606068
I guess it's somehow related to LEGACY camera HAL. I recently bumped into this problem too and actually if you just use glReadPixel
you can achieve better frame rate than ImageReader. Check this answer:https://stackoverflow.com/a/51083567/2606068
这篇关于为什么Android的ImageReader类这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!