我正在尝试使用firebase_ml_vision从图像读取文本。我得到了图像,但是当我尝试获取文本时,出现了错误:“默认FirebaseApp在此过程com.example.flutter_tfg中未初始化。请确保先调用FirebaseApp.initializeApp(Context)。”
我已将依赖项firebase_ml_vision:^ 0.7.0添加到pubspec.yaml。
我的应用失败的代码是:
File pickedImage;
bool isImageLoaded = false;
Future pickImage() async {
var tempStore = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
pickedImage = tempStore;
isImageLoaded = true;
});
}
Future readText() async {
FirebaseVisionImage ourImage = FirebaseVisionImage.fromFile(pickedImage);
TextRecognizer recognizeText = FirebaseVision.instance.textRecognizer();
VisionText readText = await recognizeText.processImage(ourImage);
for (TextBlock block in readText.blocks) {
for (TextLine line in block.lines) {
for (TextElement word in line.elements) {
print(word.text);
}
}
}
}
我在做什么错了?