ms-vite-plugin 1.4.15 → 1.4.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +707 -9
- package/dist/mcp/doc-tools.d.ts +0 -8
- package/dist/mcp/doc-tools.js +17 -188
- package/dist/mcp/docs-service.d.ts +1 -50
- package/dist/mcp/docs-service.js +0 -105
- package/dist/mcp/httpapi-docs-service.d.ts +8 -32
- package/dist/mcp/httpapi-docs-service.js +8 -89
- package/dist/mcp/httpapi-tools.d.ts +1 -1
- package/dist/mcp/httpapi-tools.js +7 -155
- package/dist/mcp/image-tools.d.ts +69 -0
- package/dist/mcp/image-tools.js +163 -0
- package/dist/mcp/ocr-tools.d.ts +50 -0
- package/dist/mcp/ocr-tools.js +59 -48
- package/dist/mcp/runtime-tools.js +12 -4
- package/dist/mcp/tool-utils.d.ts +0 -12
- package/dist/mcp/tool-utils.js +0 -15
- package/dist/mcp/tools.js +0 -1
- package/dist/mcp/types.d.ts +0 -13
- package/dist/project.d.ts +3 -2
- package/dist/project.js +8 -2
- package/docs/AGENTS.md +54 -52
- package/docs/SKILL.md +52 -45
- package/docs/api/paddleocr.md +11 -33
- package/docs/apicn/paddleocr.md +5 -29
- package/docs/apipython/paddleocr.md +34 -55
- package/docs/mcp-agent-description.md +58 -73
- package/package.json +1 -1
package/docs/SKILL.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: kuaijs-mcp
|
|
3
|
-
description: 快点JS专用开发助手。用于快点JS
|
|
3
|
+
description: 快点JS专用开发助手。用于快点JS项目开发、本地 API 文档读取、iOS 设备自动化、HTTP API 调用、截图、节点 XML、日志查看、OCR、项目运行和打包;MCP 工具和项目自带 ms CLI 都可以使用,但必须依据快点JS文档与项目结构,不臆造 API 或运行机制。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# 快点JS开发技能
|
|
7
7
|
|
|
8
8
|
## 使用场景
|
|
9
9
|
|
|
10
|
-
当任务涉及快点JS项目开发、快点JS API
|
|
10
|
+
当任务涉及快点JS项目开发、快点JS API、iOS 设备自动化、HTTP API 调用、截图、节点 XML、日志、OCR、项目运行或打包时,使用本技能。
|
|
11
11
|
|
|
12
12
|
你是快点JS专用开发助手,只服务于快点JS这一特定执行环境。必须严格依据快点JS官方 API 文档、当前项目结构、当前 MCP 工具能力和项目自带命令能力回答问题与编写代码。
|
|
13
13
|
|
|
@@ -27,28 +27,36 @@ MCP 工具和项目命令都可以使用。
|
|
|
27
27
|
|
|
28
28
|
优先使用 MCP 的情况:
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
30
|
+
- 获取快点JS本地文档路径。
|
|
31
|
+
- 读取文档后通过 `http_api_call` 调用已确认的 HTTP API。
|
|
32
|
+
- 设置设备、设置工作区、运行项目、截图、抓节点树、读日志、OCR。
|
|
33
33
|
|
|
34
34
|
可以使用命令的情况:
|
|
35
35
|
|
|
36
|
-
- MCP transport 断开或不可用。
|
|
37
36
|
- 用户明确要求使用命令。
|
|
38
37
|
- 需要快速验证项目本地 `ms` CLI 能力。
|
|
39
|
-
- 使用项目自带 KuaiJS CLI
|
|
38
|
+
- 使用项目自带 KuaiJS CLI 获取文档路径、调用已确认的 HTTP API、同步、运行、停止、截图、抓节点、查日志、OCR 和图片处理。
|
|
40
39
|
|
|
41
40
|
允许的常用命令示例:
|
|
42
41
|
|
|
43
42
|
```bash
|
|
44
43
|
npx ms --help
|
|
44
|
+
npx ms docs paths
|
|
45
|
+
npx ms http-call -i <device-ip> --port <port> --method GET --path <path>
|
|
45
46
|
npx ms run -i <device-ip> --port <port>
|
|
46
47
|
npx ms run-ui -i <device-ip> --port <port>
|
|
47
48
|
npx ms screenshot -i <device-ip> --port <port> --format file --output <path>
|
|
49
|
+
npx ms source -i <device-ip> --port <port> --mode 1 --output <path>
|
|
50
|
+
npx ms logs -i <device-ip> --port <port> --limit 200
|
|
51
|
+
npx ms ocr -i <device-ip> --port <port> --engine appleocr --mode recognize
|
|
52
|
+
npx ms screen-crop -i <device-ip> --port <port> --x <x> --y <y> --width <w> --height <h> --output <path>
|
|
53
|
+
npx ms screen-pick-color -i <device-ip> --port <port> --x <x> --y <y>
|
|
54
|
+
npx ms image-crop --image <path> --x <x> --y <y> --width <w> --height <h> --output <path>
|
|
55
|
+
npx ms image-transparent --image <path> --output <path>
|
|
48
56
|
npx ms stop -i <device-ip> --port <port>
|
|
49
57
|
```
|
|
50
58
|
|
|
51
|
-
使用 `
|
|
59
|
+
使用 `ms http-call` 调用设备 HTTP API 前,必须先直接读取本地 HTTP API 文档,确认接口存在、方法、路径、参数位置和返回结构。
|
|
52
60
|
|
|
53
61
|
## 目录职责
|
|
54
62
|
|
|
@@ -72,59 +80,64 @@ npx ms stop -i <device-ip> --port <port>
|
|
|
72
80
|
|
|
73
81
|
## 文档工作流
|
|
74
82
|
|
|
75
|
-
回答快点JS API
|
|
83
|
+
回答快点JS API 或编写脚本前,先确认语言并直接读取对应语言文档。文档随 `ms-vite-plugin` npm 包发布,路径一定存在,不需要额外的文档查询或读取 API。
|
|
76
84
|
|
|
77
|
-
MCP
|
|
85
|
+
MCP 入口:
|
|
78
86
|
|
|
79
|
-
1. 使用 `
|
|
80
|
-
2.
|
|
81
|
-
3.
|
|
82
|
-
4. 只依据已确认的文档内容回答或编写代码。
|
|
87
|
+
1. 使用 `get_docs_paths` 获取本地文档根目录、语言 API 文档目录和 HTTP API 文档路径。
|
|
88
|
+
2. 直接读取对应 markdown 文件。
|
|
89
|
+
3. 只依据已读取的本地文档内容回答或编写代码。
|
|
83
90
|
|
|
84
|
-
|
|
91
|
+
CLI 入口:
|
|
85
92
|
|
|
86
|
-
1.
|
|
87
|
-
2.
|
|
88
|
-
3.
|
|
93
|
+
1. 使用 `npx ms docs paths` 获取同一组本地文档路径。
|
|
94
|
+
2. 直接读取对应 markdown 文件。
|
|
95
|
+
3. 只使用文档中已经确认的 API。
|
|
89
96
|
|
|
90
97
|
## HTTP API 工作流
|
|
91
98
|
|
|
92
|
-
调用设备 HTTP API
|
|
99
|
+
调用设备 HTTP API 前,必须直接读取 HTTP API 文档。
|
|
93
100
|
|
|
94
|
-
MCP
|
|
101
|
+
MCP 入口:
|
|
95
102
|
|
|
96
|
-
1. 使用 `
|
|
97
|
-
2.
|
|
98
|
-
3.
|
|
99
|
-
4. 使用 `http_api_call` 调用接口,并传入文档返回的 `docSlug`。
|
|
103
|
+
1. 使用 `get_docs_paths` 获取 HTTP API 文档路径。
|
|
104
|
+
2. 直接读取 HTTP API markdown,确认 `method`、`path`、参数位置、参数类型和返回结构。
|
|
105
|
+
3. 使用 `http_api_call` 调用接口,只传 `method`、`path`、`query` 或 `body`。
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
CLI 入口:
|
|
102
108
|
|
|
103
|
-
1.
|
|
104
|
-
2.
|
|
105
|
-
3.
|
|
109
|
+
1. 使用 `npx ms docs paths` 获取 HTTP API 文档路径。
|
|
110
|
+
2. 直接读取 HTTP API markdown,确认接口存在和参数要求。
|
|
111
|
+
3. 使用 `npx ms http-call -i <device-ip> --port <port> --method <method> --path <path>` 调用明确存在的接口。
|
|
112
|
+
4. 不要把未确认的路径当成可用接口。
|
|
106
113
|
|
|
107
114
|
## 设备工作流
|
|
108
115
|
|
|
109
116
|
设备相关操作以用户指定的设备为准。不要假设设备已经设置;用户给出新设备时必须使用新设备。
|
|
110
117
|
|
|
111
|
-
MCP
|
|
118
|
+
MCP 入口:
|
|
112
119
|
|
|
113
120
|
1. 使用 `get_device` 查看当前默认设备。
|
|
114
121
|
2. 如果未设置设备,使用 `set_device` 设置设备 IP 和端口。
|
|
115
122
|
3. 使用 `get_logs` 获取当前日志最新行。
|
|
116
123
|
|
|
117
|
-
|
|
124
|
+
CLI 入口:
|
|
118
125
|
|
|
119
126
|
- 用 `npx ms run -i <device-ip> --port <port>` 运行脚本。
|
|
120
127
|
- 用 `npx ms screenshot -i <device-ip> --port <port> --format file --output <path>` 截图验证。
|
|
128
|
+
- 用 `npx ms source -i <device-ip> --port <port> --mode 1 --output <path>` 获取节点 XML。
|
|
129
|
+
- 用 `npx ms logs -i <device-ip> --port <port> --limit 200` 查看当前日志。
|
|
130
|
+
- 用 `npx ms ocr -i <device-ip> --port <port> --engine appleocr --mode recognize` 执行 OCR。
|
|
131
|
+
- 用 `npx ms screen-crop` 或 `npx ms image-crop` 裁切找图模板。
|
|
132
|
+
- 用 `npx ms screen-pick-color` 或 `npx ms image-pick-color` 获取颜色。
|
|
133
|
+
- 用 `npx ms image-transparent` 制作透明找图模板。
|
|
121
134
|
- 用 `npx ms stop -i <device-ip> --port <port>` 停止项目。
|
|
122
135
|
|
|
123
136
|
UI 预览发起后不需要长时间等待结果,可以用截图查看当前界面效果。
|
|
124
137
|
|
|
125
138
|
## 项目运行工作流
|
|
126
139
|
|
|
127
|
-
MCP
|
|
140
|
+
MCP 入口:
|
|
128
141
|
|
|
129
142
|
1. 使用 `set_workspace` 设置快点JS项目根目录。
|
|
130
143
|
2. 使用 `get_workspace` 确认当前工作区。
|
|
@@ -133,25 +146,19 @@ MCP 可用时:
|
|
|
133
146
|
5. 使用 `stop_project` 停止当前设备上的项目。
|
|
134
147
|
6. 使用 `package_project` 执行生产打包。
|
|
135
148
|
|
|
136
|
-
|
|
149
|
+
CLI 入口:
|
|
137
150
|
|
|
138
|
-
1.
|
|
151
|
+
1. 使用 `npx ms --help` 确认 CLI。
|
|
139
152
|
2. 使用 `npx ms run -i <device-ip> --port <port>` 同步并运行。
|
|
140
153
|
3. 使用 `npx ms screenshot ...` 验证界面。
|
|
141
154
|
|
|
142
|
-
|
|
155
|
+
`build`、`package`、`run`、`run-ui` 需要在快点JS项目根目录运行,项目根目录必须包含 `package.json` 和 `scripts/`。文档路径、HTTP API 调用、截图、节点、日志、OCR、图片处理、停止和 WS 状态命令可以在任意目录使用。
|
|
143
156
|
|
|
144
157
|
## 工具分组
|
|
145
158
|
|
|
146
159
|
### 文档
|
|
147
160
|
|
|
148
|
-
- `
|
|
149
|
-
- `get_docs_language`
|
|
150
|
-
- `list_api_docs`
|
|
151
|
-
- `search_api_docs`
|
|
152
|
-
- `read_api_doc`
|
|
153
|
-
- `search_http_api_docs`
|
|
154
|
-
- `read_http_api_doc`
|
|
161
|
+
- `get_docs_paths`
|
|
155
162
|
|
|
156
163
|
### 工作区与运行
|
|
157
164
|
|
|
@@ -180,9 +187,9 @@ MCP 可用时:
|
|
|
180
187
|
|
|
181
188
|
- `http_api_call`
|
|
182
189
|
|
|
183
|
-
控制、HID、IME、镜像、配置、当前应用、运行脚本等普通设备 HTTP API 通过 `
|
|
190
|
+
控制、HID、IME、镜像、配置、当前应用、运行脚本等普通设备 HTTP API 通过 `get_docs_paths` 和 `http_api_call` 使用;CLI 入口使用 `ms docs paths` 和 `ms http-call`。
|
|
184
191
|
|
|
185
|
-
|
|
192
|
+
使用 `ocr_recognize` 执行 OCR 识别。`ocr_recognize` 支持 `appleocr` 和 `paddleocr`,默认 `appleocr`,识别结果坐标可直接用于点击。
|
|
186
193
|
|
|
187
194
|
图片与识别工作流:
|
|
188
195
|
|
|
@@ -194,7 +201,7 @@ OCR 没有独立 HTTP 接口,使用 `ocr_recognize` 通过 `POST /api/runScrip
|
|
|
194
201
|
|
|
195
202
|
## 禁止事项
|
|
196
203
|
|
|
197
|
-
-
|
|
204
|
+
- 不要在没有读取本地文档的情况下回答 API 用法或编写 API 调用代码。
|
|
198
205
|
- 不要调用 HTTP API 文档中未声明的接口。
|
|
199
206
|
- 不要把完整 URL 传给 `http_api_call.path`。
|
|
200
207
|
- 不要用未确认的通用命令替代 KuaiJS MCP 或项目自带 `ms` CLI。
|
|
@@ -203,4 +210,4 @@ OCR 没有独立 HTTP 接口,使用 `ocr_recognize` 通过 `POST /api/runScrip
|
|
|
203
210
|
|
|
204
211
|
## 文档入口
|
|
205
212
|
|
|
206
|
-
|
|
213
|
+
优先直接读取项目本地 `node_modules/ms-vite-plugin/docs/` 文档;也可以使用 MCP `get_docs_paths` 或 `ms docs paths` 获取具体文档路径。
|
package/docs/api/paddleocr.md
CHANGED
|
@@ -4,11 +4,11 @@ PaddleOCR 模块基于百度飞桨 PaddleOCR 技术,提供强大的光学字
|
|
|
4
4
|
|
|
5
5
|
## 功能概览
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- **自动加载**: 识别和查找方法会自动加载所需模型,无需先手动加载
|
|
8
8
|
- **多源识别**: 支持屏幕截图、图片文件、URL 等多种输入源
|
|
9
9
|
- **区域识别**: 支持指定区域的精确文字识别
|
|
10
10
|
- **结构化结果**: 提供详细的文本位置、置信度和方向信息
|
|
11
|
-
-
|
|
11
|
+
- **资源释放**: 可在需要时释放 OCR 资源
|
|
12
12
|
|
|
13
13
|
## 数据类型
|
|
14
14
|
|
|
@@ -61,7 +61,9 @@ interface OCRResult {
|
|
|
61
61
|
|
|
62
62
|
### 模型管理
|
|
63
63
|
|
|
64
|
-
#### loadV5 -
|
|
64
|
+
#### loadV5 - 可选预加载 PP-OCRv5 模型。
|
|
65
|
+
|
|
66
|
+
识别和查找方法会自动加载所需模型,通常不需要先调用 `loadV5`。只有需要提前加载或指定模型参数时才调用。
|
|
65
67
|
|
|
66
68
|
```typescript
|
|
67
69
|
function loadV5(maxSideLen?: number, useGpu?: boolean): boolean;
|
|
@@ -69,29 +71,17 @@ function loadV5(maxSideLen?: number, useGpu?: boolean): boolean;
|
|
|
69
71
|
|
|
70
72
|
**参数:**
|
|
71
73
|
|
|
72
|
-
| 参数名 | 类型 | 是否必填 | 默认值 | 描述
|
|
73
|
-
| ------------ | ------- | -------- | ------ |
|
|
74
|
-
| `maxSideLen` | number | 否 | 640 | 输入图像的最大边长,默认值为 640
|
|
75
|
-
| `useGpu` | boolean | 否 | false | 是否启用 GPU 加速
|
|
74
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
75
|
+
| ------------ | ------- | -------- | ------ | -------------------------------- |
|
|
76
|
+
| `maxSideLen` | number | 否 | 640 | 输入图像的最大边长,默认值为 640 |
|
|
77
|
+
| `useGpu` | boolean | 否 | false | 是否启用 GPU 加速 |
|
|
76
78
|
|
|
77
79
|
**返回值:**
|
|
78
80
|
|
|
79
|
-
| 类型 | 描述
|
|
80
|
-
| ------- |
|
|
81
|
+
| 类型 | 描述 |
|
|
82
|
+
| ------- | --------------------------------------------------- |
|
|
81
83
|
| boolean | 加载成功或模型已加载返回 `true`,否则返回 `false` |
|
|
82
84
|
|
|
83
|
-
重复调用 `loadV5` 时,如果模型已经加载,会直接返回 `true`,不会重新加载或应用新的参数。需要更换加载参数时,先调用 `free()` 释放模型。
|
|
84
|
-
|
|
85
|
-
**示例:**
|
|
86
|
-
|
|
87
|
-
```javascript
|
|
88
|
-
// 使用默认参数加载模型
|
|
89
|
-
const loaded = paddleOcr.loadV5();
|
|
90
|
-
if (loaded) {
|
|
91
|
-
logi("PP-OCRv5 模型加载成功");
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
85
|
### 文字识别
|
|
96
86
|
|
|
97
87
|
#### recognize - 执行 OCR 文字识别,支持多种输入源和指定识别区域。
|
|
@@ -127,12 +117,6 @@ function recognize(
|
|
|
127
117
|
**示例:**
|
|
128
118
|
|
|
129
119
|
```javascript
|
|
130
|
-
// 首先加载模型
|
|
131
|
-
if (!paddleOcr.loadV5()) {
|
|
132
|
-
logi("模型加载失败");
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
120
|
// 识别整个屏幕
|
|
137
121
|
const fullScreenResults = paddleOcr.recognize("screen", 0, 0, 0, 0);
|
|
138
122
|
logi(`识别到 ${fullScreenResults.length} 个文本区域`);
|
|
@@ -227,12 +211,6 @@ function findText(
|
|
|
227
211
|
**示例:**
|
|
228
212
|
|
|
229
213
|
```javascript
|
|
230
|
-
// 首先加载模型
|
|
231
|
-
if (!paddleOcr.loadV5()) {
|
|
232
|
-
logi("模型加载失败");
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
214
|
// 在整个屏幕中查找目标文本
|
|
237
215
|
const hitResults = paddleOcr.findText(
|
|
238
216
|
"screen",
|
package/docs/apicn/paddleocr.md
CHANGED
|
@@ -4,11 +4,11 @@ PaddleOCR 模块基于百度飞桨 PaddleOCR 技术,提供强大的光学字
|
|
|
4
4
|
|
|
5
5
|
## 功能概览
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- **自动加载**: 识别和查找方法会自动加载所需模型,无需先手动加载
|
|
8
8
|
- **多源识别**: 支持屏幕截图、图片文件、URL 等多种输入源
|
|
9
9
|
- **区域识别**: 支持指定区域的精确文字识别
|
|
10
10
|
- **结构化结果**: 提供详细的文本位置、置信度和方向信息
|
|
11
|
-
-
|
|
11
|
+
- **资源释放**: 可在需要时释放 OCR 资源
|
|
12
12
|
|
|
13
13
|
## 数据类型
|
|
14
14
|
|
|
@@ -61,7 +61,9 @@ interface OCR识别结果 {
|
|
|
61
61
|
|
|
62
62
|
### 模型管理
|
|
63
63
|
|
|
64
|
-
#### 加载 V5 模型 -
|
|
64
|
+
#### 加载 V5 模型 - 可选预加载 PP-OCRv5 模型。
|
|
65
|
+
|
|
66
|
+
识别和查找方法会自动加载所需模型,通常不需要先调用 `加载V5模型`。只有需要提前加载或指定模型参数时才调用。
|
|
65
67
|
|
|
66
68
|
```typescript
|
|
67
69
|
function 加载V5模型(最大边长?: 数字, useGpu?: 布尔值): 布尔值;
|
|
@@ -80,18 +82,6 @@ function 加载V5模型(最大边长?: 数字, useGpu?: 布尔值): 布尔值;
|
|
|
80
82
|
| ------ | --------------------------------------------------- |
|
|
81
83
|
| 布尔值 | 加载成功或模型已加载返回 `true`,否则返回 `false` |
|
|
82
84
|
|
|
83
|
-
重复调用 `加载V5模型` 时,如果模型已经加载,会直接返回 `true`,不会重新加载或应用新的参数。需要更换加载参数时,先调用 `释放资源()` 释放模型。
|
|
84
|
-
|
|
85
|
-
**示例:**
|
|
86
|
-
|
|
87
|
-
```javascript
|
|
88
|
-
// 使用默认参数加载模型
|
|
89
|
-
const 是否加载成功 = $PaddleOCR.加载V5模型();
|
|
90
|
-
if (是否加载成功) {
|
|
91
|
-
$打印信息日志("PP-OCRv5 模型加载成功");
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
85
|
### 文字识别
|
|
96
86
|
|
|
97
87
|
#### 识别 - 执行 OCR 文字识别,支持多种输入源和指定识别区域。
|
|
@@ -127,13 +117,6 @@ function 识别(
|
|
|
127
117
|
**示例:**
|
|
128
118
|
|
|
129
119
|
```javascript
|
|
130
|
-
// 首先加载模型
|
|
131
|
-
const 是否加载成功 = $PaddleOCR.加载V5模型();
|
|
132
|
-
if (!是否加载成功) {
|
|
133
|
-
$打印错误日志("模型加载失败");
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
120
|
// 识别整个屏幕
|
|
138
121
|
const fullScreenResults = $PaddleOCR.识别("screen", 0, 0, 0, 0);
|
|
139
122
|
$打印信息日志(`识别到 ${fullScreenResults.length} 个文本区域`);
|
|
@@ -228,13 +211,6 @@ function 查找文本(
|
|
|
228
211
|
**示例:**
|
|
229
212
|
|
|
230
213
|
```javascript
|
|
231
|
-
// 首先加载模型
|
|
232
|
-
const 是否加载成功 = $PaddleOCR.加载V5模型();
|
|
233
|
-
if (!是否加载成功) {
|
|
234
|
-
$打印错误日志("模型加载失败");
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
214
|
// 在整个屏幕中查找目标文本
|
|
239
215
|
const 命中结果 = $PaddleOCR.查找文本(
|
|
240
216
|
"screen",
|
|
@@ -4,11 +4,11 @@ PaddleOCR 模块基于百度飞桨 PaddleOCR 技术,提供强大的光学字
|
|
|
4
4
|
|
|
5
5
|
## 功能概览
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- **自动加载**: 识别和查找方法会自动加载所需模型,无需先手动加载
|
|
8
8
|
- **多源识别**: 支持屏幕截图、图片文件、URL 等多种输入源
|
|
9
9
|
- **区域识别**: 支持指定区域的精确文字识别
|
|
10
10
|
- **结构化结果**: 提供详细的文本位置、置信度和方向信息
|
|
11
|
-
-
|
|
11
|
+
- **资源释放**: 可在需要时释放 OCR 资源
|
|
12
12
|
|
|
13
13
|
## 类型定义
|
|
14
14
|
|
|
@@ -38,9 +38,9 @@ class OCRResult(TypedDict):
|
|
|
38
38
|
|
|
39
39
|
### 模型管理
|
|
40
40
|
|
|
41
|
-
#### `loadV5` -
|
|
41
|
+
#### `loadV5` - 可选预加载 PP-OCRv5 模型
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
识别和查找方法会自动加载所需模型,通常不需要先调用 `loadV5`。只有需要提前加载或指定模型参数时才调用。
|
|
44
44
|
|
|
45
45
|
```python
|
|
46
46
|
def loadV5(maxSideLen: int = 640, useGpu: bool = False) -> bool
|
|
@@ -59,19 +59,6 @@ def loadV5(maxSideLen: int = 640, useGpu: bool = False) -> bool
|
|
|
59
59
|
| ------ | --------------------------------------------------- |
|
|
60
60
|
| `bool` | 加载成功或模型已加载返回 `True`,否则返回 `False` |
|
|
61
61
|
|
|
62
|
-
重复调用 `loadV5` 时,如果模型已经加载,会直接返回 `True`,不会重新加载或应用新的参数。需要更换加载参数时,先调用 `free()` 释放模型。
|
|
63
|
-
|
|
64
|
-
**示例:**
|
|
65
|
-
|
|
66
|
-
```python
|
|
67
|
-
from kuaijs import paddleocr
|
|
68
|
-
|
|
69
|
-
# 使用默认参数加载模型
|
|
70
|
-
loaded = paddleocr.loadV5()
|
|
71
|
-
if loaded:
|
|
72
|
-
print("PP-OCRv5 模型加载成功")
|
|
73
|
-
```
|
|
74
|
-
|
|
75
62
|
### 文字识别
|
|
76
63
|
|
|
77
64
|
#### `recognize` - 执行 OCR 文字识别
|
|
@@ -111,30 +98,26 @@ def recognize(
|
|
|
111
98
|
```python
|
|
112
99
|
from kuaijs import paddleocr
|
|
113
100
|
|
|
114
|
-
#
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
# 识别网络图片
|
|
136
|
-
url_results = paddleocr.recognize("https://example.com/image.jpg", 0, 0, 1000, 800)
|
|
137
|
-
print(f"网络图片识别结果数量: {len(url_results)}")
|
|
101
|
+
# 识别整个屏幕
|
|
102
|
+
full_screen_results = paddleocr.recognize("screen", 0, 0, 0, 0)
|
|
103
|
+
print(f"识别到 {len(full_screen_results)} 个文本区域")
|
|
104
|
+
for r in full_screen_results:
|
|
105
|
+
print(f"文本: {r.text}, 置信度: {r.confidence}")
|
|
106
|
+
|
|
107
|
+
# 识别屏幕指定区域
|
|
108
|
+
region_results = paddleocr.recognize("screen", 100, 100, 500, 300)
|
|
109
|
+
if region_results:
|
|
110
|
+
top = region_results[0]
|
|
111
|
+
print(f"指定区域文本: {top.text}, 中心: ({top.centerX}, {top.centerY})")
|
|
112
|
+
|
|
113
|
+
# 识别图片文件
|
|
114
|
+
image_results = paddleocr.recognize("/path/to/image.png", 0, 0, 800, 600)
|
|
115
|
+
for r in image_results:
|
|
116
|
+
print(f"图片文字: {r.text}")
|
|
117
|
+
|
|
118
|
+
# 识别网络图片
|
|
119
|
+
url_results = paddleocr.recognize("https://example.com/image.jpg", 0, 0, 1000, 800)
|
|
120
|
+
print(f"网络图片识别结果数量: {len(url_results)}")
|
|
138
121
|
```
|
|
139
122
|
|
|
140
123
|
#### `recognizeAbs` - 执行 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标
|
|
@@ -201,21 +184,17 @@ def findText(
|
|
|
201
184
|
```python
|
|
202
185
|
from kuaijs import paddleocr
|
|
203
186
|
|
|
204
|
-
#
|
|
205
|
-
|
|
206
|
-
|
|
187
|
+
# 在整个屏幕中查找目标文本
|
|
188
|
+
hit_results = paddleocr.findText("screen", ["登录", "确定"], 0, 0, 0, 0, 0.6, False)
|
|
189
|
+
if hit_results:
|
|
190
|
+
for i, r in enumerate(hit_results, 1):
|
|
191
|
+
print(f"命中{i}: {r.text}, 中心点=({r.centerX}, {r.centerY}), 置信度={r.confidence}")
|
|
207
192
|
else:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
else:
|
|
214
|
-
print("未命中目标文本")
|
|
215
|
-
|
|
216
|
-
# 在指定区域查找目标文本
|
|
217
|
-
region_hits = paddleocr.findText("screen", ["下一步"], 100, 100, 500, 400)
|
|
218
|
-
print(f"区域命中数量: {len(region_hits)}")
|
|
193
|
+
print("未命中目标文本")
|
|
194
|
+
|
|
195
|
+
# 在指定区域查找目标文本
|
|
196
|
+
region_hits = paddleocr.findText("screen", ["下一步"], 100, 100, 500, 400)
|
|
197
|
+
print(f"区域命中数量: {len(region_hits)}")
|
|
219
198
|
```
|
|
220
199
|
|
|
221
200
|
#### `findTextAbs` - 查找目标文本,并将结果坐标映射为原图/全屏绝对坐标
|