问题
I am using camera2 api to capture images in a loop. When I capture a image, I get callback in onCaptureCompleted method and there I use TotalCaptureResult to get information about the image like iso, exposure and timestamp. Then I store these information in a map.
After that I get the image in OnImageAvailableListener of ImageReader and I use image's getTimestamp method and ExifInterface to get exif data like iso and exposure.
Surprisingly, the values of iso and exposure is different for the image and capture result at same timestamp.
Is this normal?
Reference Code :
mSession.capture(captureRequest.build(), new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
int capturedISO = result.get(CaptureResult.SENSOR_SENSITIVITY);
long timeStamp = result.get(CaptureResult.SENSOR_TIMESTAMP);
/// Save somewhere to be used later
super.onCaptureCompleted(session, request, result);
}
}, backgroundHandler);
And in OnImageAvailableListener
public void onImageAvailable(ImageReader imageReader) {
if (!isRecording) {
return;
}
Image image = imageReader.acquireLatestImage();
Long timestamp = image.getTimestamp();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
outputStream.write(bytes);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
image.close();
try {
ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
double value = exifInterface.getAttributeDouble(ExifInterface.TAG_ISO_SPEED_RATINGS, 0);
/// Compare the iso with the CaptureCallback's saved one for this timestamp. I got different values.
} catch (Exception e) {
e.printStackTrace();
}
}
回答1:
You need to change the values of BLACK_LEVEL_LOCK field.
Whether black-level compensation is locked to its current values or is free to vary.
When set to true(ON)
, the values used for black-level compensation will not change until the lock is set to false (OFF)
.
Since changes to certain capture parameters (such as exposure time) may require resetting of black level compensation, the camera device must report whether setting the black level lock was successful in the output result metadata.
The camera device will maintain the lock to the extent possible, only overriding the lock to OFF when changes to other request parameters require a black level recalculation or reset.
回答2:
Assuming the device supports the READ_SENSOR_SETTINGS capability, this would be a device-specific bug and not correct. If the device does not support that capability, then the TotalCaptureResult values are likely not correct at all, if they're even present.
Unfortunately there currently isn't a compliance test for verifying this particular combination of metadata values matches for the capture.
来源:https://stackoverflow.com/questions/56977579/android-camera2-compare-image-timestamp-with-captureresult-sensor-timestamp