firebase - 如何使用 ML Kit 云文本识别器进行颤振?
问题描述
我在我的项目中使用包“firebase_ml_vision”来进行 OCR。我可以很好地阅读基于拉丁语的语言,但是,我想阅读汉字。我知道文本识别器在设备和基于云的版本上有。但是,我不知道如何在我的应用程序中“启用”基于云的版本。我已经在 Firebase 中激活了基于云的 API,如下图所示:已激活的云 API
我目前使用的代码是:
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 的云文本识别器?
解决方案
有同样的问题,不要认为 cloud-OCR 目前可以与 ML-Package 一起使用。我设法通过 POST 请求使其工作。以下是您需要的一切:发出 Vision API 请求
// 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}");
推荐阅读
- laravel - 将输入值传递给 url 删除方法 laravel
- php - 循环生成一年中的几周并不总是正确的
- node.js - 与 Azure 函数一起使用时,Mongoose .select 不是函数
- javascript - 是否可以创建一个在新选项卡中打开指定网站并关闭当前网站的按钮?
- arrays - 求最大长度子数组条件 2 * min > max
- kubernetes - minikube ip 无法访问
- google-maps - 多个 MarkerClusterer 的渲染顺序
- java - Minecraft Plugin launchProjectiles 问题
- java - 为什么在Java中初始化sybase驱动时会加载Oracle驱动?
- ios - 每次我拨打电话时,JSON api网络调用都没有返回可靠数量的数据(Swift)