ML kit face recognition not working on IOS

1,453

I know this is an old issue, but I was having the same problem and turns out I just forgot to add the pod 'Firebase/MLVisionFaceModel' in the podfile.

Share:
1,453
Léo Moraes
Author by

Léo Moraes

Updated on December 12, 2022

Comments

  • Léo Moraes
    Léo Moraes over 1 year

    I'm working on an app that does facial recognition. One of the steps include detecting the user smile. For that, I am currently using google's Ml Kit. The application works fine on Android platform but when I run on Ios (Iphone Xr and others) it does not recognize any faces on any image. I have already followed every steps on how to integrate Ios and Firebase and it runs fine.

    Here's my code. It's always falling on length == 0, as the image would not contain any faces. The image passed as parameter is coming from the image_picker plugin.

    Future<Face> verifyFace(File thisImage) async {
      var beforeTime = new DateTime.now();
      final image = FirebaseVisionImage.fromFile(thisImage);
      final faceDetector = FirebaseVision.instance.faceDetector(
        FaceDetectorOptions(
          mode: FaceDetectorMode.accurate,
          enableClassification: true,
        ),
      );
    
      var processedImages = await faceDetector.processImage(image);
      print('Processing time: ' +
          DateTime.now().difference(beforeTime).inMilliseconds.toString());
    
      if (processedImages.length == 0) {
        throw new NoFacesDetectedException();
      } else if (processedImages.length == 1) {
        Face face = processedImages.first;
        if(face.smilingProbability == null){
          throw new LipsNotFoundException();
        }
        else {
          return face;
        }
      } else if (processedImages.length > 1) {
        throw new TooManyFacesDetectedException();
      }
    }
    

    If someone has any tips or can tell what I am doing wrong I would be very grateful.

  • Léo Moraes
    Léo Moraes almost 5 years
    I already saw that video, it does the same as I am doing on the code posted. As said, it works on Android but not on IOS. About posting code, I cannot do it because of my company's policy, but everything used to detect faces is on the code above
  • Dong Chen
    Dong Chen almost 5 years
    Have you checked out the iOS QuickStart example for ML Kit Vision APIs (including face detection): github.com/firebase/quickstart-ios/tree/master/mlvision (Please note that ML Kit does not support face recognition; it only supports face detection.)