MLKit OCR
提供原生 ML Kit OCR API 的插件
要求
Android
-
在
android/app/build.gradle中设置minSdkVersion 21 -
在
android/build.gradle中设置ext.kotlin_version = '1.6.10' -
应用大小影响:260KB,参考 此处
iOS
- 最低 iOS 部署目标:10.0
- Xcode 12.5.1 或更高版本。
- ML Kit 仅支持 64 位架构(x86_64 和 arm64)。请查看此 列表 以了解您的设备是否具有所需的设备功能。
- 由于 ML Kit 不支持 32 位架构(i386 和 armv7)阅读更多,您需要在 Xcode 中排除 armv7 架构才能构建 iOS
- 应用大小影响:约 20 MB,参考 此处
用法
// Create an Instance of [MlKitOcr]
final ocr = MlKitOcr();
//...
// Pick Image using image picker
//...
// Call `processImage()` and pass params as `InputImage` [check example for more info]
final result = await ocr
.processImage(InputImage.fromFilePath(image.path));
recognitions = '';
// Iterate over TextBlocks
for (var blocks in result.blocks) {
for (var lines in blocks.lines) {
for (var words in lines.elements) {
recognitions += words.text;
}
}
}
此插件基本上是 google_ml_kit 的精简版。由于 google_ml_kit 包含所有 NLP 和 Vision API,应用大小会急剧增加。因此,我创建了这个插件,现在示例应用的 fat apk 是 17MB,分割后的 apks 是 6MB。