gascom/lib/extensions/face_detection_extension.dart
Abdullah Salah 216efb8a83 first commit
2024-12-25 11:09:55 +03:00

48 lines
1.3 KiB
Dart

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;
}
}
}