Android Flatter Firebase ML视觉面部检测器从未完成
我正在使用Flatter软件包Android Flatter Firebase ML视觉面部检测器从未完成,android,flutter,dart,firebase-machine-learning,Android,Flutter,Dart,Firebase Machine Learning,我正在使用Flatter软件包Firebase ML Vision在我的应用程序中检测人脸(以及轮廓)。大多数情况下,它工作得很好。然而,当给它一张光线不好、头发模糊、戴着帽子、戴着眼镜等的次优面部照片时,它会持续处理图像,而且永远不会完成 我正在寻找一个可能的解决办法 我的代码(其中pickedImage是一个文件,包含来自设备摄像头或设备库的图像): Future\u processImage()异步{ //探测器选项 FaceDetector选项=FaceDetector选项( 使能轮廓:
Firebase ML Vision
在我的应用程序中检测人脸(以及轮廓)。大多数情况下,它工作得很好。然而,当给它一张光线不好、头发模糊、戴着帽子、戴着眼镜等的次优面部照片时,它会持续处理图像,而且永远不会完成
我正在寻找一个可能的解决办法
我的代码(其中pickedImage
是一个文件
,包含来自设备摄像头或设备库的图像):
Future\u processImage()异步{
//探测器选项
FaceDetector选项=FaceDetector选项(
使能轮廓:正确,
使能地标:正确,
模式:FaceDetectorMode。精确);
//维森物体
FirebaseVisionImage visionImage=FirebaseVisionImage.fromFile(pickedImage);
//人脸检测对象
FaceDetector FaceDetector=FirebaseVision.instance.FaceDetector(选项);
列表面=等待面检测器.processImage(visionImage);
打印(“facedector已完成”);
}
如果图像很好,它会打印,如果图像是完全随机的(没有面),它会打印,但是如果图像是面,但有一些差异,那么它不会打印,只是等待processImage()
我的解决方案是向processImage()添加超时,如下所示:
Future _processImage() async {
//detector options
FaceDetectorOptions options = FaceDetectorOptions(
enableContours: true,
enableLandmarks: 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();
}
}
Future\u processImage()异步{
//探测器选项
FaceDetector选项=FaceDetector选项(
使能轮廓:正确,
使能地标:正确,
模式:FaceDetectorMode。精确);
//维森物体
FirebaseVisionImage visionImage=FirebaseVisionImage.fromFile(pickedImage);
//面检测器对象
FaceDetector FaceDetector=FirebaseVision.instance.FaceDetector(选项);
试一试{
//从图像中获取我们的脸
列表面=等待面检测器
.processImage(visionImage)
.超时(持续时间(秒:30));
打印(“facedector已完成”);
}on TimeoutException捕获(异常){
打印(异常消息);
面部检测器。关闭();
}
}
但是,如果我使用我知道可以工作的图像再次调用\u processImage()
方法,它将永远继续分析,直到整个应用程序关闭并重新启动。我真的不知道为什么会发生这种情况,但如果有人知道如何让这项工作或任何类型的工作,我将非常感激
Future _processImage() async {
//detector options
FaceDetectorOptions options = FaceDetectorOptions(
enableContours: true,
enableLandmarks: 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();
}
}