问题
I am using the package 'firebase_ml_vision' in my project to do OCR. I can read Latin based languages just fine, however, I want to read Chinese characters. I know that there are on the device and cloud-based versions of the text recognizer. However, I can't find out how to 'enable' the cloud-based version in my app. I have already activated cloud-based APIs in Firebase as seen in this image: Activated cloud apis
The code that I currently use is:
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);
}
}}
Image I try to read
Results:
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
Can anyone explain to me how to use cloud text recognizer for Flutter?
回答1:
Have the same problem, don't think cloud-OCR currently works with the ML-Package. I managed to make it work via a POST request. Here is everything you need: 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}");
来源:https://stackoverflow.com/questions/55726537/how-to-use-ml-kit-cloud-text-recognizer-for-flutter