I am developing a custom API application for camera 2, and I notice that the capture format conversion is different on some devices when I use the ImageReader callback.
For example, in Nexus 4 it doesnβt work fine, but in Nexus5X it looks normal, here is the conclusion.
I initialize ImageReader in this form:
mImageReader = ImageReader.newInstance(320, 240, ImageFormat.YUV_420_888,2);
And my callback is the ImageReader callback callback.
mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable( ImageReader reader) { try { mBackgroundHandler.post( new ImageController(reader.acquireNextImage()) ); } catch(Exception e) {
};
And in the case of Nexus 4: I had this error.
D/qdgralloc: gralloc_lock_ycbcr: Invalid format passed: 0x32315659
When I try to write a raw file on both devices, I have different images. Therefore, I understand that the Nexus 5X image is encoded in NV21, and the Nexus 4 is encoded in YV12.
I found the image format specification, and I'm trying to get the format in ImageReader. There are options for YV12 and NV21, but obviously I get the format YUV_420_888 when I try to get the format.
int test=mImageReader.getImageFormat();
So, is there a way to get the camera input format (NV21 or YV12) to distinguish between these types of encoding in the camera class? Perhaps the characteristics of the camera?
Thanks in advance.
Unai. PD: I use OpenGL to display in RGB images, and I use Opencv to convert to YUV_420_888.