Android camera2将图像时间戳与CaptureResult SENSOR_TIMESTAMP进行比较 [英] Android camera2 compare image timestamp with CaptureResult SENSOR_TIMESTAMP

查看:1213
本文介绍了Android camera2将图像时间戳与CaptureResult SENSOR_TIMESTAMP进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用camera2 api循环捕获图像. 捕获图像时,我在onCaptureCompleted方法中获得了回调,并在其中使用TotalCaptureResult获取有关图像的信息,例如iso,曝光和时间戳.然后,我将这些信息存储在地图中.

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.

此后,我在ImageReader的OnImageAvailableListener中获取图像,并使用图像的getTimestamp方法和ExifInterface来获取exif数据,例如iso和Exposure.

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.

令人惊讶的是,在同一时间戳下,图像和捕获结果的iso和曝光值是不同的.

Surprisingly, the values of iso and exposure is different for the image and capture result at same timestamp.

这正常吗?

参考代码:

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);

在OnImageAvailableListener中

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();
    }
}

推荐答案

假定设备支持READ_SENSOR_SETTINGS功能,这将是设备特定的错误,因此不正确.如果设备不支持该功能,则TotalCaptureResult值甚至可能根本不正确.

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.

这篇关于Android camera2将图像时间戳与CaptureResult SENSOR_TIMESTAMP进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆