8

I am using camera2 API to capture images with manual exposure and ISO. But sometimes the image captured has different values for ISO and exposure then the one I have specified.

Is there any way I could pass the information of the values that I set in the capture request to the image reader listener where callback comes when image is captured to see if the image is actually having the values that I specified.

I am capturing a lot of images(say a loop) with different values of ISO and exposure for every image.

This is my code to capture images:

imageReader = ImageReader.newInstance(imageWidth, imageHeight, ImageFormat.JPEG, 1);
imageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
        @Override
        public void onImageAvailable(ImageReader imageReader) {
            /// How to check the image is taken with correct values
        }
    }, backgroundHandler);

captureRequest = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureRequest.addTarget(preview);
captureRequest.addTarget(imageReader.getSurface());
captureRequest.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
captureRequest.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_OFF);
captureRequest.set(CaptureRequest.SENSOR_SENSITIVITY, <MANUAL_ISO>);
captureRequest.set(CaptureRequest.SENSOR_EXPOSURE_TIME, <MANUAL_EXPOSURE>);
mSession.capture(captureRequest.build(), null, backgroundHandler);

This works most of the times, like if I am taking 100 photos then around 70 are taken with the values I specify and rest 30 will have different values.

What I tried:

I have tried below approach where, when I capture image, I check the values in onCaptureCompleted and create a queue indicating whether the image is taken with correct values or not. But when I get image in imageReader, I have no idea if the value in queue is for current image or some other image. This happens because I don't know when will imageReader listener be invoked for a image: It can be invoked just after onCaptureCompleted finishes or before it, or in worst case after onCaptureCompleted is invoked 2-3 times for 2-3 images as I am capturing images in loop.

Basically I need a tag to identify images in this approach but I don't know how to do that.

Here is the code for the same:

class CapturedPicture {
    static Queue<Boolean> iso = new LinkedList<>();
} 
mSession.capture(captureRequest.build(), new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                super.onCaptureCompleted(session, request, result);
                int capturedISO = result.get(CaptureResult.SENSOR_SENSITIVITY);
                CapturedPicture.iso.add(<MANUAL_ISO> == capturedISO);
            }
        }, backgroundHandler);

So I need a way to pass information to imageReader listener to indicate if the current image conforms to the settings I specified. Any help is appreciated.

PS: I also tried saving TotalCaptureResult's SENSOR_TIMESTAMP and image.getTimestamp and comparing them but I can confirm sometimes the image with some timestamp doesn't have same parameters as captured from totalCaptureResult.

Shivam Pokhriyal
  • 479
  • 4
  • 14
  • nice question and are you doing something "HDR"? Another question might be, is the image timestamp before or after the camera exposure time? – flankechen May 25 '21 at 06:34

1 Answers1

0

Ideally the captureResult data should match with the corresponding images based on timestamp. If it is not, could you check if your device supports postRawSensitivityBoost or not, you may need to consider setting this as well.

Wasim Ansari
  • 305
  • 1
  • 9