ms-vite-plugin 1.4.39 → 1.4.41
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/docs/api/dotocr.md +160 -0
- package/docs/api/node.md +90 -3
- package/docs/api/opencv.md +1328 -0
- package/docs/apicn/dotocr.md +161 -0
- package/docs/apicn/node.md +89 -3
- package/docs/apipython/dotocr.md +148 -0
- package/docs/apipython/node.md +86 -4
- package/package.json +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# 点阵 OCR 模块($点阵OCR)
|
|
2
|
+
|
|
3
|
+
`$点阵OCR` 使用图色工具生成的固定像素点阵字库识别文字。字库保存在项目的 `res/fonts` 目录,使用方式与 YOLO 模型一致:先加载资源取得字库 ID,再复用该 ID 进行识别,使用完毕后释放。
|
|
4
|
+
|
|
5
|
+
点阵模板按照制作时的原始像素尺寸匹配,不会自动缩放到其他分辨率。目标文字的字号、缩放比例或像素形状发生变化时,应制作对应的字库特征。
|
|
6
|
+
|
|
7
|
+
## 功能概览
|
|
8
|
+
|
|
9
|
+
- **字库管理**:加载、缓存和释放项目字库
|
|
10
|
+
- **文字识别**:返回按阅读顺序排列的识别结果数组
|
|
11
|
+
- **文本查找**:先识别再按行定位目标串,返回命中位置的绝对坐标
|
|
12
|
+
- **多源输入**:支持 `"screen"`、图片文件路径、URL 或 imageId
|
|
13
|
+
- **绝对坐标**:裁剪区域内的结果会映射回原图或全屏坐标
|
|
14
|
+
|
|
15
|
+
## 数据类型
|
|
16
|
+
|
|
17
|
+
### OCR字符
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
interface OCR字符 {
|
|
21
|
+
text: 字符串;
|
|
22
|
+
confidence: 数字;
|
|
23
|
+
x: 数字;
|
|
24
|
+
y: 数字;
|
|
25
|
+
ex: 数字;
|
|
26
|
+
ey: 数字;
|
|
27
|
+
width: 数字;
|
|
28
|
+
height: 数字;
|
|
29
|
+
centerX: 数字;
|
|
30
|
+
centerY: 数字;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| 字段名 | 类型 | 描述 |
|
|
35
|
+
| -------------------- | ------ | -------------------------------------- |
|
|
36
|
+
| `OCR字符.text` | 字符串 | 识别文本;查找结果中为命中的目标字符串 |
|
|
37
|
+
| `confidence` | 数字 | 置信度,范围为 0-1 |
|
|
38
|
+
| `x`, `y` | 数字 | 结果区域左上角绝对坐标 |
|
|
39
|
+
| `ex`, `ey` | 数字 | 结果区域右下角绝对坐标 |
|
|
40
|
+
| `width`, `height` | 数字 | 结果区域宽度和高度 |
|
|
41
|
+
| `centerX`, `centerY` | 数字 | 结果区域中心点绝对坐标 |
|
|
42
|
+
|
|
43
|
+
## API 参考
|
|
44
|
+
|
|
45
|
+
### 字库管理
|
|
46
|
+
|
|
47
|
+
#### 加载字库 - 加载并缓存字库
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
function 加载字库(字库资源路径: 字符串): 字符串 | null;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
54
|
+
| -------------- | ------ | -------- | ------ | --------------------------------------------------------------------------- |
|
|
55
|
+
| `字库资源路径` | 字符串 | 是 | | 资源路径,运行时会自动处理 `res` 目录解析;常见写法如 `/fonts/default.json` |
|
|
56
|
+
|
|
57
|
+
**返回值:**加载成功返回字库 ID,失败返回 `null`。加载后的字库 ID 会复用到后续识别与释放流程。
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const 字库ID = $点阵OCR.加载字库("/fonts/default.json");
|
|
61
|
+
if (!字库ID) throw new Error("字库加载失败");
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
建议在脚本初始化时加载一次并保存字库 ID,后续识别时复用,不要每次识别都重新加载。
|
|
65
|
+
|
|
66
|
+
### 文字识别
|
|
67
|
+
|
|
68
|
+
#### 识别绝对坐标 - 识别文字并返回绝对坐标
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
function 识别绝对坐标(
|
|
72
|
+
字库ID: 字符串,
|
|
73
|
+
输入源: 字符串,
|
|
74
|
+
左?: 数字,
|
|
75
|
+
上?: 数字,
|
|
76
|
+
右?: 数字,
|
|
77
|
+
下?: 数字,
|
|
78
|
+
置信度阈值?: 数字,
|
|
79
|
+
): 数组<OCR字符>;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
83
|
+
| ------------ | ------ | -------- | ------ | -------------------------------------------------------------------------------------------- |
|
|
84
|
+
| `字库ID` | 字符串 | 是 | | `加载字库` 返回的字库 ID |
|
|
85
|
+
| `输入源` | 字符串 | 是 | | 输入源,支持 `"screen"`、图片文件路径、URL 或 imageId |
|
|
86
|
+
| `左`, `上` | 数字 | 否 | 0 | 裁剪区域左上角坐标 |
|
|
87
|
+
| `右`, `下` | 数字 | 否 | 0 | 裁剪区域右下角坐标;`右` 或 `下` 为 0 时分别使用图像宽度或高度 |
|
|
88
|
+
| `置信度阈值` | 数字 | 否 | 0.8 | 相似度下限;`<=0` 时按 `0.8`;低于阈值的字符会被过滤;`>0.95` 时要求像素完全一致 |
|
|
89
|
+
|
|
90
|
+
**返回值:**`数组<OCR字符>`。按行从上到下、同一行从左到右排列。颜色按字库各字自带的前景色/偏色匹配,无需额外传色。
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
const 结果 = $点阵OCR.识别绝对坐标(字库ID, "screen", 100, 200, 600, 280, 0.8);
|
|
94
|
+
$打印信息日志(结果[0]?.text);
|
|
95
|
+
$打印信息日志(`坐标: ${结果[0]?.x}, ${结果[0]?.y}`);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 文本查找
|
|
99
|
+
|
|
100
|
+
#### 查找文本绝对坐标 - 查找指定字符串并返回绝对坐标
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
function 查找文本绝对坐标(
|
|
104
|
+
字库ID: 字符串,
|
|
105
|
+
输入源: 字符串,
|
|
106
|
+
目标文本: 数组<字符串>,
|
|
107
|
+
左?: 数字,
|
|
108
|
+
上?: 数字,
|
|
109
|
+
右?: 数字,
|
|
110
|
+
下?: 数字,
|
|
111
|
+
置信度阈值?: 数字,
|
|
112
|
+
完整匹配?: 布尔值,
|
|
113
|
+
): 数组<OCR字符>;
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
117
|
+
| ------------ | ------------- | -------- | ------ | --------------------------------------------------------------------- |
|
|
118
|
+
| `字库ID` | 字符串 | 是 | | `加载字库` 返回的字库 ID |
|
|
119
|
+
| `输入源` | 字符串 | 是 | | 输入源,支持 `"screen"`、图片文件路径、URL 或 imageId |
|
|
120
|
+
| `目标文本` | 数组<字符串> | 是 | | 要查找的字符串数组,例如 `["商店", "背包"]` |
|
|
121
|
+
| `左`, `上` | 数字 | 否 | 0 | 裁剪区域左上角坐标 |
|
|
122
|
+
| `右`, `下` | 数字 | 否 | 0 | 裁剪区域右下角坐标;`右` 或 `下` 为 0 时分别使用图像宽度或高度 |
|
|
123
|
+
| `置信度阈值` | 数字 | 否 | 0.8 | 单字符识别相似度下限;语义同 `识别绝对坐标` |
|
|
124
|
+
| `完整匹配` | 布尔值 | 否 | false | `false` 为行内子串包含匹配;`true` 要求某一整行文本完全等于目标字符串 |
|
|
125
|
+
|
|
126
|
+
**返回值:**命中结果数组。每个目标最多返回一次命中(最先匹配到的行);每项的 `text` 是目标字符串。
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const 命中 = $点阵OCR.查找文本绝对坐标(
|
|
130
|
+
字库ID,
|
|
131
|
+
"screen",
|
|
132
|
+
["商店", "背包"],
|
|
133
|
+
100,
|
|
134
|
+
200,
|
|
135
|
+
600,
|
|
136
|
+
280,
|
|
137
|
+
0.8,
|
|
138
|
+
false,
|
|
139
|
+
);
|
|
140
|
+
if (命中.length > 0) $动作.点击(命中[0].centerX, 命中[0].centerY);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 资源管理
|
|
144
|
+
|
|
145
|
+
#### 释放 - 释放指定字库
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
function 释放(字库ID: 字符串): void;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### 释放全部 - 释放全部点阵字库
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
function 释放全部(): void;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
$点阵OCR.释放(字库ID);
|
|
159
|
+
// 或在需要清理全部已加载的点阵字库时:
|
|
160
|
+
$点阵OCR.释放全部();
|
|
161
|
+
```
|
package/docs/apicn/node.md
CHANGED
|
@@ -90,6 +90,13 @@ interface $节点信息 {
|
|
|
90
90
|
点击中心(): 布尔值; // 点击中心
|
|
91
91
|
点击随机范围(): 布尔值; // 随机点击
|
|
92
92
|
hittable(): 布尔值; // 节点是否可接收事件,用于判断节点是否在屏幕可见
|
|
93
|
+
tap(): 布尔值; // 无障碍点击
|
|
94
|
+
doubleTap(): 布尔值; // 无障碍双击
|
|
95
|
+
press(duration: 数字): 布尔值; // 无障碍长按,duration 单位毫秒
|
|
96
|
+
scrollToVisible(): 布尔值; // 将节点滚动到可见区域
|
|
97
|
+
clearInput(): 布尔值; // 清空输入
|
|
98
|
+
input(text: 字符串): 布尔值; // 追加输入(聚焦后输入)
|
|
99
|
+
setValue(text: 字符串): 布尔值; // 设置节点的值(见下方支持控件)
|
|
93
100
|
parent(): $节点信息 | null; // 获取父节点
|
|
94
101
|
child(index: 数字): $节点信息 | null; // 获取子节点
|
|
95
102
|
allChildren(): $节点信息[]; // 获取所有子节点
|
|
@@ -274,16 +281,82 @@ const xpathElements = 选择器.xpath("//*[@title='快点JS']").获取所有节
|
|
|
274
281
|
#### 点击操作
|
|
275
282
|
|
|
276
283
|
```typescript
|
|
277
|
-
//
|
|
284
|
+
// 点击节点中心(坐标点击)
|
|
278
285
|
node.点击中心(): 布尔值;
|
|
279
286
|
|
|
280
|
-
//
|
|
287
|
+
// 随机点击节点区域(坐标点击)
|
|
281
288
|
node.点击随机范围(): 布尔值;
|
|
282
289
|
|
|
283
290
|
// 节点是否可接收事件(用于判断是否显示在屏幕上)
|
|
284
291
|
node.hittable(): 布尔值;
|
|
292
|
+
|
|
293
|
+
// 无障碍点击
|
|
294
|
+
node.tap(): 布尔值;
|
|
295
|
+
|
|
296
|
+
// 无障碍双击
|
|
297
|
+
node.doubleTap(): 布尔值;
|
|
298
|
+
|
|
299
|
+
// 无障碍长按,duration 单位毫秒
|
|
300
|
+
node.press(duration: 数字): 布尔值;
|
|
301
|
+
|
|
302
|
+
// 将节点滚动到可见区域
|
|
303
|
+
node.scrollToVisible(): 布尔值;
|
|
304
|
+
|
|
305
|
+
// 清空输入
|
|
306
|
+
node.clearInput(): 布尔值;
|
|
307
|
+
|
|
308
|
+
// 追加输入
|
|
309
|
+
node.input(text: 字符串): 布尔值;
|
|
310
|
+
|
|
311
|
+
// 设置节点的值
|
|
312
|
+
node.setValue(text: 字符串): 布尔值;
|
|
285
313
|
```
|
|
286
314
|
|
|
315
|
+
#### tap / doubleTap / press - 无障碍手势
|
|
316
|
+
|
|
317
|
+
通过无障碍 API 直接操作节点,不依赖坐标点击。
|
|
318
|
+
|
|
319
|
+
| 方法 | 参数 | 说明 |
|
|
320
|
+
| --- | --- | --- |
|
|
321
|
+
| `tap()` | 无 | 无障碍单击 |
|
|
322
|
+
| `doubleTap()` | 无 | 无障碍双击 |
|
|
323
|
+
| `press(duration)` | `duration`:长按持续时间,单位毫秒 | 无障碍长按 |
|
|
324
|
+
|
|
325
|
+
**示例:**
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
const 选择器 = $创建节点选择器();
|
|
329
|
+
|
|
330
|
+
const btn = 选择器.label("确定").type("XCUIElementTypeButton").获取一个节点(3000);
|
|
331
|
+
if (btn) {
|
|
332
|
+
// 无障碍单击
|
|
333
|
+
btn.tap();
|
|
334
|
+
|
|
335
|
+
// 无障碍双击
|
|
336
|
+
btn.doubleTap();
|
|
337
|
+
|
|
338
|
+
// 无障碍长按 800ms
|
|
339
|
+
btn.press(800);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 释放选择器内存
|
|
343
|
+
选择器.释放内存();
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
#### setValue - 设置节点的值
|
|
347
|
+
|
|
348
|
+
按控件类型自动处理,常用支持如下:
|
|
349
|
+
|
|
350
|
+
| 控件类型 | 传参示例 | 说明 |
|
|
351
|
+
| --- | --- | --- |
|
|
352
|
+
| `XCUIElementTypePickerWheel` | `"1小时"` | 滚轮选到对应选项文案 |
|
|
353
|
+
| `XCUIElementTypeTextField` | `"hello"` | 先聚焦再输入文本 |
|
|
354
|
+
| `XCUIElementTypeSecureTextField` | `"123456"` | 同上 |
|
|
355
|
+
| `XCUIElementTypeTextView` | `"多行内容"` | 同上 |
|
|
356
|
+
| `XCUIElementTypeSearchField` | `"关键词"` | 同上 |
|
|
357
|
+
|
|
358
|
+
文本类控件不会先清空已有内容;需要清空时先调用 `clearInput()`。
|
|
359
|
+
|
|
287
360
|
**示例:**
|
|
288
361
|
|
|
289
362
|
```typescript
|
|
@@ -298,12 +371,25 @@ if (confirmBtn) {
|
|
|
298
371
|
const isHittable = confirmBtn.hittable();
|
|
299
372
|
$打印信息日志(`是否可接收事件: ${isHittable}`);
|
|
300
373
|
|
|
301
|
-
|
|
374
|
+
confirmBtn.scrollToVisible();
|
|
375
|
+
// 优先使用无障碍点击;也可用 点击中心 / 点击随机范围 做坐标点击
|
|
376
|
+
const clicked = confirmBtn.tap();
|
|
302
377
|
if (clicked) {
|
|
303
378
|
$打印信息日志("成功点击确定按钮");
|
|
304
379
|
}
|
|
305
380
|
}
|
|
306
381
|
|
|
382
|
+
const field = 选择器.type("XCUIElementTypeTextField").获取一个节点(3000);
|
|
383
|
+
if (field) {
|
|
384
|
+
field.clearInput();
|
|
385
|
+
field.setValue("hello");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const wheel = 选择器.type("XCUIElementTypePickerWheel").获取一个节点(3000);
|
|
389
|
+
if (wheel) {
|
|
390
|
+
wheel.setValue("1小时");
|
|
391
|
+
}
|
|
392
|
+
|
|
307
393
|
// 随机点击避免检测
|
|
308
394
|
const randomClick = confirmBtn?.点击随机范围();
|
|
309
395
|
if (randomClick) {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# 点阵 OCR 模块(dotocr)
|
|
2
|
+
|
|
3
|
+
`dotocr` 使用图色工具生成的固定像素点阵字库识别文字。字库保存在项目的 `res/fonts` 目录,使用方式与 YOLO 模型一致:先加载资源取得字库 ID,再复用该 ID 进行识别,使用完毕后释放。
|
|
4
|
+
|
|
5
|
+
点阵模板按照制作时的原始像素尺寸匹配,不会自动缩放到其他分辨率。目标文字的字号、缩放比例或像素形状发生变化时,应制作对应的字库特征。
|
|
6
|
+
|
|
7
|
+
## 数据类型
|
|
8
|
+
|
|
9
|
+
### OCRChar
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from kuaijs._types import KuaiJSNamespace
|
|
13
|
+
|
|
14
|
+
class OCRChar(KuaiJSNamespace):
|
|
15
|
+
text: str
|
|
16
|
+
confidence: float
|
|
17
|
+
x: int
|
|
18
|
+
y: int
|
|
19
|
+
ex: int
|
|
20
|
+
ey: int
|
|
21
|
+
width: int
|
|
22
|
+
height: int
|
|
23
|
+
centerX: int
|
|
24
|
+
centerY: int
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| 字段名 | 类型 | 描述 |
|
|
28
|
+
| -------------------- | ----- | -------------------------------------- |
|
|
29
|
+
| `OCRChar.text` | str | 识别文本;查找结果中为命中的目标字符串 |
|
|
30
|
+
| `confidence` | float | 置信度,范围为 0-1 |
|
|
31
|
+
| `x`, `y` | int | 结果区域左上角绝对坐标 |
|
|
32
|
+
| `ex`, `ey` | int | 结果区域右下角绝对坐标 |
|
|
33
|
+
| `width`, `height` | int | 结果区域宽度和高度 |
|
|
34
|
+
| `centerX`, `centerY` | int | 结果区域中心点绝对坐标 |
|
|
35
|
+
|
|
36
|
+
## API 参考
|
|
37
|
+
|
|
38
|
+
### 字库管理
|
|
39
|
+
|
|
40
|
+
#### `loadFont` - 加载并缓存字库
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
def loadFont(fontPath: str) -> Optional[str]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
47
|
+
| ---------- | ---- | -------- | ------ | --------------------------------------------------------------------------- |
|
|
48
|
+
| `fontPath` | str | 是 | | 资源路径,运行时会自动处理 `res` 目录解析;常见写法如 `/fonts/default.json` |
|
|
49
|
+
|
|
50
|
+
**返回值:**加载成功返回 `fontId`,失败返回 `None`。加载后的字库 ID 会复用到后续识别与释放流程。
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from kuaijs import dotocr
|
|
54
|
+
|
|
55
|
+
font_id = dotocr.loadFont("/fonts/default.json")
|
|
56
|
+
if not font_id:
|
|
57
|
+
raise RuntimeError("字库加载失败")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
建议在脚本初始化时加载一次并保存 `font_id`,后续识别时复用,不要每次识别都重新加载。
|
|
61
|
+
|
|
62
|
+
### 文字识别
|
|
63
|
+
|
|
64
|
+
#### `recognizeAbs` - 识别文字并返回绝对坐标
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
def recognizeAbs(
|
|
68
|
+
fontId: str,
|
|
69
|
+
input: str,
|
|
70
|
+
x: int = 0,
|
|
71
|
+
y: int = 0,
|
|
72
|
+
ex: int = 0,
|
|
73
|
+
ey: int = 0,
|
|
74
|
+
confidenceThreshold: float = 0.8,
|
|
75
|
+
) -> List[OCRChar]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
79
|
+
| --------------------- | ----- | -------- | ------ | -------------------------------------------------------------------------------------------- |
|
|
80
|
+
| `fontId` | str | 是 | | `loadFont` 返回的字库 ID |
|
|
81
|
+
| `input` | str | 是 | | 输入源,支持 `"screen"`、图片文件路径、URL 或 imageId |
|
|
82
|
+
| `x`, `y` | int | 否 | 0 | 裁剪区域左上角坐标 |
|
|
83
|
+
| `ex`, `ey` | int | 否 | 0 | 裁剪区域右下角坐标;`ex` 或 `ey` 为 0 时分别使用图像宽度或高度 |
|
|
84
|
+
| `confidenceThreshold` | float | 否 | 0.8 | 相似度下限;`<=0` 时按 `0.8`;低于阈值的字符会被过滤;`>0.95` 时要求像素完全一致 |
|
|
85
|
+
|
|
86
|
+
**返回值:**`List[OCRChar]`。按行从上到下、同一行从左到右排列。颜色按字库各字自带的前景色/偏色匹配,无需额外传色。
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
chars = dotocr.recognizeAbs(font_id, "screen", 100, 200, 600, 280, 0.8)
|
|
90
|
+
if chars:
|
|
91
|
+
print(chars[0].text, chars[0].x, chars[0].width)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 文本查找
|
|
95
|
+
|
|
96
|
+
#### `findTextAbs` - 查找指定字符串并返回绝对坐标
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
def findTextAbs(
|
|
100
|
+
fontId: str,
|
|
101
|
+
input: str,
|
|
102
|
+
targetTexts: List[str],
|
|
103
|
+
x: int = 0,
|
|
104
|
+
y: int = 0,
|
|
105
|
+
ex: int = 0,
|
|
106
|
+
ey: int = 0,
|
|
107
|
+
confidenceThreshold: float = 0.8,
|
|
108
|
+
exactMatch: bool = False,
|
|
109
|
+
) -> List[OCRChar]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
113
|
+
| --------------------- | --------- | -------- | ------ | --------------------------------------------------------------------- |
|
|
114
|
+
| `fontId` | str | 是 | | `loadFont` 返回的字库 ID |
|
|
115
|
+
| `input` | str | 是 | | 输入源,支持 `"screen"`、图片文件路径、URL 或 imageId |
|
|
116
|
+
| `targetTexts` | List[str] | 是 | | 要查找的字符串数组,例如 `["商店", "背包"]` |
|
|
117
|
+
| `x`, `y` | int | 否 | 0 | 裁剪区域左上角坐标 |
|
|
118
|
+
| `ex`, `ey` | int | 否 | 0 | 裁剪区域右下角坐标;`ex` 或 `ey` 为 0 时分别使用图像宽度或高度 |
|
|
119
|
+
| `confidenceThreshold` | float | 否 | 0.8 | 单字符识别相似度下限;语义同 `recognizeAbs` |
|
|
120
|
+
| `exactMatch` | bool | 否 | false | `false` 为行内子串包含匹配;`true` 要求某一整行文本完全等于目标字符串 |
|
|
121
|
+
|
|
122
|
+
**返回值:**命中结果数组。每个目标最多返回一次命中(最先匹配到的行);每项的 `text` 是目标字符串。
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
hits = dotocr.findTextAbs(font_id, "screen", ["商店", "背包"], 100, 200, 600, 280, 0.8, False)
|
|
126
|
+
if hits:
|
|
127
|
+
action.click(hits[0].centerX, hits[0].centerY)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 资源管理
|
|
131
|
+
|
|
132
|
+
#### `free` - 释放指定字库
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
def free(fontId: str) -> None
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### `freeAll` - 释放全部点阵字库
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
def freeAll() -> None
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
dotocr.free(font_id)
|
|
146
|
+
# 或在需要清理全部已加载的点阵字库时:
|
|
147
|
+
dotocr.freeAll()
|
|
148
|
+
```
|
package/docs/apipython/node.md
CHANGED
|
@@ -37,6 +37,13 @@ class NodeInfo:
|
|
|
37
37
|
def clickCenter(self) -> bool: ...
|
|
38
38
|
def clickRandom(self) -> bool: ...
|
|
39
39
|
def hittable(self) -> bool: ...
|
|
40
|
+
def tap(self) -> bool: ...
|
|
41
|
+
def doubleTap(self) -> bool: ...
|
|
42
|
+
def press(self, duration: int = 500) -> bool: ...
|
|
43
|
+
def scrollToVisible(self) -> bool: ...
|
|
44
|
+
def clearInput(self) -> bool: ...
|
|
45
|
+
def input(self, text: str) -> bool: ...
|
|
46
|
+
def setValue(self, text: str) -> bool: ...
|
|
40
47
|
def parent(self) -> Optional["NodeInfo"]: ...
|
|
41
48
|
def child(self, index: int) -> Optional["NodeInfo"]: ...
|
|
42
49
|
def allChildren(self) -> List["NodeInfo"]: ...
|
|
@@ -253,16 +260,80 @@ xpath_elements = selector.xpath("//*[@title='快点JS']").getNodeInfo(3000)
|
|
|
253
260
|
### 点击操作
|
|
254
261
|
|
|
255
262
|
```python
|
|
256
|
-
#
|
|
263
|
+
# 点击节点中心(坐标点击)
|
|
257
264
|
def clickCenter() -> bool
|
|
258
265
|
|
|
259
|
-
#
|
|
266
|
+
# 随机点击节点区域(坐标点击)
|
|
260
267
|
def clickRandom() -> bool
|
|
261
268
|
|
|
262
269
|
# 节点是否可接收事件(用于判断是否显示在屏幕上)
|
|
263
270
|
def hittable() -> bool
|
|
271
|
+
|
|
272
|
+
# 无障碍点击
|
|
273
|
+
def tap() -> bool
|
|
274
|
+
|
|
275
|
+
# 无障碍双击
|
|
276
|
+
def doubleTap() -> bool
|
|
277
|
+
|
|
278
|
+
# 无障碍长按,duration 单位毫秒,默认 500
|
|
279
|
+
def press(duration: int = 500) -> bool
|
|
280
|
+
|
|
281
|
+
# 将节点滚动到可见区域
|
|
282
|
+
def scrollToVisible() -> bool
|
|
283
|
+
|
|
284
|
+
# 清空输入
|
|
285
|
+
def clearInput() -> bool
|
|
286
|
+
|
|
287
|
+
# 追加输入
|
|
288
|
+
def input(text: str) -> bool
|
|
289
|
+
|
|
290
|
+
# 设置节点的值
|
|
291
|
+
def setValue(text: str) -> bool
|
|
264
292
|
```
|
|
265
293
|
|
|
294
|
+
#### tap / doubleTap / press - 无障碍手势
|
|
295
|
+
|
|
296
|
+
通过无障碍 API 直接操作节点,不依赖坐标点击。
|
|
297
|
+
|
|
298
|
+
| 方法 | 参数 | 说明 |
|
|
299
|
+
| --- | --- | --- |
|
|
300
|
+
| `tap()` | 无 | 无障碍单击 |
|
|
301
|
+
| `doubleTap()` | 无 | 无障碍双击 |
|
|
302
|
+
| `press(duration=500)` | `duration`:长按持续时间,单位毫秒,默认 500 | 无障碍长按 |
|
|
303
|
+
|
|
304
|
+
**示例:**
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
from kuaijs import node
|
|
308
|
+
|
|
309
|
+
selector = node.createNodeSelector()
|
|
310
|
+
|
|
311
|
+
btn = selector.label("确定").type("XCUIElementTypeButton").getOneNodeInfo(3000)
|
|
312
|
+
if btn:
|
|
313
|
+
# 无障碍单击
|
|
314
|
+
btn.tap()
|
|
315
|
+
|
|
316
|
+
# 无障碍双击
|
|
317
|
+
btn.doubleTap()
|
|
318
|
+
|
|
319
|
+
# 无障碍长按 800ms
|
|
320
|
+
btn.press(800)
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
#### setValue - 设置节点的值
|
|
324
|
+
|
|
325
|
+
按控件类型自动处理,常用支持如下:
|
|
326
|
+
|
|
327
|
+
| 控件类型 | 传参示例 | 说明 |
|
|
328
|
+
| --- | --- | --- |
|
|
329
|
+
| `XCUIElementTypePickerWheel` | `"1小时"` | 滚轮选到对应选项文案 |
|
|
330
|
+
| `XCUIElementTypeTextField` | `"hello"` | 先聚焦再输入文本 |
|
|
331
|
+
| `XCUIElementTypeSecureTextField` | `"123456"` | 同上 |
|
|
332
|
+
| `XCUIElementTypeTextView` | `"多行内容"` | 同上 |
|
|
333
|
+
| `XCUIElementTypeSearchField` | `"关键词"` | 同上 |
|
|
334
|
+
|
|
335
|
+
文本类控件不会先清空已有内容;需要清空时先调用 `clearInput()`。
|
|
336
|
+
|
|
266
337
|
**示例:**
|
|
267
338
|
|
|
268
339
|
```python
|
|
@@ -276,12 +347,23 @@ confirm_btn = selector.label("确定").type("XCUIElementTypeButton").getOneNodeI
|
|
|
276
347
|
if confirm_btn:
|
|
277
348
|
print(f"是否可接收事件: {confirm_btn.hittable()}")
|
|
278
349
|
|
|
279
|
-
|
|
350
|
+
confirm_btn.scrollToVisible()
|
|
351
|
+
# 优先使用无障碍点击;也可用 clickCenter / clickRandom 做坐标点击
|
|
352
|
+
clicked = confirm_btn.tap()
|
|
280
353
|
if clicked:
|
|
281
354
|
print("成功点击确定按钮")
|
|
282
355
|
|
|
283
|
-
#
|
|
356
|
+
# 随机坐标点击避免检测
|
|
284
357
|
confirm_btn.clickRandom()
|
|
358
|
+
|
|
359
|
+
field = selector.type("XCUIElementTypeTextField").getOneNodeInfo(3000)
|
|
360
|
+
if field:
|
|
361
|
+
field.clearInput()
|
|
362
|
+
field.setValue("hello")
|
|
363
|
+
|
|
364
|
+
wheel = selector.type("XCUIElementTypePickerWheel").getOneNodeInfo(3000)
|
|
365
|
+
if wheel:
|
|
366
|
+
wheel.setValue("1小时")
|
|
285
367
|
```
|
|
286
368
|
|
|
287
369
|
### 节点导航
|