我在我的项目中使用软件包“ firebase_ml_vision”进行OCR。我可以阅读基于拉丁语的语言,但是我想阅读汉字。我知道在设备和基于云的文本识别器版本上都有。但是,我找不到如何在应用程序中“启用”基于云的版本。我已经在Firebase中激活了基于云的API,如下图所示: Activated cloud apis
我当前使用的代码是:
void _initializeVision() async{
final File imageFile = File(imagePath);
final FirebaseVisionImage visionImage = FirebaseVisionImage.fromFile(imageFile);
final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
final VisionText visionText = await textRecognizer.processImage(visionImage);
for(TextBlock blocks in visionText.blocks){
for(TextLine line in blocks.lines){
print(line.text);
}
}}
结果:
I/flutter (10432): FamilyMart Collection
I/flutter (10432): 10
I/flutter (10432): Pocket facial tissue
I/flutter (10432): Without fluorescent virgin fber from wood puip
I/flutter (10432): pampers your skin
有人可以向我解释如何为Flutter使用云文本识别器吗?
答案 0 :(得分:0)
具有相同的问题,不要认为cloud-OCR当前可以与ML-Package一起使用。我设法通过POST请求使其工作。 这是您需要的一切:Make Vision API request
// Upload Image to Firebase and get
// 1. DownloadUrl or
// 2. StorageBucket or
//
// 3. Convert Image to base64 with
// String base64Image = base64Encode(File(imagePath).readAsBytesSync());
// (does not work for me, if you use this way make sure your `body` is correct)
String body = """{
'requests': [
{
'image': {
'source': {
'imageUri': '$downloadUrl'
}
},
'features': [
{
'type': 'DOCUMENT_TEXT_DETECTION'
}
]
}
]
}""";
http.Response res = await http
.post(
"https://vision.googleapis.com/v1/images:annotate?key=$API_KEY",
body: body
);
print("${res.body}");