Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera2 ImageReader freezes repeating capture request

I'm trying to capture image data from the camera using the camera2 API. I've mostly used code taken from the android Capture2RAW example. Only a few images come through (i.e. calls to onImageAvailable) before stopping completely. I've tried capturing using the RAW_SENSOR and JPEG formats at 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);
like image 687
brnby Avatar asked Jan 07 '16 20:01

brnby


1 Answers

Fixed it. The Images produced by the ImageReader need to be closed, otherwise they quickly fill up memory.

@Override
onImageAvailable(ImageReader reader) {
    Image image = reader.acquireLatestImage();
    // Process the image
    image.close();
}
like image 119
brnby Avatar answered Oct 13 '22 22:10

brnby