Android Camera2将TotalCaptureResult与Frame关联 [英] android camera2 associate TotalCaptureResult with 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.
-
在
CameraCaptureSession.CaptureCallback
的onCaptureComplete(...)
调用中将TotalCaptureResult
保存在可访问的位置..
Save the
TotalCaptureResult
somewhere accessible when it is available in yourCameraCaptureSession.CaptureCallback
'sonCaptureComplete(...)
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())
.
- 将时间戳与以下内容进行比较:
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屋!