android camera2 将 TotalCaptureResult 与 Frame 关联 [英] android camera2 associate TotalCaptureResult with Frame

查看:33
本文介绍了android camera2 将 TotalCaptureResult 与 Frame 关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于 Android 的 Camera2 API.由于捕获结果和输出帧是异步产生的,因此可以在实际帧之前获得捕获结果.有没有好的方法可以将生成的帧与相应的捕获结果相关联?

this is regarding Android's Camera2 APIs. Since capture result and output frame are produced asynchronously, one could get capture result much before the actual frame. Is there a good way to associate produced frame with the corresponding capture result ?

推荐答案

假设您正在讨论在捕获时发送到 ImageReaderSurfaceTexture 的帧(如在无处不在的 camera2basic 示例中),诀窍是比较识别图像的唯一时间戳.

Assuming you are talking about a frame that is sent to an ImageReader or SurfaceTexture upon capture (as in the ubiquitous camera2basic example), the trick is to compare unique timestamps identifying the images.

  1. TotalCaptureResult 保存在您的 CameraCaptureSession.CaptureCallbackonCaptureComplete(...) 调用中时可访问的某个位置.

  1. Save the TotalCaptureResult somewhere accessible when it is available in your CameraCaptureSession.CaptureCallback's onCaptureComplete(...) call.

然后,当实际图像可通过您的 ImageReader.OnAvailableListenerSurfaceTexture.OnFrameAvailableListener 获得时,获取图像的时间戳:

Then, when the actual image is available via your ImageReader.OnAvailableListener or SurfaceTexture.OnFrameAvailableListener, get the image's timestamp:

Long imageTimestamp = Long.valueOf(reader.acquireNextImage().getTimestamp());

Long imageTimestamp = Long.valueOf(surfaceTexture.getTimestamp()),分别.

  1. 比较时间戳:imageTimestamp.equals(totalCaptureResult.get(CaptureResult.SENSOR_TIMESTAMP));

注意事项:

  • 时间戳可能不是您设备的实际真实系统时间戳,但它保证唯一且单调递增,因此它可以用作 ID.

  • The timestamp may not be an actual true system timestamp for your device, but it is guaranteed to be unique and monotonically increasing, so it works as an ID.

如果您将图像发送到 SurfaceHolder 或其他东西,那么您很不走运,因为只有像素信息被发送,而不是 中存在的时间戳图像 对象.我不确定您可以发送帧的其他位置,例如 MediaRecorderAllocation,但我认为不是.

If you are sending the image to a SurfaceHolder or something else instead, you're out of luck as only the pixel information gets sent, not the timestamp present in the Image object. I'm not sure about the other places you can send a frame, e.g., MediaRecorder or Allocation, but I think not.

您可能需要在生成每个新的 TotalCaptureResult 时将它们添加到不断增长的集合中,然后将传入图像的时间戳与所有这些进行比较,因为您注意到了异步性质.我会让你想出你认为合适的方法.

You probably need to add each new TotalCaptureResult to a growing set as they are generated, and then compare an incoming image's timestamp against all of these, because of the asynchronous nature you noted. I'll let you figure out how to do that as you see fit.

这篇关于android camera2 将 TotalCaptureResult 与 Frame 关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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