我尝试使用CameraX API分析带有tflite模型的相机预览帧。
This documentation描述了如何使用ImageAnalyzer来处理传入帧。目前帧是以YUV格式传入的,我不知道如何将YUV图像数据传递给一个需要输入形状的tflite模型(BATCHxWIDTHxHEIGHTx3)。在旧的API中,您可以指定预览输出格式并将其更改为rgb,但此页面明确指出“CameraX以YUV_420_888格式生成图像”。
首先,我希望有人找到了一种方法来传递RGB到分析器,而不是YUV,其次,如果没有,有人能建议一种方法来传递YUV图像到TFLite解释器吗?传入的图像对象是ImageProxy类型,它有3个平面,Y,U和V。
2条答案
按热度按时间e0bqpujr1#
AFAIK,
ImageAnalysis
用例仅提供YUV_420_888格式的图像(您可以看到它定义为here)。官方的CameraX文档提供了一种将YUV图像转换为RGB位图的方法,它位于本节的底部。
有关显示如何将Media.Image对象从YUV_420_888格式转换为RGB Bitmap对象的示例代码,请参见YuvToRgbConverter.kt。
cunj1qz12#
ImageAnalysis用例现在提供YUV_420_888以及RGBA_8888格式的图像,TFLite解释器支持这两种格式。
查看官方示例应用了解更多详情:https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/android_play_services/app/src/main/java/org/tensorflow/lite/examples/objectdetection/fragments/CameraFragment.kt