I'm developing an app which has to be able to do motion detection based on androids camera2 API. So i'm working with an ImageReader and the corresponding OnImageAvailableListener. I have two target surfaces for the Frames of the CameraCaptureSession, the UI SurfaceTexture where I show the preview of the camera, and the ImageReaders surface.
I was kind of "forced" to use ImageFormat.YUV_420_88 for the same reason as mentioned in this question:
I'm kind of new to this Format and i need to implement a motion detection.
My idea is to loop through Image.getPlanes()[i].getBuffer() pixel-wise and compare two images based on a certain threshold.
I have two Questions:
Is this a good idea? Is there maybe a better / more efficient way?
Which of the Plane(s) from the Format YUV_420_88 is best suited for such motion detection?
Yes, it is. There is no other way then compare continued frames to detect motion event.
I think it is Planes()[0].
My sample code: