微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flutter Firebase ML视觉面部检测器永远无法完成

如何解决Flutter Firebase ML视觉面部检测器永远无法完成

我正在使用Flutter软件包Firebase ML Vision来检测我的应用中的人脸加上轮廓)。大多数情况下,它运行良好。但是,如果给它提供一张光线不足,被头发遮住,戴着帽子,戴着眼镜等遮盖住的次佳脸的照片,那么它将连续处理图像,并且永远无法完成。

我正在寻找可能的解决方案。

我的代码(其中pickedImageFile,其中包含来自设备相机或设备库的图像):

 Future _processImage() async {

   //detector options
   FaceDetectorOptions options = FaceDetectorOptions(
       enableContours: true,enableLandmarks: true,mode: FaceDetectorMode.accurate);

   //vison object
   FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(pickedImage);
   //Face detector object
   FaceDetector faceDetector = FirebaseVision.instance.faceDetector(options);

   List<Face> faces = await faceDetector.processImage(visionImage);

   print('facedector completed');

   }

如果图像质量好,则打印,如果图像完全随机(没有面孔),则打印,但是,如果图像是面孔,但有差异,则从不打印,仅在processImage()上等待。

我的解决方案是向processImage()添加一个超时,如下所示:

Future _processImage() async {

   //detector options
   FaceDetectorOptions options = FaceDetectorOptions(
       enableContours: true,mode: FaceDetectorMode.accurate);

   //vison object
   FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(pickedImage);
   //Face dector object
   FaceDetector faceDetector = FirebaseVision.instance.faceDetector(options);

   try {

     //Get our faces from the image
     List<Face> faces = await faceDetector
         .processImage(visionImage)
         .timeout(Duration(seconds: 30));

     print('facedector completed');

   } on TimeoutException catch (exception) {
     print(exception.message);
     faceDetector.close();
   }
}

但是,此后如果我使用我知道可以使用的图像再次调用_processImage()方法,它将继续进行永久分析,直到关闭并重新启动整个应用程序为止。我不太确定为什么会发生这种情况,但是如果有人知道如何解决此问题或进行任何形式的工作,我将非常感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。