flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[Firebase Ml Vision] Face detection not working in iOS

Open chethanprabhakar opened this issue 6 years ago • 5 comments

Hello,

We are using firebase_ml_vision in our project to detect a face using the front (selfie) camera. We detect face and then once detected, show an alert dialog with confirmation message '1 face detected'. Once confirrmed navigates to different screens

If for some reason face is not visible alert dialog shows 'no face' and allows user to go back to previous screen to start face detection again.

This is working perfectly in android

But on iOS, the front camera starts and it seems to be taking a pic. But the face is not detected (inspite of face being within the frame) and we get the 'no face' message everytime.

Suggested configuration for iOS as follows has been done..

iOS 
Versions 0.7.0+ use the latest ML Kit for Firebase version which requires a minimum deployment target of 9.0. You can add the line platform :ios, '9.0' in your iOS project Podfile.

You may also need to update your app's deployment target to 9.0 using Xcode. Otherwise, you may see compilation errors.

If you're using one of the on-device APIs, include the corresponding ML Kit library model in your Podfile. Then run pod update in a terminal within the same directory as your Podfile.

pod 'Firebase/MLVisionBarcodeModel'
pod 'Firebase/MLVisionFaceModel'
pod 'Firebase/MLVisionLabelModel'
pod 'Firebase/MLVisionTextModel'

This is a critical issue for us. Please can you suggest a fix?

Thanks Chethan

chethanprabhakar avatar Mar 04 '20 16:03 chethanprabhakar

Hi @chethanprabhakar could you follow the indication provided in the error Versions 0.7.0+ use the latest ML Kit for Firebase version which requires a minimum deployment target of 9.0. You can add the line platform :ios, '9.0' in your iOS project Podfile. if the issue persists please provide your flutter doctor -v , your flutter run --verbose and your pubspec.yaml or if possible a reproducible minimal code sample. Thank you

iapicca avatar Mar 09 '20 14:03 iapicca

I have the same issue. Face detection is very poor on iOS. Everything seems normal, It's just not performing.

Greatcallie avatar May 18 '20 13:05 Greatcallie

Hey @chethanprabhakar. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jul 30 '20 01:07 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@chethanprabhakar if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Aug 10 '20 01:08 google-oss-bot

firebase_ml_vision won't return any faces for me on an actual IPhone or when testing on the simulator IPhone 11. I have the deployment in version in my podfile set to 9.0. Any Ideas? Flutter doctor comes back fine.. here is my code.

import 'dart:io';

import 'package:firebase_ml_vision/firebase_ml_vision.dart'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart';

void main() { runApp(MyApp()); }

class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), home: MyHomePage(title: 'Face Detector Basic'), ); } }

class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title;

@override _MyHomePageState createState() => _MyHomePageState(); }

class _MyHomePageState extends State { int _counter = 0; ImagePicker picker = ImagePicker(); File _image; List _faces; File _imageFile;

void _getImage() async { final imageFile = await ImagePicker().getImage(source: ImageSource.gallery); _image = File(imageFile.path); final options = FaceDetectorOptions( mode: FaceDetectorMode.accurate, enableClassification: true, );

final image = FirebaseVisionImage.fromFile(_image);
final faceDetector = FirebaseVision.instance.faceDetector(options);

final face = await faceDetector.processImage(image);
if (mounted) {
  setState(() {
    _faces = face;
    _imageFile = _image;
    print("length ${face.length}"); //always == 0 not sure why
    faceDetector.close();
  });
}

}

@override Widget build(BuildContext context) {

return Scaffold(
  appBar: AppBar(
   
    title: Text(widget.title),
  ),
  body: (_imageFile == null)
      ? Container(
          color: Colors.blue,
        )
      : ImageAndFaces(
          filePath: _imageFile,
          faces: _faces,
        ),
  floatingActionButton: FloatingActionButton(
    onPressed: () {
      print("pushed");
      _getImage();
    },
    tooltip: 'Increment',
    child: Icon(Icons.add_a_photo),
  ), 
);

} }

class ImageAndFaces extends StatelessWidget { ImageAndFaces({this.filePath, this.faces});

final File filePath; final List faces; @override Widget build(BuildContext context) { return Column( children: [ Flexible( flex: 2, child: Container( constraints: BoxConstraints.expand(), child: Image.file( filePath, fit: BoxFit.cover, ), )), Flexible( flex: 1, child: Container( constraints: BoxConstraints.expand(), child: ListView( children: faces.map((f) => FaceCoordinates(f)).toList(), ), ), ) ], ); } }

class FaceCoordinates extends StatelessWidget { FaceCoordinates(this.face); final Face face;

@override Widget build(BuildContext context) { final pos = face.boundingBox; print("(${pos.top}, ${pos.left}, ${pos.bottom}, ${pos.right})"); return ListTile( title: Text( "(${pos.top}, ${pos.left}, ${pos.bottom}, ${pos.right})", style: TextStyle(color: Colors.black), ), ); } }

qevka avatar Aug 13 '20 06:08 qevka