
图像到文本
@capacitor-community/image-to-text
图像用于文本处理的Capacitor插件,使用苹果公司的IOS视野框架和MLKit的Android视野框架.
贷项
这个项目是从.. 密码 ML vennela Kodali所写的插件. 后被重构并被改造为Capacitor 4.
- 对于控制器 4 项目使用 v4.x
- 5个项目使用v5.x
- 对于控制器 6 项目使用 v6.x
安装
npm install @capacitor-community/image-to-text
使用量
只有一个方法 detectText 它需要图像的文件名,然后返回与之相关的文本.
在您的申请中添加以下内容:
import { Ocr, TextDetections } from '@capacitor-community/image-to-text';
...
const data: TextDetections = await Ocr.detectText({ filename: '[get-filename-of-image-jpg]' });
for (let detection of data.textDetections) {
console.log(detection.text);
}
上述代码将转换图像文件并 console.log 中找到的文本.
相机示例
你可以用这个 @capacitor/camera 拍照并转换为文本的插件 :
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { Ocr, TextDetections } from '@capacitor-community/image-to-text';
.
const photo = await Camera.getPhoto({
quality: 90,
allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Camera,
});
const data: TextDetections = await Ocr.detectText({ filename: photo.path });
for (let detection of data.textDetections) {
console.log(detection.text);
}
可以找到完整的样本应用程序 这里。 。 。 .

iOS 用户
在 iOS Capacitor 工程中使用此插件不需要额外的设置.
机器人用途
你的项目必须包括 google-services.json 存储在 Android 项目文件夹中的文件( 通常是) android/app) (中文(简体) ).
创建 Firebase 工程和 App
- 签名到 控制台. firebase.google.com (原始内容存档于2017-10-22)
- 点击
Add Project并跟随步道. - 点击
Android图标创建android应用程序. - 输入
Package Name它必须与您的应用程序软件包名称相匹配( 您可以在android/app/AndroidManifest.xml) (中文(简体) ). - 点击
Register App - 下载
google-services.json并保存到您的项目android/app目录.
添加防火基地 SDK
示范项目在以下几个方面都有此规定: build.gradle (见 此处作为参考) (中文(简体) ).
注意: 大多数启动的 Capacitor 项目都是预配置以加载 google-services.json。 。 。 .
API 参考
检测文本(...)
detectText(options: DetectTextFileOptions | DetectTextBase64Options) => Promise<TextDetections>
在图像中检测文本
| 参数 | 类型 | 说明 |
|---|---|---|
options | DetectTextFileOptions | DetectTextBase64Options | 文本检测选项 |
回返情况: Promise<TextDetections>
接口
文本检测
| Prop | 类型 |
|---|---|
textDetections | TextDetection[] |
文本检测
| Prop | 类型 |
|---|---|
bottomLeft | [number, number] |
bottomRight | [number, number] |
topLeft | [number, number] |
topRight | [number, number] |
text | string |
检测文本选项
| Prop | 类型 |
|---|---|
filename | string |
orientation | ImageOrientation |
检测TextBase64 选项
| Prop | 类型 |
|---|---|
base64 | string |
orientation | ImageOrientation |
数字
图像方向
| 成员 | 数值 |
|---|---|
Up | 'UP' |
Down | 'DOWN' |
Left | 'LEFT' |
Right | 'RIGHT' |
兼容性
图像预计仅采用肖像模式,即文字正对. 它甚至会试图以其他方式处理,但指出它可能导致胡言乱语.
iOS和Android得到支持. 网络不是.
| 特性 | 欧斯 | 机器人 |
|---|---|---|
| ML 框架 | CoreML 愿景 | 火炮基地 MLKit |
| 用静态图像进行文本检测 | 对 | 对 |
| 检测文本行 | 对 | 对 |
| 文本的边界坐标 | 对 | 对 |
| 图像方向 | 是(上,左,右,下) | 是(上,左,右,下) |
| 扭曲文本 | 对 | 无可靠性 |
| 已旋转的文本(%%% 45deg) | 对 | 是(但有声音) |
| 在线 | 对 | 对 |
| SDK/ios 版本 | ios 13.0 或更新 | 目标 API 级别 QQ 16 使用 Gradle QQ 4.1 com.android.tools.build:gradle === 3.2.1 (英语) 编译SdkVersion − 28 |
许可证
Hippocratic许可证版本2.0.
更多信息请参考LICENSE文件