ms-vite-plugin 1.1.2 → 1.1.4

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.
Files changed (94) hide show
  1. package/dist/build.js +6 -0
  2. package/dist/cli.js +91 -1
  3. package/dist/mcp/device-config.d.ts +55 -0
  4. package/dist/mcp/device-config.js +183 -0
  5. package/dist/mcp/docs-service.d.ts +65 -0
  6. package/dist/mcp/docs-service.js +168 -0
  7. package/dist/mcp/project.d.ts +16 -0
  8. package/dist/mcp/project.js +74 -0
  9. package/dist/mcp/tools.d.ts +18 -0
  10. package/dist/mcp/tools.js +825 -0
  11. package/dist/mcp/types.d.ts +32 -0
  12. package/dist/mcp/types.js +11 -0
  13. package/dist/mcp-server.d.ts +2 -0
  14. package/dist/mcp-server.js +86 -0
  15. package/dist/project.d.ts +89 -0
  16. package/dist/project.js +306 -0
  17. package/dist/version.d.ts +12 -0
  18. package/dist/version.js +63 -0
  19. package/docs/api/action.md +922 -0
  20. package/docs/api/appleocr.md +229 -0
  21. package/docs/api/config.md +122 -0
  22. package/docs/api/cryptoUtils.md +232 -0
  23. package/docs/api/device.md +374 -0
  24. package/docs/api/file.md +516 -0
  25. package/docs/api/global.md +617 -0
  26. package/docs/api/hid.md +1032 -0
  27. package/docs/api/hotUpdate.md +166 -0
  28. package/docs/api/http.md +548 -0
  29. package/docs/api/image.md +907 -0
  30. package/docs/api/ime.md +290 -0
  31. package/docs/api/logger.md +324 -0
  32. package/docs/api/media.md +248 -0
  33. package/docs/api/mysql.md +441 -0
  34. package/docs/api/netCard.md +200 -0
  35. package/docs/api/node.md +353 -0
  36. package/docs/api/paddleocr.md +246 -0
  37. package/docs/api/pip.md +242 -0
  38. package/docs/api/system.md +572 -0
  39. package/docs/api/thread.md +269 -0
  40. package/docs/api/tomatoocr.md +425 -0
  41. package/docs/api/tts.md +334 -0
  42. package/docs/api/ui.md +947 -0
  43. package/docs/api/utils.md +265 -0
  44. package/docs/api/yolo.md +310 -0
  45. package/docs/apicn/action.md +919 -0
  46. package/docs/apicn/appleocr.md +233 -0
  47. package/docs/apicn/config.md +120 -0
  48. package/docs/apicn/device.md +385 -0
  49. package/docs/apicn/file.md +511 -0
  50. package/docs/apicn/global.md +613 -0
  51. package/docs/apicn/hid.md +1033 -0
  52. package/docs/apicn/hotUpdate.md +170 -0
  53. package/docs/apicn/http.md +672 -0
  54. package/docs/apicn/image.md +924 -0
  55. package/docs/apicn/ime.md +290 -0
  56. package/docs/apicn/logger.md +332 -0
  57. package/docs/apicn/media.md +252 -0
  58. package/docs/apicn/mysql.md +445 -0
  59. package/docs/apicn/netCard.md +200 -0
  60. package/docs/apicn/node.md +362 -0
  61. package/docs/apicn/paddleocr.md +255 -0
  62. package/docs/apicn/pip.md +242 -0
  63. package/docs/apicn/system.md +575 -0
  64. package/docs/apicn/thread.md +269 -0
  65. package/docs/apicn/tts.md +338 -0
  66. package/docs/apicn/ui.md +933 -0
  67. package/docs/apicn/utils.md +265 -0
  68. package/docs/apicn/yolo.md +314 -0
  69. package/docs/apipython/action.md +901 -0
  70. package/docs/apipython/appleocr.md +226 -0
  71. package/docs/apipython/config.md +126 -0
  72. package/docs/apipython/cryptoUtils.md +246 -0
  73. package/docs/apipython/device.md +365 -0
  74. package/docs/apipython/file.md +476 -0
  75. package/docs/apipython/g.md +154 -0
  76. package/docs/apipython/hid.md +1059 -0
  77. package/docs/apipython/hotUpdate.md +154 -0
  78. package/docs/apipython/image.md +938 -0
  79. package/docs/apipython/ime.md +306 -0
  80. package/docs/apipython/logger.md +330 -0
  81. package/docs/apipython/media.md +221 -0
  82. package/docs/apipython/mysql.md +432 -0
  83. package/docs/apipython/netCard.md +219 -0
  84. package/docs/apipython/node.md +331 -0
  85. package/docs/apipython/overview.md +66 -0
  86. package/docs/apipython/paddleocr.md +211 -0
  87. package/docs/apipython/pip.md +231 -0
  88. package/docs/apipython/system.md +458 -0
  89. package/docs/apipython/tomatoocr.md +444 -0
  90. package/docs/apipython/tts.md +331 -0
  91. package/docs/apipython/ui.md +949 -0
  92. package/docs/apipython/utils.md +284 -0
  93. package/docs/apipython/yolo.md +281 -0
  94. package/package.json +8 -4
@@ -0,0 +1,938 @@
1
+ # 图片模块 (Image)
2
+
3
+ 图片模块提供了强大的图像处理功能,包括截图、图像识别、模板匹配、颜色查找、图像变换等。
4
+
5
+ 注意所有的 `imageId` 都需要在使用后释放,否则会导致内存泄漏。
6
+
7
+ 所有传递`imageId`的函数都可以使用`"screen"`作为参数,来表示对当前屏幕进行操作。
8
+
9
+ `"screen"` 在设置为`Agent`模式,使用`快点Agent`截图,录屏模式使用录屏截图。
10
+
11
+ 所有传递`imageId`的函数都可以使用`"shortcut"`作为参数,来表示指定 HID 快捷指令截图
12
+
13
+ 所有传递`imageId`的函数都可以使用`"actionScreenshot"`作为参数,来表示指定 HID 快捷键系统截图
14
+
15
+ 所有传递`imageId`的函数都可以使用图片路径作为参数,来表示对指定图片进行操作,支持 res 目录文件,和手机文件路径。
16
+
17
+ ## 图片获取与管理
18
+
19
+ ### captureScreen - 截取屏幕
20
+
21
+ ```python
22
+ def captureScreen(x: Optional[int] = 0, y: Optional[int] = 0, ex: Optional[int] = 0, ey: Optional[int] = 0) -> Optional[str]
23
+ ```
24
+
25
+ **参数:**
26
+
27
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
28
+ | ------ | ------ | -------- | ------ | ----------------- |
29
+ | `x` | number | 否 | 0 | 区域左上角 X 坐标 |
30
+ | `y` | number | 否 | 0 | 区域左上角 Y 坐标 |
31
+ | `ex` | number | 否 | 0 | 区域右下角 X 坐标 |
32
+ | `ey` | number | 否 | 0 | 区域右下角 Y 坐标 |
33
+
34
+ **返回值:**
35
+
36
+ | 类型 | 描述 |
37
+ | ------------- | -------------------------------- |
38
+ | `str \| None` | 截图的图片 ID,失败时返回 `None` |
39
+
40
+ **示例:**
41
+
42
+ ```python
43
+ # 截取全屏
44
+ imageId = image.captureScreen()
45
+ # 获取手机文档目录
46
+ dir = file.getInternalDir("documents")
47
+ if imageId:
48
+ print("截图成功")
49
+ image.saveTo(imageId, f"{dir}/screenshot.jpg")
50
+ image.release(imageId) # 记得释放内存
51
+ else:
52
+ print("截图失败")
53
+
54
+ # 截取指定区域
55
+ imageId = image.captureScreen(100, 100, 200, 200)
56
+ # 获取手机文档目录
57
+ dir = file.getInternalDir("documents")
58
+ if imageId:
59
+ print("截图成功")
60
+ image.saveTo(imageId, f"{dir}/screenshot.jpg")
61
+ image.release(imageId) # 记得释放内存
62
+ else:
63
+ print("截图失败")
64
+ ```
65
+
66
+ ### captureFullScreen - 截取设备全屏。
67
+
68
+ ```python
69
+ def captureFullScreen() -> Optional[str]
70
+ ```
71
+
72
+ **返回值:**
73
+
74
+ | 类型 | 描述 |
75
+ | ------------- | -------------------------------- |
76
+ | `str \| None` | 截图的图片 ID,失败时返回 `None` |
77
+
78
+ **示例:**
79
+
80
+ ```python
81
+ from kuaijs import image, file
82
+
83
+ imageId = image.captureFullScreen()
84
+ # 获取手机文档目录
85
+ dir_path = file.getInternalDir("documents")
86
+ if imageId:
87
+ print("截图成功")
88
+ image.saveTo(imageId, f"{dir_path}/screenshot.jpg")
89
+ image.release(imageId) # 记得释放内存
90
+ else:
91
+ print("截图失败")
92
+ ```
93
+
94
+ ### captureRect - 截取设备指定区域。
95
+
96
+ ```python
97
+ def captureRect(x: int, y: int, ex: int, ey: int) -> Optional[str]
98
+ ```
99
+
100
+ **参数:**
101
+
102
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
103
+ | ----------- | ---- | -------- | ------ | -------------- |
104
+ | `x,y,ex,ey` | int | 是 | <br /> | 左上与右下坐标 |
105
+
106
+ **返回值:**
107
+
108
+ | 类型 | 描述 |
109
+ | ------------- | -------------------------------- |
110
+ | `str \| None` | 截图的图片 ID,失败时返回 `None` |
111
+
112
+ **示例:**
113
+
114
+ ```python
115
+ from kuaijs import image
116
+
117
+ imageId = image.captureRect(100, 100, 200, 200)
118
+ if imageId:
119
+ print("截图成功")
120
+ image.saveTo(imageId, "rect.jpg")
121
+ image.release(imageId)
122
+ else:
123
+ print("截图失败")
124
+ ```
125
+
126
+ ### readImage - 从文件路径或imageId读取图片。
127
+
128
+ ```python
129
+ def readImage(path: str) -> Optional[str]
130
+ ```
131
+
132
+ **参数:**
133
+
134
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
135
+ | ------ | ---- | -------- | ------ | ----------------------------------------------------------------------- |
136
+ | `path` | str | 是 | <br /> | 图片文件路径 支持 res 目录文件和手机文件绝对路径,支持特殊标识的imageId |
137
+
138
+ **返回值:**
139
+
140
+ | 类型 | 描述 |
141
+ | ------------- | -------------------------- |
142
+ | `str \| None` | 图片 ID,失败时返回 `None` |
143
+
144
+ **示例:**
145
+
146
+ ```python
147
+ from kuaijs import image
148
+
149
+ imageId = image.readImage("template.jpg")
150
+ if imageId:
151
+ print("图片读取成功")
152
+ # 使用图片...
153
+ image.release(imageId)
154
+ else:
155
+ print("图片读取失败")
156
+ ```
157
+
158
+ ### saveTo - 保存图片到指定路径。
159
+
160
+ ```python
161
+ def saveTo(id: str, path: str) -> bool
162
+ ```
163
+
164
+ **参数:**
165
+
166
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
167
+ | ------ | ---- | -------- | ------ | -------- |
168
+ | `id` | str | 是 | <br /> | 图片 ID |
169
+ | `path` | str | 是 | <br /> | 保存路径 |
170
+
171
+ **返回值:**
172
+
173
+ | 类型 | 描述 |
174
+ | ------ | ------------------------------------- |
175
+ | `bool` | `True` 表示保存成功,`False` 表示失败 |
176
+
177
+ **示例:**
178
+
179
+ ```python
180
+ from kuaijs import image, file
181
+
182
+ imageId = image.captureFullScreen()
183
+ # 获取手机文档目录
184
+ dir_path = file.getInternalDir("documents")
185
+ if imageId:
186
+ image.saveTo(imageId, f"{dir_path}/screenshot.jpg")
187
+ image.release(imageId)
188
+ ```
189
+
190
+ ## 内存管理
191
+
192
+ ### release - 释放单个图片的内存。
193
+
194
+ ```python
195
+ def release(id: str) -> None
196
+ ```
197
+
198
+ **参数:**
199
+
200
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
201
+ | ------ | ---- | -------- | ------ | --------------- |
202
+ | `id` | str | 是 | <br /> | 要释放的图片 ID |
203
+
204
+ ### releaseAll - 释放所有图片的内存。
205
+
206
+ ```python
207
+ def releaseAll() -> None
208
+ ```
209
+
210
+ ### isRelease - 检查图片是否已被释放。
211
+
212
+ ```python
213
+ def isRelease(id: str) -> bool
214
+ ```
215
+
216
+ **参数:**
217
+
218
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
219
+ | ------ | ---- | -------- | ------ | ------- |
220
+ | `id` | str | 是 | <br /> | 图片 ID |
221
+
222
+ **返回值:**
223
+
224
+ | 类型 | 描述 |
225
+ | ------ | ------------------------------------- |
226
+ | `bool` | `True` 表示已释放,`False` 表示未释放 |
227
+
228
+ **示例:**
229
+
230
+ ```python
231
+ from kuaijs import image
232
+
233
+ imageId = image.captureFullScreen()
234
+ if imageId:
235
+ print(f"释放前: {image.isRelease(imageId)}") # False
236
+ image.release(imageId)
237
+ print(f"释放后: {image.isRelease(imageId)}") # True
238
+ ```
239
+
240
+ ## 图片信息
241
+
242
+ ### getSize - 获取图片尺寸。
243
+
244
+ ```python
245
+ from typing import TypedDict, Optional
246
+
247
+ class Size(TypedDict):
248
+ width: int
249
+ height: int
250
+
251
+ def getSize(id: str) -> Optional[Size]
252
+ ```
253
+
254
+ **参数:**
255
+
256
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
257
+ | ------ | ---- | -------- | ------ | ------- |
258
+ | `id` | str | 是 | <br /> | 图片 ID |
259
+
260
+ **返回值:**
261
+
262
+ | 类型 | 描述 |
263
+ | -------------- | -------------------------------------------------------------- |
264
+ | `Size \| None` | 图片尺寸对象,包含 `width` 和 `height` 属性,失败时返回 `None` |
265
+
266
+ **示例:**
267
+
268
+ ```python
269
+ from kuaijs import image
270
+
271
+ imageId = image.captureFullScreen()
272
+ if imageId:
273
+ size = image.getSize(imageId)
274
+ if size:
275
+ print(f"图片尺寸: {size.width} x {size.height}")
276
+ image.release(imageId)
277
+ ```
278
+
279
+ ### pixel - 获取图片指定坐标的像素颜色值。
280
+
281
+ ```python
282
+ def pixel(id: str, x: int, y: int) -> int
283
+ ```
284
+
285
+ **参数:**
286
+
287
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
288
+ | ------ | ---- | -------- | ------ | ------- |
289
+ | `id` | str | 是 | <br /> | 图片 ID |
290
+ | `x,y` | int | 是 | <br /> | 坐标 |
291
+
292
+ **返回值:**
293
+
294
+ | 类型 | 描述 |
295
+ | ----- | -------------- |
296
+ | `int` | 颜色值(整型) |
297
+
298
+ **示例:**
299
+
300
+ ```python
301
+ from kuaijs import image
302
+
303
+ imageId = image.captureFullScreen()
304
+ if imageId:
305
+ color = image.pixel(imageId, 100, 100)
306
+ colorHex = image.argb(color)
307
+ print(f"坐标 (100, 100) 的颜色: {colorHex}")
308
+ image.release(imageId)
309
+ ```
310
+
311
+ ### argb - 将整型颜色值转换为 16 进制 RGB 字符串。
312
+
313
+ ```python
314
+ def argb(color: int) -> str
315
+ ```
316
+
317
+ **参数:**
318
+
319
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
320
+ | ------- | ---- | -------- | ------ | ---------- |
321
+ | `color` | int | 是 | <br /> | 整型颜色值 |
322
+
323
+ **返回值:**
324
+
325
+ | 类型 | 描述 |
326
+ | ----- | ------------------ |
327
+ | `str` | 16 进制 RGB 字符串 |
328
+
329
+ ## 颜色识别
330
+
331
+ ### findColor - 单点找色
332
+
333
+ ```python
334
+ def findColor(id: str, color: str, threshold: float, x: int, y: int, ex: int, ey: int, limit: int, orz: int) -> List[Point]
335
+ ```
336
+
337
+ **参数:**
338
+
339
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
340
+ | ----------- | ----- | -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
341
+ | `id` | str | 是 | <br /> | 图片 ID |
342
+ | `color` | str | 是 | <br /> | 颜色值,支持 "主色-偏色" 格式,如 "#6DD1E6-#101010" |
343
+ | `threshold` | float | 是 | <br /> | 颜色匹配阈值 (0.0-1.0) |
344
+ | `x,y,ex,ey` | int | 是 | <br /> | 搜索区域左上与右下坐标 |
345
+ | `limit` | int | 是 | <br /> | 最大查找数量 |
346
+ | `orz` | int | 是 | <br /> | 查找方向(1-8) 1 左上角到右下角,纵向开始 2 左上角到右下角,横向开始 3 右上角到左下角,横向开始 4 右上角到左下角,纵向开始 5 右下角到左上角,纵向开始 6 右下角到左上角,横向开始 7 左下角到右上角,横向开始 8 左下角到右上角,纵向开始 |
347
+
348
+ **返回值:**
349
+
350
+ | 类型 | 描述 |
351
+ | ------------- | ---------------------------------------------- |
352
+ | `List[Point]` | 找到的颜色点数组,每个元素包含 `x` 和 `y` 属性 |
353
+
354
+ **示例:**
355
+
356
+ ```python
357
+ from kuaijs import image, action
358
+
359
+ imageId = image.captureFullScreen()
360
+ if imageId:
361
+ # 查找蓝色按钮
362
+ points = image.findColor(
363
+ imageId,
364
+ "#1E90FF-#101010", # 蓝色,允许一定偏差
365
+ 0.9, # 阈值
366
+ 0,
367
+ 0, # 搜索区域左上角
368
+ 400,
369
+ 800, # 搜索区域右下角
370
+ 5, # 最多找 5 个
371
+ 1 # 从左到右查找
372
+ )
373
+
374
+ if len(points) > 0:
375
+ print(f"找到 {len(points)} 个蓝色点")
376
+ # 点击第一个找到的点
377
+ action.click(points[0].x, points[0].y, 100, False)
378
+
379
+ image.release(imageId)
380
+ ```
381
+
382
+ ### findMultiColor - 多点找色
383
+
384
+ ```python
385
+ def findMultiColor(id: str, firstColor: str, threshold: float, points: str, x: int, y: int, ex: int, ey: int, limit: int, orz: int) -> List[Point]
386
+ ```
387
+
388
+ **参数:**
389
+
390
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
391
+ | ------------ | ----- | -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
392
+ | `id` | str | 是 | <br /> | 图片 ID |
393
+ | `firstColor` | str | 是 | <br /> | 第一个颜色 |
394
+ | `threshold` | float | 是 | <br /> | 颜色匹配阈值 (0.0-1.0) |
395
+ | `points` | str | 是 | <br /> | 其他颜色点的相对位置和颜色,格式:`x1\|y1\|color1-偏色,x2\|y2\|color2-偏色` |
396
+ | `x,y,ex,ey` | int | 是 | <br /> | 搜索区域左上与右下坐标 |
397
+ | `limit` | int | 是 | <br /> | 最大查找数量 |
398
+ | `orz` | int | 是 | <br /> | 查找方向(1-8) 1 左上角到右下角,纵向开始 2 左上角到右下角,横向开始 3 右上角到左下角,横向开始 4 右上角到左下角,纵向开始 5 右下角到左上角,纵向开始 6 右下角到左上角,横向开始 7 左下角到右上角,横向开始 8 左下角到右上角,纵向开始 |
399
+
400
+ **返回值:**
401
+
402
+ | 类型 | 描述 |
403
+ | ------------- | ---------------------------------------------- |
404
+ | `List[Point]` | 找到的颜色点数组,每个元素包含 `x` 和 `y` 属性 |
405
+
406
+ **示例:**
407
+
408
+ ```python
409
+ from kuaijs import image, action
410
+
411
+ imageId = image.captureFullScreen()
412
+ if imageId:
413
+ # 查找特定的颜色组合(如按钮的特征颜色)
414
+ points = image.findMultiColor(
415
+ imageId,
416
+ "#1E90FF-#101010", # 主颜色
417
+ 0.9, # 阈值
418
+ "10|0|#FFFFFF-#101010,20|0|#000000-#101010", # 相对位置的其他颜色
419
+ 0,
420
+ 0,
421
+ 400,
422
+ 800,
423
+ 1,
424
+ 1
425
+ )
426
+
427
+ if len(points) > 0:
428
+ print("找到匹配的颜色组合")
429
+ action.click(points[0].x, points[0].y, 100, False)
430
+
431
+ image.release(imageId)
432
+ ```
433
+
434
+ ### cmpColor - 多点比色
435
+
436
+ ```python
437
+ def cmpColor(id: str, points: str, threshold: float) -> bool
438
+ ```
439
+
440
+ **参数:**
441
+
442
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
443
+ | ----------- | ----- | -------- | ------ | --------------------------------------------------------------------------- |
444
+ | `id` | str | 是 | <br /> | 图片 ID |
445
+ | `points` | str | 是 | <br /> | 其他颜色点的相对位置和颜色,格式:`x1\|y1\|color1-偏色,x2\|y2\|color2-偏色` |
446
+ | `threshold` | float | 是 | <br /> | 颜色匹配阈值 (0.0-1.0) |
447
+
448
+ **返回值:**
449
+
450
+ | 类型 | 描述 |
451
+ | ------ | ------------------------------------------- |
452
+ | `bool` | 如果颜色匹配则返回 `True`,否则返回 `False` |
453
+
454
+ **示例:**
455
+
456
+ ```python
457
+ from kuaijs import image
458
+
459
+ imageId = image.captureFullScreen()
460
+ if imageId:
461
+ # 检查特定区域是否为预期颜色
462
+ isMatch = image.cmpColor(
463
+ imageId,
464
+ "1|2|#6DD1E6-#101010",
465
+ 0.9 # 阈值
466
+ )
467
+
468
+ if isMatch:
469
+ print("颜色匹配")
470
+
471
+ image.release(imageId)
472
+ ```
473
+
474
+ ## 图像识别
475
+
476
+ ### findImage - 找图
477
+
478
+ ```python
479
+ def findImage(id: str, templateImageId: str, x: int, y: int, ex: int, ey: int, threshold: float, limit: int, method: int, rgb: bool = False, options: dict = {}) -> List[Rect]
480
+ ```
481
+
482
+ **参数:**
483
+
484
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
485
+ | ---------------------- | ------------ | -------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
486
+ | `imageId` | str | 是 | <br /> | `"screen"`-当前屏幕截图, `string`-图片文件路径或 URL ,`imageId`-图片 ID(通过 image 模块获取) |
487
+ | `templateImageId` | str | 是 | <br /> | `"screen"`-当前屏幕截图, `string`-图片文件路径或 URL ,`imageId`-图片 ID(通过 image 模块获取)支持按\|分割,多个图片按顺序查找 |
488
+ | `x, y` | int | 是 | <br /> | 搜索区域左上角坐标 |
489
+ | `ex, ey` | int | 是 | <br /> | 搜索区域右下角坐标 |
490
+ | `threshold` | float | 是 | <br /> | 匹配阈值 (0.0-1.0) 全分辨率匹配时建议 0.5-0.6 其他建议 0.9-0.995 |
491
+ | `limit` | int | 是 | <br /> | 最大查找数量,每个模板图片最多找 limit 个匹配结果 |
492
+ | `method` | int | 是 | <br /> | 匹配方法 0 SIFT 全分辨率 1 TM_SQDIFF_NORMED 3 TM_CCORR_NORMED 5 TM_CCOEFF_NORMED 99 全分辨率缩放匹配法 |
493
+ | `rgb` | bool | 否 | `False` | 是否使用 RGB 找图,默认 `False` 会自动转灰度找图 |
494
+ | `options` | dict | 否 | `{}` | 选项 |
495
+ | `options.scaleFactors` | list\[float] | 否 | `[1.0, 0.9, 1.1, 0.8, 1.2]` | 缩放匹配法缩放因子数组,默认 `[1.0, 0.9, 1.1, 0.8, 1.2]` 会在这些缩放比例下进行匹配。 |
496
+
497
+ **返回值:**
498
+
499
+ | 类型 | 描述 |
500
+ | ------------ | ------------------------------------------------------------------------------------------ |
501
+ | `List[Rect]` | 找到的匹配结果数组,每个元素包含位置、尺寸和置信度,其中 index 代表模板图片的索引从 0 开始 |
502
+
503
+ **示例:**
504
+
505
+ ```python
506
+ from kuaijs import image, action
507
+
508
+ matches = image.findImage(
509
+ "screen",
510
+ "template.jpg|template2.jpg",
511
+ 0,
512
+ 0,
513
+ 400,
514
+ 800, # 搜索区域
515
+ 0.8, # 80% 匹配度
516
+ 3, # 最多找 3 个
517
+ 5, # 匹配方法
518
+ False # 不使用 rgb 找图
519
+ )
520
+
521
+ if len(matches) > 0:
522
+ best = matches[0]
523
+ print(f"找到匹配,置信度: {best.confidence}")
524
+
525
+ # 点击匹配区域的中心
526
+ centerX = best.centerX
527
+ centerY = best.centerY
528
+ action.click(centerX, centerY, 100, False)
529
+ ```
530
+
531
+ ## 图像处理
532
+
533
+ ### clip - 裁剪图片。
534
+
535
+ ```python
536
+ def clip(id: str, x: int, y: int, ex: int, ey: int) -> Optional[str]
537
+ ```
538
+
539
+ **参数:**
540
+
541
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
542
+ | ----------- | ---- | -------- | ------ | ------------------ |
543
+ | `id` | str | 是 | <br /> | 原图片 ID |
544
+ | `x,y,ex,ey` | int | 是 | <br /> | 裁剪区域左上与右下 |
545
+
546
+ **返回值:**
547
+
548
+ | 类型 | 描述 |
549
+ | ------------- | ----------------- |
550
+ | `str \| None` | 裁剪后的新图片 ID |
551
+
552
+ **示例:**
553
+
554
+ ```python
555
+ from kuaijs import image, device, file
556
+
557
+ imageId = image.captureFullScreen()
558
+ # 获取手机文档目录
559
+ dir_path = file.getInternalDir("documents")
560
+ if imageId:
561
+ # 裁剪屏幕上半部分
562
+ screen = device.getScreenRealSize()
563
+ clippedId = image.clip(imageId, 0, 0, screen.width, screen.height // 2)
564
+
565
+ if clippedId:
566
+ image.saveTo(clippedId, f"{dir_path}/top_half.jpg")
567
+ image.release(clippedId)
568
+
569
+ image.release(imageId)
570
+ ```
571
+
572
+ ### rotateImage - 旋转图片。
573
+
574
+ ```python
575
+ def rotateImage(id: str, degree: int) -> Optional[str]
576
+ ```
577
+
578
+ **参数:**
579
+
580
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
581
+ | -------- | ---- | -------- | ------ | ----------------------------- |
582
+ | `id` | str | 是 | <br /> | 原图片 ID |
583
+ | `degree` | int | 是 | <br /> | 旋转角度,仅支持 90、-90、180 |
584
+
585
+ **返回值:**
586
+
587
+ | 类型 | 描述 |
588
+ | ------------- | ---------------------------------- |
589
+ | `str \| None` | 旋转后的新图片 ID;失败返回 `None` |
590
+
591
+ **示例:**
592
+
593
+ ```python
594
+ from kuaijs import image, file
595
+
596
+ imageId = image.readImage("photo.jpg")
597
+ # 获取手机文档目录
598
+ dir_path = file.getInternalDir("documents")
599
+ if imageId:
600
+ rotatedId = image.rotateImage(imageId, 90)
601
+ if rotatedId:
602
+ image.saveTo(rotatedId, f"{dir_path}/photo_rotated.jpg")
603
+ image.release(rotatedId)
604
+ image.release(imageId)
605
+ ```
606
+
607
+ ### gray - 将图片转换为灰度图。
608
+
609
+ ```python
610
+ def gray(id: str) -> Optional[str]
611
+ ```
612
+
613
+ **参数:**
614
+
615
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
616
+ | ------ | ---- | -------- | ------ | --------- |
617
+ | `id` | str | 是 | <br /> | 原图片 ID |
618
+
619
+ **返回值:**
620
+
621
+ | 类型 | 描述 |
622
+ | ------------- | ------------------- |
623
+ | `str \| None` | 灰度化后的新图片 ID |
624
+
625
+ **示例:**
626
+
627
+ ```python
628
+ from kuaijs import image, file
629
+
630
+ imageId = image.captureFullScreen()
631
+ # 获取手机文档目录
632
+ dir_path = file.getInternalDir("documents")
633
+ if imageId:
634
+ grayId = image.gray(imageId)
635
+ if grayId:
636
+ image.saveTo(grayId, f"{dir_path}/screenshot_gray.jpg")
637
+ image.release(grayId)
638
+ image.release(imageId)
639
+ ```
640
+
641
+ ### binaryzation - 将图片进行二值化处理。
642
+
643
+ ```python
644
+ def binaryzation(id: str, threshold: float) -> Optional[str]
645
+ ```
646
+
647
+ **参数:**
648
+
649
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
650
+ | ----------- | ----- | -------- | ------ | ---------------------- |
651
+ | `id` | str | 是 | <br /> | 原图片 ID |
652
+ | `threshold` | float | 是 | <br /> | 二值化阈值 (0.0-255.0) |
653
+
654
+ **返回值:**
655
+
656
+ | 类型 | 描述 |
657
+ | ------------- | ------------------- |
658
+ | `str \| None` | 二值化后的新图片 ID |
659
+
660
+ **示例:**
661
+
662
+ ```python
663
+ from kuaijs import image, file
664
+
665
+ imageId = image.captureFullScreen()
666
+ # 获取手机文档目录
667
+ dir_path = file.getInternalDir("documents")
668
+ if imageId:
669
+ binaryId = image.binaryzation(imageId, 128)
670
+ if binaryId:
671
+ image.saveTo(binaryId, f"{dir_path}/screenshot_binary.jpg")
672
+ image.release(binaryId)
673
+ image.release(imageId)
674
+ ```
675
+
676
+ ### drawRect - 绘制矩形。
677
+
678
+ ```python
679
+ def drawRect(id: str, x: int, y: int, ex: int, ey: int, color: str, thickness: int) -> None
680
+ ```
681
+
682
+ **参数:**
683
+
684
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
685
+ | ----------- | ---- | -------- | ------ | --------------------------- |
686
+ | `id` | str | 是 | <br /> | 原图片 ID |
687
+ | `x,y,ex,ey` | int | 是 | <br /> | 矩形左上与右下坐标 |
688
+ | `color` | str | 是 | <br /> | 颜色,如 `#FF0000` 表示红色 |
689
+ | `thickness` | int | 是 | <br /> | 线宽 |
690
+
691
+ **示例:**
692
+
693
+ ```python
694
+ from kuaijs import image, file
695
+
696
+ # 获取手机文档目录
697
+ dir_path = file.getInternalDir("documents")
698
+
699
+ imageId = image.captureFullScreen()
700
+ if imageId:
701
+ image.drawRect(imageId, 100, 100, 200, 200, "#FF0000", 2)
702
+ image.saveTo(imageId, f"{dir_path}/test.jpg")
703
+ image.release(imageId)
704
+ ```
705
+
706
+ ### scanCode - 扫码条码(支持一维码和二维码)
707
+
708
+ ```python
709
+ def scanCode(id: str) -> Optional[str]
710
+ ```
711
+
712
+ **参数:**
713
+
714
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
715
+ | ------ | ---- | -------- | ------ | --------- |
716
+ | `id` | str | 是 | <br /> | 原图片 ID |
717
+
718
+ **返回值:**
719
+
720
+ | 类型 | 描述 |
721
+ | ------------- | ------------------------- |
722
+ | `str \| None` | 扫码结果;失败返回 `None` |
723
+
724
+ **示例:**
725
+
726
+ ```python
727
+ from kuaijs import image
728
+
729
+ imageId = image.captureFullScreen()
730
+ if imageId:
731
+ result = image.scanCode(imageId)
732
+ if result:
733
+ print(f"扫码结果: {result}")
734
+ else:
735
+ print("扫码失败")
736
+ image.release(imageId)
737
+ ```
738
+
739
+ ## Base64 转换
740
+
741
+ ### base64ToImage - 将 Base64 字符串转换为图片。
742
+
743
+ ```python
744
+ def base64ToImage(base64: str) -> Optional[str]
745
+ ```
746
+
747
+ **参数:**
748
+
749
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
750
+ | -------- | ---- | -------- | ------ | ------------- |
751
+ | `base64` | str | 是 | <br /> | Base64 字符串 |
752
+
753
+ **返回值:**
754
+
755
+ | 类型 | 描述 |
756
+ | ------------- | --------------- |
757
+ | `str \| None` | 转换后的图片 ID |
758
+
759
+ **示例:**
760
+
761
+ ```python
762
+ from kuaijs import image, file
763
+
764
+ base64Data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg=="
765
+ imageId = image.base64ToImage(base64Data)
766
+
767
+ # 获取手机文档目录
768
+ dir_path = file.getInternalDir("documents")
769
+ if imageId:
770
+ image.saveTo(imageId, f"{dir_path}/base64.jpg")
771
+ image.release(imageId)
772
+ ```
773
+
774
+ ### toBase64Format - 将图片转换为 Base64 字符串。
775
+
776
+ ```python
777
+ def toBase64Format(id: str, format: str, q: int) -> str
778
+ ```
779
+
780
+ **参数:**
781
+
782
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
783
+ | -------- | ---- | -------- | ------ | ------------------------------ |
784
+ | `id` | str | 是 | <br /> | 原图片 ID |
785
+ | `format` | str | 是 | <br /> | 图片格式(如 "jpg", "png") |
786
+ | `q` | int | 是 | <br /> | 质量 (1-100),数字越大质量越高 |
787
+
788
+ **返回值:**
789
+
790
+ | 类型 | 描述 |
791
+ | ----- | ---------------------- |
792
+ | `str` | 转换后的 Base64 字符串 |
793
+
794
+ **示例:**
795
+
796
+ ```python
797
+ from kuaijs import image
798
+
799
+ imageId = image.captureFullScreen()
800
+ if imageId:
801
+ base64 = image.toBase64Format(imageId, "jpg", 90)
802
+ print(f"Base64 数据: {base64[:100]}...")
803
+ image.release(imageId)
804
+ ```
805
+
806
+ ## OpenCV方法
807
+
808
+ ### captureMat - 截取屏幕并返回 OpenCV Mat(numpy.ndarray)
809
+
810
+ ```python
811
+ def captureMat() -> any
812
+ ```
813
+
814
+ **参数:**
815
+
816
+
817
+
818
+ **返回值:**
819
+
820
+ | 类型 | 描述 |
821
+ | ----- | ------------------------------------------------------------------------- |
822
+ | `any` | OpenCV-Python Mat 对象(本质为 `numpy.ndarray`,BGR 格式,失败为 `None`) |
823
+
824
+ **示例:**
825
+
826
+ ```python
827
+ from kuaijs import image
828
+ import cv2
829
+
830
+ mat = image.captureMat()
831
+ if mat is not None:
832
+ print("shape:", mat.shape)
833
+ gray = cv2.cvtColor(mat, cv2.COLOR_BGR2GRAY)
834
+ ```
835
+
836
+ ### readImageMat - 读取图片并返回 OpenCV Mat(numpy.ndarray)
837
+
838
+ ```python
839
+ def readImageMat(path: str) -> any
840
+ ```
841
+
842
+ **参数:**
843
+
844
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
845
+ | ------ | ---- | -------- | ------ | ------------ |
846
+ | `path` | str | 是 | <br /> | 图片路径/URL |
847
+
848
+ **返回值:**
849
+
850
+ | 类型 | 描述 |
851
+ | ----- | ------------------------------------------------------------------------- |
852
+ | `any` | OpenCV-Python Mat 对象(本质为 `numpy.ndarray`,BGR 格式,失败为 `None`) |
853
+
854
+ **示例:**
855
+
856
+ ```python
857
+ from kuaijs import image
858
+ import cv2
859
+
860
+ mat = image.readImageMat("/tmp/a.jpg")
861
+ if mat is not None:
862
+ edges = cv2.Canny(mat, 100, 200)
863
+ print(edges.shape)
864
+ ```
865
+
866
+ ### imageIdToMat - 将图片ID转换为 OpenCV Mat(numpy.ndarray)
867
+
868
+ ```python
869
+ def imageIdToMat(imageId: str) -> any
870
+ ```
871
+
872
+ **参数:**
873
+
874
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
875
+ | --------- | ---- | -------- | ------ | ------ |
876
+ | `imageId` | str | 是 | <br /> | 图片ID |
877
+
878
+ **返回值:**
879
+
880
+ | 类型 | 描述 |
881
+ | ----- | ------------------------------------------------------------------------- |
882
+ | `any` | OpenCV-Python Mat 对象(本质为 `numpy.ndarray`,BGR 格式,失败为 `None`) |
883
+
884
+ **示例:**
885
+
886
+ ```python
887
+ from kuaijs import image
888
+ import cv2
889
+
890
+ img_id = image.captureFullScreen()
891
+ if img_id:
892
+ mat = image.imageIdToMat(img_id)
893
+ if mat is not None:
894
+ blur = cv2.GaussianBlur(mat, (5, 5), 0)
895
+ print(blur.shape)
896
+ image.release(img_id)
897
+ ```
898
+
899
+ ## 安卓独有方法
900
+
901
+ ### getBitmap - 获取安卓的Bitmap对象
902
+
903
+ 此方法仅在安卓可用,用于获取图片的 Bitmap 对象。
904
+
905
+ ```python
906
+ def getBitmap(imageId: str) -> any:
907
+ ```
908
+
909
+ **参数:**
910
+
911
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
912
+ | --------- | ------ | -------- | ------ | --------- |
913
+ | `imageId` | string | 是 | - | 原图片 ID |
914
+
915
+ **返回值:**
916
+
917
+ | 类型 | 描述 |
918
+ | ----- | ---------------- |
919
+ | `any` | 安卓的Bitmap对象 |
920
+
921
+ **示例:**
922
+
923
+ ```python
924
+ from kuaijs import image
925
+
926
+ imageId = image.captureFullScreen()
927
+ if imageId:
928
+ bitmap = image.getBitmap(imageId)
929
+ print(f"Bitmap 对象: {bitmap}")
930
+ # 注意:使用完 Bitmap 后,需要调用 recycle() 方法释放内存
931
+ bitmap.recycle()
932
+ image.release(imageId)
933
+
934
+ # 快捷获取截屏bitmap
935
+ bitmap = image.getBitmap("screen");
936
+ print(f"Bitmap 对象: {bitmap}")
937
+ bitmap.recycle();
938
+ ```