ms-vite-plugin 1.4.10 → 1.4.12

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.
@@ -125,6 +125,31 @@ chinese_results = appleocr.recognize("screen", 0, 0, 1920, 1080, ["zh-Hans", "en
125
125
  print(f"中英文识别结果: {chinese_results}")
126
126
  ```
127
127
 
128
+ #### `recognizeAbs` - 执行 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标
129
+
130
+ 参数与 `recognize` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
131
+
132
+ ```python
133
+ def recognizeAbs(
134
+ input: str,
135
+ x: int = 0,
136
+ y: int = 0,
137
+ ex: int = 0,
138
+ ey: int = 0,
139
+ languages: Optional[List[str]] = None
140
+ ) -> List[OCRResult]
141
+ ```
142
+
143
+ **示例:**
144
+
145
+ ```python
146
+ from kuaijs import appleocr, action
147
+
148
+ abs_results = appleocr.recognizeAbs("screen", 100, 100, 500, 300)
149
+ if abs_results:
150
+ action.click(abs_results[0]["centerX"], abs_results[0]["centerY"])
151
+ ```
152
+
128
153
  ### 数字识别
129
154
 
130
155
  #### recognizeNumbers
@@ -174,6 +199,30 @@ for i, result in enumerate(number_results):
174
199
  print(f"位置: ({result.centerX}, {result.centerY})")
175
200
  ```
176
201
 
202
+ #### `recognizeNumbersAbs` - 执行数字 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标
203
+
204
+ 参数与 `recognizeNumbers` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
205
+
206
+ ```python
207
+ def recognizeNumbersAbs(
208
+ input: str,
209
+ x: int = 0,
210
+ y: int = 0,
211
+ ex: int = 0,
212
+ ey: int = 0
213
+ ) -> List[OCRResult]
214
+ ```
215
+
216
+ **示例:**
217
+
218
+ ```python
219
+ from kuaijs import appleocr, action
220
+
221
+ abs_number_results = appleocr.recognizeNumbersAbs("screen", 100, 100, 500, 300)
222
+ if abs_number_results:
223
+ action.click(abs_number_results[0]["centerX"], abs_number_results[0]["centerY"])
224
+ ```
225
+
177
226
  ### 文本查找
178
227
 
179
228
  #### findText
@@ -224,3 +273,29 @@ for i, result in enumerate(text_results):
224
273
  print(f"位置: ({result.x}, {result.y}) - ({result.ex}, {result.ey})")
225
274
  print(f"中心点: ({result.centerX}, {result.centerY})")
226
275
  ```
276
+
277
+ #### `findTextAbs` - 查找目标文本,并将结果坐标映射为原图/全屏绝对坐标
278
+
279
+ 参数与 `findText` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
280
+
281
+ ```python
282
+ def findTextAbs(
283
+ input: str,
284
+ texts: List[str],
285
+ x: int = 0,
286
+ y: int = 0,
287
+ ex: int = 0,
288
+ ey: int = 0,
289
+ languages: Optional[List[str]] = None
290
+ ) -> List[OCRResult]
291
+ ```
292
+
293
+ **示例:**
294
+
295
+ ```python
296
+ from kuaijs import appleocr, action
297
+
298
+ abs_hits = appleocr.findTextAbs("screen", ["确定"], 100, 100, 500, 400)
299
+ if abs_hits:
300
+ action.click(abs_hits[0]["centerX"], abs_hits[0]["centerY"])
301
+ ```
@@ -153,6 +153,59 @@ if g.getCpuAutoThrottle():
153
153
  print("CPU 自动限流已开启")
154
154
  ```
155
155
 
156
+ #### `setCpuThrottleDelay` - 设置 CPU 限流延迟
157
+
158
+ 设置 CPU 限流单次 sleep 延迟范围(毫秒)。默认 `min_ms=3`、`max_ms=30`。仅在 CPU 自动限流开启且触发限流时生效。
159
+
160
+ ```python
161
+ def setCpuThrottleDelay(min_ms: int, max_ms: int) -> dict
162
+ ```
163
+
164
+ **参数:**
165
+
166
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
167
+ | --------- | ----- | -------- | ------ | ---------------------------------- |
168
+ | `min_ms` | `int` | 是 | - | 最低延迟(毫秒) |
169
+ | `max_ms` | `int` | 是 | - | 最高延迟(毫秒);小于 min_ms 时自动对齐 |
170
+
171
+ **返回值:**
172
+
173
+ | 类型 | 描述 |
174
+ | ------ | ------------------ |
175
+ | `dict` | `{"minMs": int, "maxMs": int}`,实际生效的延迟范围 |
176
+
177
+ **示例:**
178
+
179
+ ```python
180
+ from kuaijs import g
181
+
182
+ delay = g.setCpuThrottleDelay(3, 30)
183
+ print(f"CPU 限流延迟: {delay['minMs']}~{delay['maxMs']}ms")
184
+ ```
185
+
186
+ #### `getCpuThrottleDelay` - 获取 CPU 限流延迟
187
+
188
+ 获取 CPU 限流延迟范围(毫秒)。
189
+
190
+ ```python
191
+ def getCpuThrottleDelay() -> dict
192
+ ```
193
+
194
+ **返回值:**
195
+
196
+ | 类型 | 描述 |
197
+ | ------ | ------------------ |
198
+ | `dict` | `{"minMs": int, "maxMs": int}`,当前最低与最高延迟 |
199
+
200
+ **示例:**
201
+
202
+ ```python
203
+ from kuaijs import g
204
+
205
+ delay = g.getCpuThrottleDelay()
206
+ print(f"CPU 限流延迟: {delay['minMs']}~{delay['maxMs']}ms")
207
+ ```
208
+
156
209
  #### `restartScript` - 重启脚本
157
210
 
158
211
  ```python
@@ -46,6 +46,7 @@ class NodeInfo:
46
46
 
47
47
  class NodeSelectorOptions(TypedDict, total=False):
48
48
  maxDepth: int # 最大层级深度,默认 50
49
+ mode: int # 抓取模式:模式 1、模式 2,默认模式 1
49
50
  ```
50
51
 
51
52
  ## 节点选择器 (NodeSelector)
@@ -67,6 +68,7 @@ def createNodeSelector(params: Optional[NodeSelectorOptions] = None) -> NodeSele
67
68
  | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
68
69
  | ---------- | ---- | -------- | ------ | --------------------- |
69
70
  | `maxDepth` | int | 否 | 50 | 最大层级深度,默认 50 |
71
+ | `mode` | int | 否 | 1 | 抓取模式。模式 1、模式 2,默认模式 1 |
70
72
 
71
73
  **返回值:** `NodeSelector`
72
74
 
@@ -77,7 +79,8 @@ from kuaijs import node
77
79
 
78
80
  # 创建选择器
79
81
  selector = node.createNodeSelector({
80
- "maxDepth": 20 # 最大20层深度
82
+ "maxDepth": 20, # 最大20层深度
83
+ "mode": 1 # 默认模式 1
81
84
  })
82
85
  ```
83
86
 
@@ -5,7 +5,7 @@
5
5
  - 导入方式:
6
6
 
7
7
  ```python
8
- from kuaijs import action, hid, image, appleocr, paddleocr, yolo, system, device, file, mysql, netcard, ime, media, hotupdate, tomatoocr, tts, ui, utils, node, pip, logger
8
+ from kuaijs import action, hid, image, appleocr, paddleocr, yolo, yolocls, system, device, file, mysql, netcard, ime, media, hotupdate, tomatoocr, tts, ui, utils, node, pip, logger
9
9
  ```
10
10
 
11
11
  ## 下载资源
@@ -43,7 +43,7 @@ class OCRResult(TypedDict):
43
43
  初始化 PP-OCRv5 模型,这是使用 OCR 功能的前提。
44
44
 
45
45
  ```python
46
- def loadV5(maxSideLen: int = 640) -> bool
46
+ def loadV5(maxSideLen: int = 640, useGpu: bool = False) -> bool
47
47
  ```
48
48
 
49
49
  **参数:**
@@ -51,12 +51,15 @@ def loadV5(maxSideLen: int = 640) -> bool
51
51
  | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
52
52
  | ------------ | ---- | -------- | ------ | -------------------------------- |
53
53
  | `maxSideLen` | int | 否 | 640 | 输入图像的最大边长,默认值为 640 |
54
+ | `useGpu` | bool | 否 | False | 是否启用 GPU 加速 |
54
55
 
55
56
  **返回值:**
56
57
 
57
- | 类型 | 描述 |
58
- | ------ | ---------------- |
59
- | `bool` | 是否成功加载模型 |
58
+ | 类型 | 描述 |
59
+ | ------ | --------------------------------------------------- |
60
+ | `bool` | 加载成功或模型已加载返回 `True`,否则返回 `False` |
61
+
62
+ 重复调用 `loadV5` 时,如果模型已经加载,会直接返回 `True`,不会重新加载或应用新的参数。需要更换加载参数时,先调用 `free()` 释放模型。
60
63
 
61
64
  **示例:**
62
65
 
@@ -134,6 +137,29 @@ else:
134
137
  print(f"网络图片识别结果数量: {len(url_results)}")
135
138
  ```
136
139
 
140
+ #### `recognizeAbs` - 执行 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标
141
+
142
+ 参数与 `recognize` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
143
+
144
+ ```python
145
+ def recognizeAbs(
146
+ input: str,
147
+ x: int = 0,
148
+ y: int = 0,
149
+ ex: int = 0,
150
+ ey: int = 0,
151
+ confidenceThreshold: float = 0.6
152
+ ) -> List[OCRResult]
153
+ ```
154
+
155
+ **示例:**
156
+
157
+ ```python
158
+ abs_results = paddleocr.recognizeAbs("screen", 100, 100, 500, 300)
159
+ if abs_results:
160
+ print(f"绝对坐标中心点: ({abs_results[0].centerX}, {abs_results[0].centerY})")
161
+ ```
162
+
137
163
  #### `findText` - 在识别结果中查找目标文本并返回对应子串坐标
138
164
 
139
165
  在 OCR 识别结果中查找指定文本,返回匹配文本的坐标和置信度等信息。
@@ -190,6 +216,30 @@ else:
190
216
  print(f"区域命中数量: {len(region_hits)}")
191
217
  ```
192
218
 
219
+ #### `findTextAbs` - 查找目标文本,并将结果坐标映射为原图/全屏绝对坐标
220
+
221
+ 参数与 `findText` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
222
+
223
+ ```python
224
+ def findTextAbs(
225
+ input: str,
226
+ targetTexts: List[str],
227
+ x: int = 0,
228
+ y: int = 0,
229
+ ex: int = 0,
230
+ ey: int = 0,
231
+ confidenceThreshold: float = 0.6
232
+ ) -> List[OCRResult]
233
+ ```
234
+
235
+ **示例:**
236
+
237
+ ```python
238
+ abs_hits = paddleocr.findTextAbs("screen", ["确定"], 100, 100, 500, 400, 0.6)
239
+ if abs_hits:
240
+ print(f"绝对坐标中心点: ({abs_hits[0].centerX}, {abs_hits[0].centerY})")
241
+ ```
242
+
193
243
  ### 资源管理
194
244
 
195
245
  #### `free` - 释放 OCR 模型占用的内存资源
@@ -1,12 +1,14 @@
1
1
  # 悬浮窗模块 (PIP)
2
2
 
3
- 悬浮窗模块提供画中画(Picture in Picture)日志窗口能力。
3
+ 悬浮窗模块提供 iOS 画中画(Picture in Picture)悬浮窗能力,可用于显示脚本日志、保活提示或脚本自定义文本。
4
4
 
5
5
  ## 功能特性
6
6
 
7
- - **模式切换**:切换日志、保活和关闭三种悬浮窗模式
7
+ - **显示模式**:支持日志、保活和自定义三种显示模式
8
+ - **关闭控制**:支持主动关闭悬浮窗
8
9
  - **状态查询**:判断悬浮窗是否正在显示
9
- - **识别标记**:日志窗口左上角默认显示高对比标记,可用于截图识别悬浮窗位置
10
+ - **尺寸设置**:日志模式和自定义模式支持设置内容宽高,并按模式分别持久化
11
+ - **自定义文本**:自定义模式支持文本、换行、文字颜色、背景色和文字大小
10
12
 
11
13
  ## API 参考
12
14
 
@@ -35,7 +37,7 @@ if pip.isPipActive():
35
37
 
36
38
  ### switchToLogMode - 切换到日志模式
37
39
 
38
- 切换到日志模式并尝试显示悬浮窗日志窗口。首次显示悬浮窗时 App 必须在前台。
40
+ 切换到日志模式并尝试显示悬浮窗日志窗口。首次显示悬浮窗时 App 必须在前台。日志模式会恢复最近一次保存的日志窗口尺寸。
39
41
 
40
42
  ```python
41
43
  def switchToLogMode() -> bool
@@ -58,7 +60,7 @@ success = pip.switchToLogMode()
58
60
 
59
61
  ### switchToKeepAliveMode - 切换到保活模式
60
62
 
61
- 切换到保活模式并尝试显示极小高度悬浮窗。首次显示悬浮窗时 App 必须在前台。
63
+ 切换到保活模式并尝试显示极小高度悬浮窗。首次显示悬浮窗时 App 必须在前台。保活模式不接受脚本尺寸设置。
62
64
 
63
65
  ```python
64
66
  def switchToKeepAliveMode() -> bool
@@ -79,12 +81,12 @@ utils.takeMeToFront()
79
81
  success = pip.switchToKeepAliveMode()
80
82
  ```
81
83
 
82
- ### switchToOffMode - 切换到关闭模式
84
+ ### switchToCustomMode - 切换到自定义模式
83
85
 
84
- 切换到关闭模式并关闭悬浮窗。
86
+ 切换到自定义模式并显示脚本设置的自定义文本。首次显示悬浮窗时 App 必须在前台。自定义模式会恢复最近一次保存的自定义窗口尺寸。
85
87
 
86
88
  ```python
87
- def switchToOffMode() -> bool
89
+ def switchToCustomMode() -> bool
88
90
  ```
89
91
 
90
92
  **返回值:**
@@ -95,10 +97,185 @@ def switchToOffMode() -> bool
95
97
 
96
98
  **示例:**
97
99
 
100
+ ```python
101
+ from kuaijs import pip, utils
102
+
103
+ utils.takeMeToFront()
104
+ pip.switchToCustomMode()
105
+ pip.setCustomText("运行中\n进度 1/3")
106
+ pip.setCustomTextColor("#34c759")
107
+ pip.setCustomTextSize(18)
108
+ ```
109
+
110
+ ### closeWindow - 关闭悬浮窗
111
+
112
+ 关闭悬浮窗。
113
+
114
+ ```python
115
+ def closeWindow() -> bool
116
+ ```
117
+
118
+ **返回值:**
119
+
120
+ | 类型 | 描述 |
121
+ | ------ | --------------------- |
122
+ | `bool` | `True` 代表已提交请求 |
123
+
124
+ **示例:**
125
+
126
+ ```python
127
+ from kuaijs import pip
128
+
129
+ success = pip.closeWindow()
130
+ ```
131
+
132
+ ### setContentSize - 设置内容尺寸
133
+
134
+ 设置日志模式或自定义模式的悬浮窗内容尺寸。宽度和高度都必须传入有效数字。日志模式和自定义模式会分别保存尺寸;悬浮窗关闭状态和保活模式不会生效。
135
+
136
+ ```python
137
+ def setContentSize(width: float, height: float) -> bool
138
+ ```
139
+
140
+ **参数:**
141
+
142
+ | 参数 | 类型 | 必填 | 描述 |
143
+ | -------- | ---------------- | ---- | ----------------------------- |
144
+ | `width` | `float` | 是 | 目标内容宽度 |
145
+ | `height` | `float` | 是 | 目标内容高度 |
146
+
147
+ **返回值:**
148
+
149
+ | 类型 | 描述 |
150
+ | ------ | ------------------------------------------------------------------- |
151
+ | `bool` | `True` 代表尺寸已提交;`False` 代表当前模式不允许设置或宽高无效 |
152
+
153
+ **示例:**
154
+
98
155
  ```python
99
156
  from kuaijs import pip
100
157
 
101
- success = pip.switchToOffMode()
158
+ pip.switchToLogMode()
159
+ pip.setContentSize(280, 120)
160
+
161
+ pip.switchToCustomMode()
162
+ pip.setContentSize(120, 180)
163
+ ```
164
+
165
+ ### setCustomText - 设置自定义文本
166
+
167
+ 设置自定义模式显示的纯文本内容。该方法只更新自定义文本数据,不会自动切换到自定义模式。
168
+
169
+ ```python
170
+ def setCustomText(text: str) -> bool
171
+ ```
172
+
173
+ **参数:**
174
+
175
+ | 参数 | 类型 | 必填 | 描述 |
176
+ | ------ | ----- | ---- | ------------------------------------------- |
177
+ | `text` | `str` | 是 | 要显示的文本,支持真实换行和字符串中的 `\n` |
178
+
179
+ **返回值:**
180
+
181
+ | 类型 | 描述 |
182
+ | ------ | --------------------- |
183
+ | `bool` | `True` 代表文本已提交 |
184
+
185
+ **示例:**
186
+
187
+ ```python
188
+ from kuaijs import pip
189
+
190
+ pip.setCustomText("运行中\n进度 1/3")
191
+ pip.switchToCustomMode()
192
+ ```
193
+
194
+ ### setCustomTextColor - 设置自定义文字颜色
195
+
196
+ 设置自定义模式显示文本的文字颜色。该方法只更新文字颜色数据,不会自动切换到自定义模式。
197
+
198
+ ```python
199
+ def setCustomTextColor(color: str) -> bool
200
+ ```
201
+
202
+ **参数:**
203
+
204
+ | 参数 | 类型 | 必填 | 描述 |
205
+ | ------- | ----- | ---- | ---------------------------------------------------------- |
206
+ | `color` | `str` | 是 | 文字颜色,支持 `RRGGBB`、`RRGGBBAA`,可带 `#` 前缀;末尾 AA 为透明度;无效值使用白色 |
207
+
208
+ **返回值:**
209
+
210
+ | 类型 | 描述 |
211
+ | ------ | ------------------------- |
212
+ | `bool` | `True` 代表文字颜色已提交 |
213
+
214
+ **示例:**
215
+
216
+ ```python
217
+ from kuaijs import pip
218
+
219
+ pip.setCustomTextColor("#34c759")
220
+ pip.switchToCustomMode()
221
+ ```
222
+
223
+ ### setCustomTextSize - 设置自定义文字大小
224
+
225
+ 设置自定义模式显示文本的文字大小。该方法只更新文字大小数据,不会自动切换到自定义模式。
226
+
227
+ ```python
228
+ def setCustomTextSize(fontSize: float) -> bool
229
+ ```
230
+
231
+ **参数:**
232
+
233
+ | 参数 | 类型 | 必填 | 描述 |
234
+ | ---------- | ------- | ---- | -------------------------- |
235
+ | `fontSize` | `float` | 是 | 文字字号,必须是有效数字 |
236
+
237
+ **返回值:**
238
+
239
+ | 类型 | 描述 |
240
+ | ------ | ----------------------------------------------------- |
241
+ | `bool` | `True` 代表文字大小已提交;`False` 代表字号无效 |
242
+
243
+ **示例:**
244
+
245
+ ```python
246
+ from kuaijs import pip
247
+
248
+ pip.setCustomTextSize(18)
249
+ pip.switchToCustomMode()
250
+ ```
251
+
252
+ ### setCustomBackgroundColor - 设置自定义背景色
253
+
254
+ 设置自定义模式显示区域的背景色。该方法只更新背景色数据,不会自动切换到自定义模式。
255
+
256
+ ```python
257
+ def setCustomBackgroundColor(color: str) -> bool
258
+ ```
259
+
260
+ **参数:**
261
+
262
+ | 参数 | 类型 | 必填 | 描述 |
263
+ | ------- | ----- | ---- | ---------------------------------------------------------- |
264
+ | `color` | `str` | 是 | 背景颜色,支持 `RRGGBB`、`RRGGBBAA`,可带 `#` 前缀;末尾 AA 为透明度;无效值使用黑色 |
265
+
266
+ **返回值:**
267
+
268
+ | 类型 | 描述 |
269
+ | ------ | ----------------------- |
270
+ | `bool` | `True` 代表背景色已提交 |
271
+
272
+ **示例:**
273
+
274
+ ```python
275
+ from kuaijs import pip
276
+
277
+ pip.setCustomBackgroundColor("#111111")
278
+ pip.switchToCustomMode()
102
279
  ```
103
280
 
104
281
  ## 完整使用示例
@@ -107,15 +284,25 @@ success = pip.switchToOffMode()
107
284
  from kuaijs import pip, utils
108
285
 
109
286
  utils.takeMeToFront()
287
+
110
288
  pip.switchToLogMode()
289
+ pip.setContentSize(280, 120)
290
+
291
+ pip.setCustomText("任务运行中\n1/3")
292
+ pip.setCustomTextColor("#34c759")
293
+ pip.setCustomTextSize(18)
294
+ pip.setCustomBackgroundColor("#111111")
295
+ pip.switchToCustomMode()
296
+ pip.setContentSize(120, 180)
111
297
  ```
112
298
 
113
299
  ## 注意事项
114
300
 
115
- 1. **前台限制**:首次切换到日志模式或保活模式并启动悬浮窗时,App 必须在前台;悬浮窗已启动后可以继续切换日志/保活模式
301
+ 1. **前台限制**:首次切换到日志、保活或自定义显示模式并启动悬浮窗时,App 必须在前台;悬浮窗已启动后可以继续切换显示模式或关闭悬浮窗
116
302
  2. **设备兼容性**:仅支持 iOS 15+ 且具备画中画功能的设备
117
303
  3. **系统限制**:悬浮窗位置和实际显示尺寸由 iOS 管理
118
- 4. **识别标记**:日志窗口左上角默认包含识别标记,便于通过截图识别悬浮窗位置
304
+ 4. **尺寸持久化**:日志模式和自定义模式分别保存尺寸,互不共用;保活模式不接受脚本尺寸
305
+ 5. **竖向文本**:自定义窗口高度大于宽度时,文本会按逐字符换行方式竖向显示
119
306
 
120
307
  ## 故障排除
121
308
 
@@ -124,3 +311,8 @@ pip.switchToLogMode()
124
311
  - 确认设备支持悬浮窗功能
125
312
  - 检查悬浮窗权限是否已开启
126
313
  - 确认应用当前在前台
314
+
315
+ ### setContentSize 返回 False
316
+
317
+ - 确认当前模式是日志模式或自定义模式
318
+ - 确认宽度和高度都传入了有效数字
@@ -65,7 +65,7 @@ class YoloResult(TypedDict):
65
65
  加载模型是使用目标检测功能的前提。
66
66
 
67
67
  ```python
68
- def load(paramPath: str, binPath: str, nc: int, version: int = 11) -> Optional[str]
68
+ def load(paramPath: str, binPath: str, nc: int = 0, version: int = 11, useGpu: bool = False) -> Optional[str]
69
69
  ```
70
70
 
71
71
  **参数:**
@@ -74,8 +74,9 @@ def load(paramPath: str, binPath: str, nc: int, version: int = 11) -> Optional[s
74
74
  | ----------- | ---- | -------- | ------ | ------------------------------------------- |
75
75
  | `paramPath` | str | 是 | - | NCNN 模型的 param 文件绝对路径 |
76
76
  | `binPath` | str | 是 | - | NCNN 模型的 bin 文件绝对路径 |
77
- | `nc` | int | | - | 模型的标签数量(在标签集 data.yaml 中查看) |
77
+ | `nc` | int | | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空列表 |
78
78
  | `version` | int | 否 | 11 | YOLO 模型版本号(仅支持 8/11/26) |
79
+ | `useGpu` | bool | 否 | False | 是否启用 GPU 加速 |
79
80
 
80
81
  **返回值:**
81
82
 
@@ -92,8 +93,9 @@ from kuaijs import yolo
92
93
  model_id = yolo.load(
93
94
  "yolov8n_ncnn_model/model.ncnn.param",
94
95
  "yolov8n_ncnn_model/model.ncnn.bin",
95
- 80,
96
+ 0,
96
97
  8,
98
+ False,
97
99
  )
98
100
  ```
99
101
 
@@ -102,7 +104,7 @@ model_id = yolo.load(
102
104
  加载模型是使用目标检测功能的前提。
103
105
 
104
106
  ```python
105
- def loadV11(paramPath: str, binPath: str, nc: int) -> Optional[str]
107
+ def loadV11(paramPath: str, binPath: str, nc: int = 0, useGpu: bool = False) -> Optional[str]
106
108
  ```
107
109
 
108
110
  **参数:**
@@ -111,7 +113,8 @@ def loadV11(paramPath: str, binPath: str, nc: int) -> Optional[str]
111
113
  | ----------- | ---- | -------- | ------ | ------------------------------------------- |
112
114
  | `paramPath` | str | 是 | - | NCNN 模型的 param 文件绝对路径 |
113
115
  | `binPath` | str | 是 | - | NCNN 模型的 bin 文件绝对路径 |
114
- | `nc` | int | | - | 模型的标签数量(在标签集 data.yaml 中查看) |
116
+ | `nc` | int | | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空列表 |
117
+ | `useGpu` | bool | 否 | False | 是否启用 GPU 加速 |
115
118
 
116
119
  **返回值:**
117
120
 
@@ -129,7 +132,8 @@ from kuaijs import yolo
129
132
  model_id = yolo.loadV11(
130
133
  "yolo11n_ncnn_model/model.ncnn.param",
131
134
  "yolo11n_ncnn_model/model.ncnn.bin",
132
- 80 # COCO 数据集有 80 个类别
135
+ 0, # 自动根据模型输出推断类别数量
136
+ False,
133
137
  )
134
138
 
135
139
  if model_id:
@@ -176,7 +180,7 @@ def detect(
176
180
  from kuaijs import yolo
177
181
 
178
182
  # 首先加载模型
179
- mid = yolo.loadV11("yolo11n_ncnn_model/model.ncnn.param", "yolo11n_ncnn_model/model.ncnn.bin", 80)
183
+ mid = yolo.loadV11("yolo11n_ncnn_model/model.ncnn.param", "yolo11n_ncnn_model/model.ncnn.bin", 0)
180
184
 
181
185
  if not mid:
182
186
  print("模型加载失败")
@@ -227,6 +231,32 @@ else:
227
231
  print(f"网络图片检测结果: {len(url_results)} 个物体")
228
232
  ```
229
233
 
234
+ #### detectAbs - 对指定区域执行目标检测,并将结果坐标映射为原图/全屏绝对坐标
235
+
236
+ ```python
237
+ def detectAbs(
238
+ modelId: str,
239
+ img: str,
240
+ x: int = 0,
241
+ y: int = 0,
242
+ ex: int = 0,
243
+ ey: int = 0,
244
+ targetSize: int = 640,
245
+ threshold: float = 0.4,
246
+ nmsThreshold: float = 0.5
247
+ ) -> List[YoloResult]
248
+ ```
249
+
250
+ **示例:**
251
+
252
+ ```python
253
+ from kuaijs import yolo, action
254
+
255
+ abs_results = yolo.detectAbs(mid, "screen", 100, 100, 500, 400, 640, 0.4, 0.5)
256
+ if abs_results:
257
+ action.click(abs_results[0]["centerX"], abs_results[0]["centerY"])
258
+ ```
259
+
230
260
  ### 资源管理
231
261
 
232
262
  #### free - 释放指定模型