3

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.

Community
  • 1
  • 1
eivour
  • 1,678
  • 12
  • 20
  • Because I only want it run in my own android cellphone and I will want fine control over camera device in the future, I don't want to fall back on `JavaCameraView`. – eivour Jun 24 '18 at 01:59
  • Please read https://github.com/opencv/opencv/issues/11261. TL;NR: this may be due to frame size, color conversion, or limited camera2 support on your device. – Alex Cohn Jun 24 '18 at 14:44
  • I don't think it is frame size or camera2 support problem because when I draw directly to a surface, or when I draw to OpenGL texture, I get good performance. I also commented out YUV420 to ARGB conversion and it is still the same. – eivour Jun 24 '18 at 22:58

1 Answers1

0

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

rmtheis
  • 5,992
  • 12
  • 61
  • 78
wdanxna
  • 10,699
  • 2
  • 23
  • 24