我遵循了此 README 中的所有说明用于人脸检测,当我尝试访问像 face.leftEyeOpenProbability
、face.rightEyeOpenProbability
或 face.smilingProbability
这样的人脸属性时,它让我很困惑null,虽然检测到了人脸。
我试图通过两种方式解决这个问题,
1. flutter使用旧的firebase_ml_vision插件(不兼容AndroidX)
firebase_ml_vision: ^0.2.1
其中使用了函数 detectInImage()
。
2.使用新的firebase_ml_vision插件(兼容AndroidX)
firebase_ml_vision: ^0.6.0+2
使用函数 processImage()
。
在这两种方法中,属性值为空。
这是使用最新插件检测人脸的片段。
void _getImageAndDetectFace() async {
final imageFile = await ImagePicker.pickImage(source: ImageSource.camera);
final image = FirebaseVisionImage.fromFile(imageFile);
final faceDetector = FirebaseVision.instance.faceDetector(FaceDetectorOptions(
mode: FaceDetectorMode.accurate,
enableLandmarks: true,
));
final faces = await faceDetector.detectInImage(image); //this is not null
setState(() {
if (mounted) {
_imageFile = imageFile;
_faces = faces;
for (Face face in faces) { //face is detected here, but...
print('left eye : ${face.leftEyeOpenProbability}'); //prints null
print('right eye : ${face.rightEyeOpenProbability}'); //prints null
print('smiling : ${face.smilingProbability}'); //prints null
}
}
});
}
请帮我解决这个问题。
最佳答案
我有完全相同的错误。
阅读文档后,我在类FaceDetector
中找到了变量enableClassification
。
此变量的默认值为 False。要使用眼睛和微笑的删除必须启用此变量。
在你的情况下会是这样的:
...
final faceDetector = FirebaseVision.instance.faceDetector(FaceDetectorOptions(
mode: FaceDetectorMode.accurate,
enableLandmarks: true,
enableClassification: true
));
...
希望这对您有所帮助。
关于firebase - Face 对象的属性在 firebase ml vision flutter 中始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55157700/