# @capacitor-community/image-to-text 中文文档

规范地址：https://npmcn.com/package/%40capacitor-community/image-to-text/

版本：8\.0\.0
npm 元数据更新时间：2026-10-23T21:47:51.124Z
中文译文更新时间：2026-11-09T04:41:41.673Z
软件包许可：Hippocratic License Version 2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40capacitor-community/image-to-text
原文对照：https://npmcn.com/package/%40capacitor-community/image-to-text/?lang=original
项目主页：https://github.com/capacitor-community/image-to-text#readme
源码仓库：https://github.com/capacitor-community/image-to-text

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：220 kB，58 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：@capacitor/core \>=8\.0\.0
- 首次发布：2023-02-24T14:44:51.850Z
- 最新版本发布：2026-01-12T12:46:13.111Z
- 近 30 天下载量：14075（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 1 个）

## 中文简介

图像到 Capacitor 的文本插件

## 安装

```sh
npm install @capacitor-community/image-to-text
```

也可以使用：`pnpm add @capacitor-community/image-to-text`、`yarn add @capacitor-community/image-to-text`、`bun add @capacitor-community/image-to-text`

## README

  
![](https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png)

### 图像到文本

**`@capacitor-community/image-to-text`**

图像用于文本处理的Capacitor插件,使用苹果公司的IOS视野框架和MLKit的Android视野框架.

## 贷项

这个项目是从.. [密码 ML](https://github.com/bendyworks/cap-ml) vennela Kodali所写的插件. 后被重构并被改造为Capacitor 4.

-   对于控制器 4 项目使用 v4.x
-   5个项目使用v5.x
-   对于控制器 6 项目使用 v6.x

## 安装

```
npm install @capacitor-community/image-to-text
```

## 使用量

只有一个方法 `detectText` 它需要图像的文件名,然后返回与之相关的文本.

在您的申请中添加以下内容:

```typescript
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`](https://capacitorjs.com/docs/apis/camera) 拍照并转换为文本的插件 :

```
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { Ocr, TextDetections } from '@capacitor-community/image-to-text';
```

.

```typescript
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);
}
```

可以找到完整的样本应用程序 [这里](https://github.com/dtarnawsky/capacitor-ocr-example)。 。 。 .

![video of scanning a card and it being converted to text](https://user-images.githubusercontent.com/84595830/221210852-2203919a-bb43-46ed-b9bf-04d096425dcb.gif)

## iOS 用户

在 iOS Capacitor 工程中使用此插件不需要额外的设置.

## 机器人用途

你的项目必须包括 `google-services.json` 存储在 Android 项目文件夹中的文件( 通常是) `android/app`) (中文(简体) ).

### 创建 Firebase 工程和 App

-   签名到 [控制台. firebase.google.com (原始内容存档于2017-10-22)](https://console.firebase.google.com/)
-   点击 `Add Project` 并跟随步道.
-   点击 `Android` 图标创建android应用程序.
-   输入 `Package Name` 它必须与您的应用程序软件包名称相匹配( 您可以在 `android/app/AndroidManifest.xml`) (中文(简体) ).
-   点击 `Register App`
-   下载 `google-services.json` 并保存到您的项目 `android/app` 目录.

### 添加防火基地 SDK

示范项目在以下几个方面都有此规定: `build.gradle` (见 [此处作为参考](https://github.com/dtarnawsky/capacitor-ocr-example/blob/09e7fb935f68e642d4906eb0ed002a52d1868b52/android/app/build.gradle#L47)) (中文(简体) ).

注意: 大多数启动的 Capacitor 项目都是预配置以加载 `google-services.json`。 。 。 .

## API 参考

-   [`detectText(...)`](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-detecttext)
-   [接口](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-interfaces)
-   [数字](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-enums)

### 检测文本(...)

```typescript
detectText(options: DetectTextFileOptions | DetectTextBase64Options) => Promise<TextDetections>
```

在图像中检测文本

| 参数 | 类型 | 说明 |
| --- | --- | --- |
| **`options`** | `[DetectTextFileOptions](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-detecttextfileoptions) | [DetectTextBase64Options](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-detecttextbase64options)` | 文本检测选项 |

**回返情况:** `Promise<[TextDetections](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-textdetections)>`

* * *

### 接口

#### 文本检测

| Prop | 类型 |
| --- | --- |
| **`textDetections`** | `TextDetection[]` |

#### 文本检测

| Prop | 类型 |
| --- | --- |
| **`bottomLeft`** | `[number, number]` |
| **`bottomRight`** | `[number, number]` |
| **`topLeft`** | `[number, number]` |
| **`topRight`** | `[number, number]` |
| **`text`** | `string` |

#### 检测文本选项

| Prop | 类型 |
| --- | --- |
| **`filename`** | `string` |
| **`orientation`** | `[ImageOrientation](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-imageorientation)` |

#### 检测TextBase64 选项

| Prop | 类型 |
| --- | --- |
| **`base64`** | `string` |
| **`orientation`** | `[ImageOrientation](https://npmcn.com/package/%40capacitor-community/image-to-text/#readme-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文件

## 常见问题

### @capacitor-community/image-to-text 是什么？

图像到 Capacitor 的文本插件

### 如何安装 @capacitor-community/image-to-text？

在项目目录运行 npm install @capacitor-community/image-to-text，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@capacitor/core（\>=8\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @capacitor-community/image-to-text 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @capacitor-community/image-to-text 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @capacitor-community/image-to-text 可以商用吗？

@capacitor-community/image-to-text 使用 Hippocratic License Version 2\.0 许可。声明的许可为 Hippocratic License Version 2\.0，请阅读许可原文确认使用条件。以上为概括，不构成法律意见，请以许可原文为准。

### @capacitor-community/image-to-text 的下载量有多少？

根据 npm 官方下载统计，@capacitor-community/image-to-text 在 2026/10/09 – 2026/11/07 这 30 天内被下载 14,075 次，日均约 469 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @capacitor-community/image-to-text 还在维护吗？

最新版本 8\.0\.0 发布于 2026/01/12（9 个月前）；至今共发布 11 个版本，其中过去 12 个月发布了 1 个；首次发布于 2023/02/24。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

