processImage method
Future<int>
processImage(
- InputImage inputImage
)
Implementation
Future<int> processImage(InputImage inputImage) async {
final FaceDetector faceDetector = FaceDetector(
options: FaceDetectorOptions(
enableContours: true,
enableClassification: true,
),
);
// bool isBusy = false;
int numberOfFaces = 0;
int? noOfFaces;
// isBusy = true;
final faces = await faceDetector.processImage(inputImage);
if (inputImage.metadata?.size != null &&
inputImage.metadata?.rotation != null) {
// final painter = FaceDetectorPainter(
// faces,
// inputImage.metadata!.size,
// inputImage.metadata!.rotation);
} else {
if (faces.isNotEmpty) {
List<Map<String, int>> faceMaps = [];
for (Face face in faces) {
int x = face.boundingBox.left.toInt();
int y = face.boundingBox.top.toInt();
int w = face.boundingBox.width.toInt();
int h = face.boundingBox.height.toInt();
Map<String, int> thisMap = {'x': x, 'y': y, 'w': w, 'h': h};
faceMaps.add(thisMap);
}
// img.Image? originalImage =
// img.decodeImage(File(imageFile.path).readAsBytesSync());
// if (originalImage != null) {
// if (faceMaps.isNotEmpty) {
// // img.Image faceCrop = img.copyCrop(
// // originalImage,
// // x: faceMaps.first['x']!, y: faceMaps.first['y']!, width: faceMaps.first['w']!, height: faceMaps.first['h']!);
// // faceImage = faceCrop;
// }
// }
}
noOfFaces = faces.length;
numberOfFaces = noOfFaces;
if (kDebugMode) {
print('Number of Faces : $noOfFaces');
}
}
// isBusy = false;
return numberOfFaces;
}