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

查看:52
本文介绍了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 ?

推荐答案

假设您所讨论的是在捕获时发送到 ImageReader SurfaceTexture 的帧(如在无处不在的 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. CameraCaptureSession.CaptureCallback onCaptureComplete(...)调用中将 TotalCaptureResult 保存在可访问的位置..

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

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

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

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

长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 或其他方式,那么您会很不幸,因为仅发送像素信息,而不发送中的时间戳图片对象.我不确定您可以发送帧的其他位置,例如 MediaRecorder Allocation ,但我认为不能.

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天全站免登陆