问题
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).
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.
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.
Or instead is ImageReader
just fine and is OpenCV missing something?
I'm using ASUS Zenfone 4 Max, Android 7.1.1.
回答1:
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
来源:https://stackoverflow.com/questions/51006362/why-is-androids-imagereader-class-so-slow