Capture Picture Without Preview Using Camera2 API

Capture picture without preview using camera2 API

You should capture photos in "onConfigured" function but not onImageAvailable.

public void onConfigured(CameraCaptureSession session) {
cameraCaptureSession = session;
createCaptureRequest();
}

In this function "onImageAvailable",you should save images,

Image image = mImageReader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
try {
save(bytes, file);
} catch (IOException e) {
e.printStackTrace();
}
image.close();

"onImageAvailable" function will be invoked after session.capture() .

Capturing image without making preview choppy using Camera 2 API

If the camera device is a LEGACY-level device, this is unfortunately expected.

Even for a LIMITED device, the camera has to support the BURST_CAPTURE capability to guarantee full-resolution capture at a fast rate. All FULL-level or better devices do support BURST_CAPTURE.

However, even on lower-capability devices, you can typically capture uncompressed YUV frames at video recording resolutions smoothly. That means adding in an ImageReader with a YUV_420_888 format to your session configuration, and then processing the Images that come out of that. JPEGs on LEGACY devices are unfortunately always slow, and some LEGACY devices don't have enough CPU power to smoothly produce the YUV data either (because there have to be some conversions under the hood).

For more detail, you can inspect the outputs of StreamConfigurationMap and see what output YUV resolutions run at a minimum frame duration of 1/30s; those should guarantee smooth operation for LIMITED or better devices.



Related Topics



Leave a reply



Submit