我想把RAW相机数据保存在一个文件中,而不丢失CameraControllers ImageStream中的帧数。
任务。检测相机图像流中的人脸,并裁剪一些面部地标。
目前,我能够通过使用Firebase从CameraController检测ImageStream中的人脸。当我试图处理这些人脸时,当ImageStream不断部署图像时,我失去了很多帧。为了避免这种情况,我想保存原始的YUV402数据,并在录像结束后处理这些数据。如果我只是把记录保存为MP4文件,那就太慢了,因为我必须为我的模型把Imagedata转回YUV数据。我的第一个尝试是将所有的RAW数据保存在一个列表中,但这将在短时间内耗尽内存。另一种方法是将YUV数据保存到一个文件中,并在完成记录后对这些数据进行后处理。我所尝试的方法太慢了,而且会阻碍我的Flutter应用程序中的每一个计算。
Here is my current Code:
首先我启动图像流
controller.startImageStream((image) => processVideoStream(image, cameraDescription));
然后我想把YUV数据写入一个文件,并检测图像中的人脸。
void processVideoStream(CameraImage image, description){
writeRawDataToFile(image);
if (_isDetecting)return;
_isDetecting = true;
ScannerUtils.detect(image, description.sensorOrientation)
.whenComplete(() => _isDetecting = false);
Future<void> writeRawDataToFile(CameraImage image) async{
List<int> data = new List<int>();
int index = 0;
for (Plane p in image.planes){
for(int i= 0; i < p.bytes.lengthInBytes; i++)
data.add(p.bytes[i]);
return _yuvFile.writeAsBytes(data,mode: FileMode.append);