import 'package:camerawesome/camerawesome_plugin.dart'; import 'package:google_mlkit_commons/google_mlkit_commons.dart'; extension MLKitUtils on AnalysisImage { InputImage toInputImage() { return when( nv21: (image) { return InputImage.fromBytes( bytes: image.bytes, metadata: InputImageMetadata( rotation: inputImageRotation, format: InputImageFormat.nv21, size: image.size, bytesPerRow: image.planes.first.bytesPerRow, ), ); }, bgra8888: (image) { return InputImage.fromBytes( bytes: image.bytes, metadata: InputImageMetadata( size: size, rotation: inputImageRotation, format: InputImageFormat.nv21, bytesPerRow: image.planes.first.bytesPerRow, ), ); } )!; } InputImageRotation get inputImageRotation => InputImageRotation.values.byName(rotation.name); InputImageFormat get inputImageFormat { switch (format) { case InputAnalysisImageFormat.bgra8888: return InputImageFormat.bgra8888; case InputAnalysisImageFormat.nv21: return InputImageFormat.nv21; default: return InputImageFormat.yuv420; } } }