Camera2 ImageReader freezes capture request again

I am trying to capture image data from a camera using camera2 API. I mainly used the code taken from the android Capture2RAW example. Only a few images go through (i.e., onImageAvailable calls) before stopping completely. I tried to capture using RAW_SENSOR and JPEG formats of different sizes with the same results. What am I doing wrong?

this.mImageReader = ImageReader.newInstance(width, height, ImageFormat.RAW_SENSOR, /*maxImages*/ 1);
Surface surface = this.mImageReader.getSurface();
final List<Surface> surfaces = Arrays.asList(surface);
this.mCamera.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
    // Callback methods here
}, null);
CaptureRequest.Builder captureRequestBuilder;
captureRequestBuilder = this.mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureRequestBuilder.addTarget(surface);
this.mCaptureRequest = captureRequestBuilder.build();
this.mCaptureSession.setRepeatingRequest(mCaptureRequest, null, null);
+4
source share
1 answer

Corrected. Images created by ImageReader must be closed, otherwise they will quickly fill up the memory.

@Override
onImageAvailable(ImageReader reader) {
    Image image = reader.acquireLatestImage();
    // Process the image
    image.close();
}
+8
source

Source: https://habr.com/ru/post/1623332/


All Articles