Android TFLite 的 Camera X ImageAnalyzer 图像格式

Android Camera X ImageAnalyzer Image Format for TFLite

我正在尝试使用 CameraX api.

分析带有 tflite 模型的相机预览帧

This documentation 描述了使用 ImageAnalyzer 处理传入的帧。目前,帧作为 YUV 传入,我不确定如何将 YUV 图像数据传递给期望输入形状 (BATCHxWIDTHxHEIGHTx3) 的 tflite 模型。在旧的 API 中,您可以指定预览输出格式并将其更改为 rgb,但是此页面特别说明 "CameraX produces images in YUV_420_888 format."

首先,我希望有人找到了一种将 RGB 传递给分析器而不是 YUV 的方法,其次,如果没有,有人可以建议一种将 YUV 图像传递给 TFLite 解释器的方法吗?传入的图像对象是 ImageProxy 类型,它有 3 个平面,Y、U 和 V。

A​​FAIK,ImageAnalysis 用例仅提供 YUV_420_888 格式的图像(您可以看到它定义了 here)。

CameraX 官方文档提供了一种将 YUV 图像转换为 RGB 位图的方法,它位于 this section 的底部。

For sample code that shows how to convert a Media.Image object from YUV_420_888 format to an RGB Bitmap object, see YuvToRgbConverter.kt.