'Not able to detect face from Image stream in flutter

I am trying to detect face from Image stream with 'google_ml_kit' and 'Camera' pluggin,first i convert the CameraImage to InputImage and pass the InputImage for face detection. but here face is not detected.

I use following fuction to convert CameraImage to InputImage

Future processesImage(CameraImage image) async {
final WriteBuffer allBytes = WriteBuffer();
for (Plane plane in image.planes) {
  allBytes.putUint8List(plane.bytes);
}
final bytes = allBytes.done().buffer.asUint8List();

final Size imageSize =
    Size(image.width.toDouble(), image.height.toDouble());

const InputImageRotation imageRotation = InputImageRotation.Rotation_180deg;

final InputImageFormat inputImageFormat =
    InputImageFormatMethods.fromRawValue(image.format.raw) ??
        InputImageFormat.NV21;

final planeData = image.planes.map(
  (Plane plane) {
    return InputImagePlaneMetadata(
      bytesPerRow: plane.bytesPerRow,
      height: plane.height,
      width: plane.width,
    );
  },
).toList();

final inputImageData = InputImageData(
  size: imageSize,
  imageRotation: imageRotation,
  inputImageFormat: inputImageFormat,
  planeData: planeData,
);

final inputImage =
    InputImage.fromBytes(bytes: bytes, inputImageData: inputImageData);

///detect face and return image only if face found
var data = await detectFace(inputImage);
if (data == true) return image;

}

detectFace() method is

  detectFace(InputImage image) async {
if (isBusy) return;
isBusy = true;
final faces = await faceDetector.processImage(image);
isBusy = false;
if (faces.isNotEmpty) {
  isBusy = false;
  return true;
} else {
  isBusy = false;
  return false;
}

}

When i try to make a InputImage from File with InputImage.file() method for testing it works fine, Face was detected



Solution 1:[1]

change camera controller ResolutionPreset one by one and check

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shivam Singh