Convert flutter CameraImage to File

岁酱吖の 提交于 2019-12-22 18:10:03

问题


Im trying to run face recognition and need a stream of images/files from the camera.
I decided to use Flutters own camera library camera: 0.2.9+1.
The method CameraController.startImageStream(Function(CameraImage) onAvailable) seams promising but I can't figure out how to convert the CameraImage data into something readable for the face recognition.

Have anyone else solved this?


回答1:


CameraImage is normally in YUV 420 format. (Test cameraImage.format.group to confirm.)

This works well with Firebase ML as that's the format that it expects. Useful demo here. However, other recognizers may want other formats (AWS wants a JPEG or PNG, for example).

YUV is tricky to convert as it uses chroma subsampling. Also, for performance, you probably want to be using native code. On Android there's a YUVImage class into which you can pass the planes. It has a method to convert to JPEG. Create a plugin or method channel to pass the plane(s) to a YUVImage, have it save itself to a ByteArrayOutputStream and return the bytes.



来源:https://stackoverflow.com/questions/54312915/convert-flutter-cameraimage-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!