Reputation: 1
I would like to save RAW Camera data in a file without losing Frames from the CameraControllers ImageStream.
Task: Detecting Faces in a Camera-Imagestream and crop some facial landmarks.
Currently I am able to detect faces in the ImageStream from the CameraController by using Firebase. When I try to process this faces, when the ImageStream keeps deploying Images, I lose a lot of Frames. To avoid that I would like to save the Raw YUV402 data and process these after the recording was finished. If I just save the the recordings as MP4 files, its to slow because I have to cast the Imagedata back to YUV data for my Model. My first attempt was to save all RAW data in a List, but this will blow the RAM in short time. Another way would be to save the YUV data to a file and post-process this data after finished recording.The attempt I was trying is just way to slow and blocks every computation in my Flutter app.
Here is my current Code:
First I start the Image stream
controller.startImageStream((image) => processVideoStream(image, cameraDescription));
Then I want to write the YUV Data to a file and detect the Faces in the Image
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);
}
I believe I will need some kind of Buffer where I can write the data and it gets written to the file in some other Thread, but I wasn't able to do so. Maybe someone already faced such a problem.
Upvotes: 0
Views: 872
Reputation: 1
After some experiments I was able to send the YUV Data to an Isolate. This solved my problem.
Upvotes: 0