ms-types 0.10.9 → 0.10.11
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/package.json +1 -1
- package/types/cryptoUtils.d.ts +50 -36
- package/types/dotocr.d.ts +9 -2
- package/types/file.d.ts +1 -1
- package/types/hid.d.ts +47 -5
- package/types/image.d.ts +447 -447
- package/types/lua/action.lua +6 -6
- package/types/lua/cryptoUtils.lua +7 -7
- package/types/lua/cv.lua +142 -142
- package/types/lua/dotocr.lua +4 -4
- package/types/lua/file.lua +1 -1
- package/types/lua/global.lua +5 -3
- package/types/lua/hid.lua +23 -23
- package/types/lua/http.lua +26 -11
- package/types/lua/image.lua +9 -5
- package/types/lua/node.lua +1 -1
- package/types/lua/pip.lua +6 -6
- package/types/lua/yolo.lua +1 -1
- package/types/lua/yolocls.lua +1 -1
- package/types/node.d.ts +1 -0
- package/types/opencv.d.ts +571 -38
- package/types/paddleocr.d.ts +1 -0
- package/types/pip.d.ts +11 -0
- package/types/system.d.ts +1 -0
- package/types/tts.d.ts +1 -1
- package/types/ui.d.ts +2 -0
- package/types/web.d.ts +16 -0
- package/types/zh/HID/346/250/241/345/235/227.d.ts +47 -5
- package/types/zh/PaddleOCR/346/250/241/345/235/227.d.ts +1 -0
- package/types/zh//345/212/250/344/275/234/346/250/241/345/235/227.d.ts +1 -1
- package/types/zh//346/202/254/346/265/256/347/252/227/346/250/241/345/235/227.d.ts +10 -0
- package/types/zh//346/226/207/344/273/266/346/250/241/345/235/227.d.ts +1 -1
- package/types/zh//347/202/271/351/230/265OCR/346/250/241/345/235/227.d.ts +9 -2
- package/types/zh//347/263/273/347/273/237/346/250/241/345/235/227.d.ts +1 -0
- package/types/zh//350/212/202/347/202/271/346/250/241/345/235/227.d.ts +1 -0
- package/types/zh//350/247/206/345/233/276/346/250/241/345/235/227.d.ts +2 -0
package/types/image.d.ts
CHANGED
|
@@ -1,447 +1,447 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 图片模块
|
|
3
|
-
*/
|
|
4
|
-
declare namespace image {
|
|
5
|
-
/**
|
|
6
|
-
* 截图屏幕
|
|
7
|
-
* @param x 截图区域左上角x坐标
|
|
8
|
-
* @param y 截图区域左上角y坐标
|
|
9
|
-
* @param ex 截图区域右下角x坐标
|
|
10
|
-
* @param ey 截图区域右下角y坐标
|
|
11
|
-
* @returns 截图的imageId ,如果截图失败则返回null
|
|
12
|
-
* @example
|
|
13
|
-
* const imageId = image.captureScreen()
|
|
14
|
-
* if (imageId) {
|
|
15
|
-
* image.saveTo(imageId, "screen.jpg")
|
|
16
|
-
* }
|
|
17
|
-
*/
|
|
18
|
-
function captureScreen(
|
|
19
|
-
x?: number,
|
|
20
|
-
y?: number,
|
|
21
|
-
ex?: number,
|
|
22
|
-
ey?: number,
|
|
23
|
-
): string | null;
|
|
24
|
-
/**
|
|
25
|
-
* 保存图片
|
|
26
|
-
* @param imageId 图片id 路径 http地址或者 screen 实时截屏
|
|
27
|
-
* @param filePath 保存路径
|
|
28
|
-
* @example
|
|
29
|
-
* image.saveTo(imageId, "screen.jpg")
|
|
30
|
-
*/
|
|
31
|
-
function saveTo(imageId: string, filePath: string): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* 图片是否已释放
|
|
34
|
-
* @param imageId 图片id
|
|
35
|
-
* @returns true 已释放 false 未释放
|
|
36
|
-
* @example
|
|
37
|
-
* const imageId = image.captureScreen()
|
|
38
|
-
* if (imageId) {
|
|
39
|
-
* image.saveTo(imageId, "screen.jpg")
|
|
40
|
-
* image.isRelease(imageId) // false
|
|
41
|
-
* image.release(imageId)
|
|
42
|
-
* image.isRelease(imageId) // true
|
|
43
|
-
* }
|
|
44
|
-
*/
|
|
45
|
-
function isRelease(imageId: string): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* 释放图片
|
|
48
|
-
* @param imageId 图片id
|
|
49
|
-
* @example
|
|
50
|
-
* image.release(imageId)
|
|
51
|
-
*/
|
|
52
|
-
function release(imageId: string): void;
|
|
53
|
-
/**
|
|
54
|
-
* 释放所有图片
|
|
55
|
-
* @example
|
|
56
|
-
* image.releaseAll()
|
|
57
|
-
*/
|
|
58
|
-
function releaseAll(): void;
|
|
59
|
-
/**
|
|
60
|
-
* 获取图片大小
|
|
61
|
-
* @param imageId 图片id
|
|
62
|
-
* @returns 图片大小 {width: number, height: number}
|
|
63
|
-
* @example
|
|
64
|
-
* const size = image.getSize(
|
|
65
|
-
* if (size) {
|
|
66
|
-
* logi(size.width, size.height)
|
|
67
|
-
* }
|
|
68
|
-
*/
|
|
69
|
-
function getSize(imageId: string): { width: number; height: number } | null;
|
|
70
|
-
/**
|
|
71
|
-
* 读取图片
|
|
72
|
-
* @param path 图片路径
|
|
73
|
-
* @returns 图片id ,如果读取失败则返回null
|
|
74
|
-
* @example
|
|
75
|
-
* const imageId = image.readImage("screen.jpg")
|
|
76
|
-
* if (imageId) {
|
|
77
|
-
* image.saveTo(imageId, "screen.jpg")
|
|
78
|
-
* }
|
|
79
|
-
* image.release(imageId)
|
|
80
|
-
*/
|
|
81
|
-
function readImage(path: string): string | null;
|
|
82
|
-
/**
|
|
83
|
-
* 旋转图片
|
|
84
|
-
* @param imageId 图片id
|
|
85
|
-
* @param degree 旋转角度 只能是 90 -90 180
|
|
86
|
-
* @returns 旋转后的图片id ,如果旋转失败则返回null
|
|
87
|
-
* @example
|
|
88
|
-
* const imageId = image.readImage("screen.jpg")
|
|
89
|
-
* if (imageId) {
|
|
90
|
-
* const newImageId = image.rotateImage(imageId, 90)
|
|
91
|
-
* if (newImageId) {
|
|
92
|
-
* image.saveTo(newImageId, "screen.jpg")
|
|
93
|
-
* }
|
|
94
|
-
* image.release(imageId)
|
|
95
|
-
* }
|
|
96
|
-
*/
|
|
97
|
-
function rotateImage(imageId: string, degree: number): string | null;
|
|
98
|
-
/**
|
|
99
|
-
* 比较颜色
|
|
100
|
-
* @param imageId 图片id
|
|
101
|
-
* @param points 颜色点
|
|
102
|
-
* @param threshold 阈值 0.0-1.0
|
|
103
|
-
* @returns true 相同 false 不同
|
|
104
|
-
* @example
|
|
105
|
-
* const imageId = image.readImage("screen.jpg")
|
|
106
|
-
* if (imageId) {
|
|
107
|
-
* const isSame = image.cmpColor(imageId, "1|2|#6DD1E6-#101010", 0.9)
|
|
108
|
-
* if (isSame) {
|
|
109
|
-
* logi("颜色相同")
|
|
110
|
-
* }
|
|
111
|
-
* }
|
|
112
|
-
*/
|
|
113
|
-
function cmpColor(
|
|
114
|
-
imageId: string,
|
|
115
|
-
points: string,
|
|
116
|
-
threshold: number,
|
|
117
|
-
): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* 查找颜色
|
|
120
|
-
* @param imageId 图片id
|
|
121
|
-
* @param color 颜色 支持"主色-偏色"格式,如"#6DD1E6-#101010"
|
|
122
|
-
* @param threshold 阈值 0.0-1.0
|
|
123
|
-
* @param x 左上角x 全屏传0
|
|
124
|
-
* @param y 左上角y 全屏传0
|
|
125
|
-
* @param ex 右下角x 全屏传0
|
|
126
|
-
* @param ey 右下角y 全屏传0
|
|
127
|
-
* @param limit 限制数量
|
|
128
|
-
* @param orz 查找方向1-8
|
|
129
|
-
* @returns 颜色点数组
|
|
130
|
-
* @example
|
|
131
|
-
* const imageId = image.readImage("screen.jpg")
|
|
132
|
-
* if (imageId) {
|
|
133
|
-
* const points = image.findColor(imageId, "#6DD1E6-#101010", 0.9, 0, 0, 100, 100, 1, 1)
|
|
134
|
-
* if (points.length > 0) {
|
|
135
|
-
* logi("找到颜色")
|
|
136
|
-
* }
|
|
137
|
-
* }
|
|
138
|
-
* image.release(imageId)
|
|
139
|
-
*/
|
|
140
|
-
function findColor(
|
|
141
|
-
imageId: string,
|
|
142
|
-
color: string,
|
|
143
|
-
threshold: number,
|
|
144
|
-
x: number,
|
|
145
|
-
y: number,
|
|
146
|
-
ex: number,
|
|
147
|
-
ey: number,
|
|
148
|
-
limit: number,
|
|
149
|
-
orz: number,
|
|
150
|
-
): { x: number; y: number }[];
|
|
151
|
-
/**
|
|
152
|
-
* 查找多颜色
|
|
153
|
-
* @param imageId 图片id
|
|
154
|
-
* @param firstColor 第一个颜色
|
|
155
|
-
* @param threshold 阈值 0.0-1.0
|
|
156
|
-
* @param points 颜色点
|
|
157
|
-
* @param x 左上角x 全屏传0
|
|
158
|
-
* @param y 左上角y 全屏传0
|
|
159
|
-
* @param ex 右下角x 全屏传0
|
|
160
|
-
* @param ey 右下角y 全屏传0
|
|
161
|
-
* @param limit 限制数量
|
|
162
|
-
* @param orz 查找方向1-8
|
|
163
|
-
* @returns 颜色点数组
|
|
164
|
-
* @example
|
|
165
|
-
* const imageId = image.readImage("screen.jpg")
|
|
166
|
-
* if (imageId) {
|
|
167
|
-
* const points = image.findMultiColor(imageId, "#6DD1E6-#101010", 0.9, "1|2|#6DD1E6-#101010", 0, 0, 100, 100, 1, 1)
|
|
168
|
-
* if (points.length > 0) {
|
|
169
|
-
* logi("找到颜色")
|
|
170
|
-
* }
|
|
171
|
-
* }
|
|
172
|
-
* image.release(imageId)
|
|
173
|
-
*/
|
|
174
|
-
function findMultiColor(
|
|
175
|
-
imageId: string,
|
|
176
|
-
firstColor: string,
|
|
177
|
-
threshold: number,
|
|
178
|
-
points: string,
|
|
179
|
-
x: number,
|
|
180
|
-
y: number,
|
|
181
|
-
ex: number,
|
|
182
|
-
ey: number,
|
|
183
|
-
limit: number,
|
|
184
|
-
orz: number,
|
|
185
|
-
): { x: number; y: number }[];
|
|
186
|
-
/**
|
|
187
|
-
* 统计颜色数量
|
|
188
|
-
* @param imageId 图片id
|
|
189
|
-
* @param colors 颜色列表,支持 "主色-偏色|主色-偏色|...",如 "#0A0A0A-#101010|#FFFFFF-#101010"
|
|
190
|
-
* @param threshold 相似度阈值 0.0-1.0
|
|
191
|
-
* @param x 区域左上角x(全图传0)
|
|
192
|
-
* @param y 区域左上角y(全图传0)
|
|
193
|
-
* @param ex 区域右下角x(全图传0)
|
|
194
|
-
* @param ey 区域右下角y(全图传0)
|
|
195
|
-
* @returns 命中像素数量
|
|
196
|
-
* @example
|
|
197
|
-
* const n = image.countColor("screen", "#0A0A0A-#101010|#FFFFFF-#101010", 0.92, 100, 200, 500, 700)
|
|
198
|
-
*/
|
|
199
|
-
function countColor(
|
|
200
|
-
imageId: string,
|
|
201
|
-
colors: string,
|
|
202
|
-
threshold: number,
|
|
203
|
-
x: number,
|
|
204
|
-
y: number,
|
|
205
|
-
ex: number,
|
|
206
|
-
ey: number,
|
|
207
|
-
): number;
|
|
208
|
-
/**
|
|
209
|
-
* 查找图片
|
|
210
|
-
* @param imageId 图片id
|
|
211
|
-
* @param templateImageId 模板图片id
|
|
212
|
-
* @param x 左上角x 全屏传0
|
|
213
|
-
* @param y 左上角y 全屏传0
|
|
214
|
-
* @param ex 右下角x 全屏传0
|
|
215
|
-
* @param ey 右下角y 全屏传0
|
|
216
|
-
* @param threshold 阈值 0.0-1.0
|
|
217
|
-
* @param limit 限制数量
|
|
218
|
-
* @param method 方法
|
|
219
|
-
* @param rgb 是否使用RGB找图,默认false
|
|
220
|
-
* @param options 选项
|
|
221
|
-
* @param options.scaleFactors 仅 method=99 生效。模板缩放比例列表(不是屏幕 scale)。
|
|
222
|
-
* 应围绕 baseScale=当前设备宽/截模板设备宽 生成,例如 baseScale 附近 ±0.05~0.1 共 3~7 档;
|
|
223
|
-
* 默认 [1.0, 0.9, 1.1, 0.8, 1.2] 只适合尺寸接近时的盲扫,跨大分辨率请按设备动态计算。
|
|
224
|
-
* @param options.orz 查找方向 1-8,与 findColor 的 orz 相同。不传或非 1-8 时仍按相似度从高到低返回;
|
|
225
|
-
* 传入 1-8 时按该方向取前 limit 个达标结果。limit=1 时只返回该方向第一个,不必把其余命中都找出来。
|
|
226
|
-
* method 0(SIFT)会先完成匹配再按方向排序截取。
|
|
227
|
-
* @returns 图片数组;method=99 时结果额外含 scaleX/scaleY
|
|
228
|
-
* @example
|
|
229
|
-
* const points = image.findImage("screen", "template.jpg", 0, 0, 100, 100, 0.9, 1, 5, false)
|
|
230
|
-
* if (points.length > 0) {
|
|
231
|
-
* logi("找到图片")
|
|
232
|
-
* }
|
|
233
|
-
*/
|
|
234
|
-
function findImage(
|
|
235
|
-
imageId: string,
|
|
236
|
-
templateImageId: string,
|
|
237
|
-
x: number,
|
|
238
|
-
y: number,
|
|
239
|
-
ex: number,
|
|
240
|
-
ey: number,
|
|
241
|
-
threshold: number,
|
|
242
|
-
limit: number,
|
|
243
|
-
method: number,
|
|
244
|
-
rgb?: boolean,
|
|
245
|
-
options?: {
|
|
246
|
-
scaleFactors?: number[];
|
|
247
|
-
orz?: number;
|
|
248
|
-
},
|
|
249
|
-
): {
|
|
250
|
-
index: number;
|
|
251
|
-
x: number;
|
|
252
|
-
y: number;
|
|
253
|
-
width: number;
|
|
254
|
-
height: number;
|
|
255
|
-
confidence: number;
|
|
256
|
-
centerX: number;
|
|
257
|
-
centerY: number;
|
|
258
|
-
ex: number;
|
|
259
|
-
ey: number;
|
|
260
|
-
/** 仅 method=99 返回:命中时模板的横向缩放比例 */
|
|
261
|
-
scaleX?: number;
|
|
262
|
-
/** 仅 method=99 返回:命中时模板的纵向缩放比例 */
|
|
263
|
-
scaleY?: number;
|
|
264
|
-
}[];
|
|
265
|
-
/**
|
|
266
|
-
* 按 kjst 模板找图
|
|
267
|
-
* @param imageId 图片id,通常为 `"screen"`
|
|
268
|
-
* @param kjstPath res 下的 kjst 文件名,不要带 `res/` 前缀
|
|
269
|
-
* @returns 矩形数组,坐标已换算到传入图片(`screen` 即屏幕)像素,可直接 click;OCR 命中额外含 `text`
|
|
270
|
-
* @example
|
|
271
|
-
* const hits = image.findImageEx("screen", "login.kjst")
|
|
272
|
-
* if (hits.length > 0) {
|
|
273
|
-
* logi(hits[0].x, hits[0].y)
|
|
274
|
-
* }
|
|
275
|
-
*/
|
|
276
|
-
function findImageEx(
|
|
277
|
-
imageId: string,
|
|
278
|
-
kjstPath: string,
|
|
279
|
-
): {
|
|
280
|
-
index: number;
|
|
281
|
-
x: number;
|
|
282
|
-
y: number;
|
|
283
|
-
width: number;
|
|
284
|
-
height: number;
|
|
285
|
-
confidence: number;
|
|
286
|
-
centerX: number;
|
|
287
|
-
centerY: number;
|
|
288
|
-
ex: number;
|
|
289
|
-
ey: number;
|
|
290
|
-
text?: string;
|
|
291
|
-
}[];
|
|
292
|
-
/**
|
|
293
|
-
* 裁剪图片
|
|
294
|
-
* @param imageId 图片id
|
|
295
|
-
* @param x 坐标x
|
|
296
|
-
* @param y 坐标y
|
|
297
|
-
* @param ex 坐标ex
|
|
298
|
-
* @param ey 坐标ey
|
|
299
|
-
* @returns 裁剪后的图片id
|
|
300
|
-
* @example
|
|
301
|
-
* const imageId = image.readImage("screen.jpg")
|
|
302
|
-
* if (imageId) {
|
|
303
|
-
* const clipImageId = image.clip(imageId, 0, 0, 100, 100)
|
|
304
|
-
* if (clipImageId) {
|
|
305
|
-
* logi("裁剪成功")
|
|
306
|
-
* }
|
|
307
|
-
* }
|
|
308
|
-
* image.release(imageId)
|
|
309
|
-
*/
|
|
310
|
-
function clip(
|
|
311
|
-
imageId: string,
|
|
312
|
-
x: number,
|
|
313
|
-
y: number,
|
|
314
|
-
ex: number,
|
|
315
|
-
ey: number,
|
|
316
|
-
): string | null;
|
|
317
|
-
/**
|
|
318
|
-
* 获取图片像素
|
|
319
|
-
* @param imageId 图片id
|
|
320
|
-
* @param x 坐标x
|
|
321
|
-
* @param y 坐标y
|
|
322
|
-
* @returns 颜色值
|
|
323
|
-
* @example
|
|
324
|
-
* const imageId = image.readImage("screen.jpg")
|
|
325
|
-
* if (imageId) {
|
|
326
|
-
* const color = image.pixel(imageId, 0, 0)
|
|
327
|
-
* logi(color)
|
|
328
|
-
* }
|
|
329
|
-
* image.release(imageId)
|
|
330
|
-
*/
|
|
331
|
-
function pixel(imageId: string, x: number, y: number): number;
|
|
332
|
-
/**
|
|
333
|
-
* 将整型的颜色值转成16进制RGB字符串
|
|
334
|
-
* @param color 颜色值
|
|
335
|
-
* @returns 16进制RGB字符串
|
|
336
|
-
* @example
|
|
337
|
-
* const imageId = image.readImage("screen.jpg")
|
|
338
|
-
* if (imageId) {
|
|
339
|
-
* const color = image.pixel(imageId, 0, 0)
|
|
340
|
-
* logi(image.argb(color))
|
|
341
|
-
* }
|
|
342
|
-
* image.release(imageId)
|
|
343
|
-
*/
|
|
344
|
-
function argb(color: number): string;
|
|
345
|
-
/**
|
|
346
|
-
* 二值化
|
|
347
|
-
* @param imageId 图片id
|
|
348
|
-
* @param threshold 阈值 0.0-255.0
|
|
349
|
-
* @returns 二值化后的图片id
|
|
350
|
-
* @example
|
|
351
|
-
* const imageId = image.readImage("screen.jpg")
|
|
352
|
-
* if (imageId) {
|
|
353
|
-
* const binaryzationImageId = image.binaryzation(imageId, 128)
|
|
354
|
-
* if (binaryzationImageId) {
|
|
355
|
-
* logi("二值化成功")
|
|
356
|
-
* }
|
|
357
|
-
* }
|
|
358
|
-
* image.release(imageId)
|
|
359
|
-
*/
|
|
360
|
-
function binaryzation(imageId: string, threshold: number): string | null;
|
|
361
|
-
/**
|
|
362
|
-
* 灰度化
|
|
363
|
-
* @param imageId 图片id
|
|
364
|
-
* @returns 灰度化后的图片id
|
|
365
|
-
* @example
|
|
366
|
-
* const imageId = image.readImage("screen.jpg")
|
|
367
|
-
* if (imageId) {
|
|
368
|
-
* const grayImageId = image.gray(imageId)
|
|
369
|
-
* if (grayImageId) {
|
|
370
|
-
* logi("灰度化成功")
|
|
371
|
-
* }
|
|
372
|
-
* }
|
|
373
|
-
* image.release(imageId)
|
|
374
|
-
*/
|
|
375
|
-
function gray(imageId: string): string | null;
|
|
376
|
-
/**
|
|
377
|
-
* base64转图片
|
|
378
|
-
* @param base64 base64字符串
|
|
379
|
-
* @returns 图片id
|
|
380
|
-
* @example
|
|
381
|
-
* const imageId = image.base64ToImage("data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==")
|
|
382
|
-
* if (imageId) {
|
|
383
|
-
* logi("base64转图片成功")
|
|
384
|
-
* }
|
|
385
|
-
* image.release(imageId)
|
|
386
|
-
*/
|
|
387
|
-
function base64ToImage(base64: string): string | null;
|
|
388
|
-
/**
|
|
389
|
-
* 图片转base64
|
|
390
|
-
* @param imageId 图片id
|
|
391
|
-
* @param format 格式
|
|
392
|
-
* @param q 质量 1-100 数字越大质量越高
|
|
393
|
-
* @returns base64字符串
|
|
394
|
-
* @example
|
|
395
|
-
* const imageId = image.readImage("screen.jpg")
|
|
396
|
-
* if (imageId) {
|
|
397
|
-
* const base64 = image.toBase64Format(imageId, "jpg", 100)
|
|
398
|
-
* logi(base64)
|
|
399
|
-
* }
|
|
400
|
-
* image.release(imageId)
|
|
401
|
-
*/
|
|
402
|
-
function toBase64Format(
|
|
403
|
-
imageId: string,
|
|
404
|
-
format: string,
|
|
405
|
-
q: number,
|
|
406
|
-
): string | null;
|
|
407
|
-
/**
|
|
408
|
-
* 扫描条码 支持一维码和二维码
|
|
409
|
-
* @param imageId 图片id
|
|
410
|
-
* @returns 条码内容
|
|
411
|
-
* @example
|
|
412
|
-
* const imageId = image.readImage("screen.jpg")
|
|
413
|
-
* if (imageId) {
|
|
414
|
-
* const code = image.scanCode(imageId)
|
|
415
|
-
* if (code) {
|
|
416
|
-
* logi(code)
|
|
417
|
-
* }
|
|
418
|
-
* }
|
|
419
|
-
*/
|
|
420
|
-
function scanCode(imageId: string): string | null;
|
|
421
|
-
/**
|
|
422
|
-
* 绘制矩形
|
|
423
|
-
* @param imageId 图片id
|
|
424
|
-
* @param x 坐标x
|
|
425
|
-
* @param y 坐标y
|
|
426
|
-
* @param ex 坐标ex
|
|
427
|
-
* @param ey 坐标ey
|
|
428
|
-
* @param color 颜色
|
|
429
|
-
* @param thickness 线宽
|
|
430
|
-
* @returns 无
|
|
431
|
-
* @example
|
|
432
|
-
* const imageId = image.readImage("screen.jpg")
|
|
433
|
-
* if (imageId) {
|
|
434
|
-
* image.drawRect(imageId, 0, 0, 100, 100, "#ff0000", 1)
|
|
435
|
-
* }
|
|
436
|
-
* image.release(imageId)
|
|
437
|
-
*/
|
|
438
|
-
function drawRect(
|
|
439
|
-
imageId: string,
|
|
440
|
-
x: number,
|
|
441
|
-
y: number,
|
|
442
|
-
ex: number,
|
|
443
|
-
ey: number,
|
|
444
|
-
color: string,
|
|
445
|
-
thickness: number,
|
|
446
|
-
): void;
|
|
447
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 图片模块
|
|
3
|
+
*/
|
|
4
|
+
declare namespace image {
|
|
5
|
+
/**
|
|
6
|
+
* 截图屏幕
|
|
7
|
+
* @param x 截图区域左上角x坐标
|
|
8
|
+
* @param y 截图区域左上角y坐标
|
|
9
|
+
* @param ex 截图区域右下角x坐标
|
|
10
|
+
* @param ey 截图区域右下角y坐标
|
|
11
|
+
* @returns 截图的imageId ,如果截图失败则返回null
|
|
12
|
+
* @example
|
|
13
|
+
* const imageId = image.captureScreen()
|
|
14
|
+
* if (imageId) {
|
|
15
|
+
* image.saveTo(imageId, "screen.jpg")
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
function captureScreen(
|
|
19
|
+
x?: number,
|
|
20
|
+
y?: number,
|
|
21
|
+
ex?: number,
|
|
22
|
+
ey?: number,
|
|
23
|
+
): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* 保存图片
|
|
26
|
+
* @param imageId 图片id 路径 http地址或者 screen 实时截屏
|
|
27
|
+
* @param filePath 保存路径
|
|
28
|
+
* @example
|
|
29
|
+
* image.saveTo(imageId, "screen.jpg")
|
|
30
|
+
*/
|
|
31
|
+
function saveTo(imageId: string, filePath: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* 图片是否已释放
|
|
34
|
+
* @param imageId 图片id
|
|
35
|
+
* @returns true 已释放 false 未释放
|
|
36
|
+
* @example
|
|
37
|
+
* const imageId = image.captureScreen()
|
|
38
|
+
* if (imageId) {
|
|
39
|
+
* image.saveTo(imageId, "screen.jpg")
|
|
40
|
+
* image.isRelease(imageId) // false
|
|
41
|
+
* image.release(imageId)
|
|
42
|
+
* image.isRelease(imageId) // true
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
function isRelease(imageId: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 释放图片
|
|
48
|
+
* @param imageId 图片id
|
|
49
|
+
* @example
|
|
50
|
+
* image.release(imageId)
|
|
51
|
+
*/
|
|
52
|
+
function release(imageId: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* 释放所有图片
|
|
55
|
+
* @example
|
|
56
|
+
* image.releaseAll()
|
|
57
|
+
*/
|
|
58
|
+
function releaseAll(): void;
|
|
59
|
+
/**
|
|
60
|
+
* 获取图片大小
|
|
61
|
+
* @param imageId 图片id
|
|
62
|
+
* @returns 图片大小 {width: number, height: number}
|
|
63
|
+
* @example
|
|
64
|
+
* const size = image.getSize("screen")
|
|
65
|
+
* if (size) {
|
|
66
|
+
* logi(size.width, size.height)
|
|
67
|
+
* }
|
|
68
|
+
*/
|
|
69
|
+
function getSize(imageId: string): { width: number; height: number } | null;
|
|
70
|
+
/**
|
|
71
|
+
* 读取图片
|
|
72
|
+
* @param path 图片路径
|
|
73
|
+
* @returns 图片id ,如果读取失败则返回null
|
|
74
|
+
* @example
|
|
75
|
+
* const imageId = image.readImage("screen.jpg")
|
|
76
|
+
* if (imageId) {
|
|
77
|
+
* image.saveTo(imageId, "screen.jpg")
|
|
78
|
+
* }
|
|
79
|
+
* image.release(imageId)
|
|
80
|
+
*/
|
|
81
|
+
function readImage(path: string): string | null;
|
|
82
|
+
/**
|
|
83
|
+
* 旋转图片
|
|
84
|
+
* @param imageId 图片id
|
|
85
|
+
* @param degree 旋转角度 只能是 90 -90 180
|
|
86
|
+
* @returns 旋转后的图片id ,如果旋转失败则返回null
|
|
87
|
+
* @example
|
|
88
|
+
* const imageId = image.readImage("screen.jpg")
|
|
89
|
+
* if (imageId) {
|
|
90
|
+
* const newImageId = image.rotateImage(imageId, 90)
|
|
91
|
+
* if (newImageId) {
|
|
92
|
+
* image.saveTo(newImageId, "screen.jpg")
|
|
93
|
+
* }
|
|
94
|
+
* image.release(imageId)
|
|
95
|
+
* }
|
|
96
|
+
*/
|
|
97
|
+
function rotateImage(imageId: string, degree: number): string | null;
|
|
98
|
+
/**
|
|
99
|
+
* 比较颜色
|
|
100
|
+
* @param imageId 图片id
|
|
101
|
+
* @param points 颜色点
|
|
102
|
+
* @param threshold 阈值 0.0-1.0
|
|
103
|
+
* @returns true 相同 false 不同
|
|
104
|
+
* @example
|
|
105
|
+
* const imageId = image.readImage("screen.jpg")
|
|
106
|
+
* if (imageId) {
|
|
107
|
+
* const isSame = image.cmpColor(imageId, "1|2|#6DD1E6-#101010", 0.9)
|
|
108
|
+
* if (isSame) {
|
|
109
|
+
* logi("颜色相同")
|
|
110
|
+
* }
|
|
111
|
+
* }
|
|
112
|
+
*/
|
|
113
|
+
function cmpColor(
|
|
114
|
+
imageId: string,
|
|
115
|
+
points: string,
|
|
116
|
+
threshold: number,
|
|
117
|
+
): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* 查找颜色
|
|
120
|
+
* @param imageId 图片id
|
|
121
|
+
* @param color 颜色 支持"主色-偏色"格式,如"#6DD1E6-#101010"
|
|
122
|
+
* @param threshold 阈值 0.0-1.0
|
|
123
|
+
* @param x 左上角x 全屏传0
|
|
124
|
+
* @param y 左上角y 全屏传0
|
|
125
|
+
* @param ex 右下角x 全屏传0
|
|
126
|
+
* @param ey 右下角y 全屏传0
|
|
127
|
+
* @param limit 限制数量
|
|
128
|
+
* @param orz 查找方向1-8
|
|
129
|
+
* @returns 颜色点数组
|
|
130
|
+
* @example
|
|
131
|
+
* const imageId = image.readImage("screen.jpg")
|
|
132
|
+
* if (imageId) {
|
|
133
|
+
* const points = image.findColor(imageId, "#6DD1E6-#101010", 0.9, 0, 0, 100, 100, 1, 1)
|
|
134
|
+
* if (points.length > 0) {
|
|
135
|
+
* logi("找到颜色")
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
* image.release(imageId)
|
|
139
|
+
*/
|
|
140
|
+
function findColor(
|
|
141
|
+
imageId: string,
|
|
142
|
+
color: string,
|
|
143
|
+
threshold: number,
|
|
144
|
+
x: number,
|
|
145
|
+
y: number,
|
|
146
|
+
ex: number,
|
|
147
|
+
ey: number,
|
|
148
|
+
limit: number,
|
|
149
|
+
orz: number,
|
|
150
|
+
): { x: number; y: number }[];
|
|
151
|
+
/**
|
|
152
|
+
* 查找多颜色
|
|
153
|
+
* @param imageId 图片id
|
|
154
|
+
* @param firstColor 第一个颜色
|
|
155
|
+
* @param threshold 阈值 0.0-1.0
|
|
156
|
+
* @param points 颜色点
|
|
157
|
+
* @param x 左上角x 全屏传0
|
|
158
|
+
* @param y 左上角y 全屏传0
|
|
159
|
+
* @param ex 右下角x 全屏传0
|
|
160
|
+
* @param ey 右下角y 全屏传0
|
|
161
|
+
* @param limit 限制数量
|
|
162
|
+
* @param orz 查找方向1-8
|
|
163
|
+
* @returns 颜色点数组
|
|
164
|
+
* @example
|
|
165
|
+
* const imageId = image.readImage("screen.jpg")
|
|
166
|
+
* if (imageId) {
|
|
167
|
+
* const points = image.findMultiColor(imageId, "#6DD1E6-#101010", 0.9, "1|2|#6DD1E6-#101010", 0, 0, 100, 100, 1, 1)
|
|
168
|
+
* if (points.length > 0) {
|
|
169
|
+
* logi("找到颜色")
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* image.release(imageId)
|
|
173
|
+
*/
|
|
174
|
+
function findMultiColor(
|
|
175
|
+
imageId: string,
|
|
176
|
+
firstColor: string,
|
|
177
|
+
threshold: number,
|
|
178
|
+
points: string,
|
|
179
|
+
x: number,
|
|
180
|
+
y: number,
|
|
181
|
+
ex: number,
|
|
182
|
+
ey: number,
|
|
183
|
+
limit: number,
|
|
184
|
+
orz: number,
|
|
185
|
+
): { x: number; y: number }[];
|
|
186
|
+
/**
|
|
187
|
+
* 统计颜色数量
|
|
188
|
+
* @param imageId 图片id
|
|
189
|
+
* @param colors 颜色列表,支持 "主色-偏色|主色-偏色|...",如 "#0A0A0A-#101010|#FFFFFF-#101010"
|
|
190
|
+
* @param threshold 相似度阈值 0.0-1.0
|
|
191
|
+
* @param x 区域左上角x(全图传0)
|
|
192
|
+
* @param y 区域左上角y(全图传0)
|
|
193
|
+
* @param ex 区域右下角x(全图传0)
|
|
194
|
+
* @param ey 区域右下角y(全图传0)
|
|
195
|
+
* @returns 命中像素数量
|
|
196
|
+
* @example
|
|
197
|
+
* const n = image.countColor("screen", "#0A0A0A-#101010|#FFFFFF-#101010", 0.92, 100, 200, 500, 700)
|
|
198
|
+
*/
|
|
199
|
+
function countColor(
|
|
200
|
+
imageId: string,
|
|
201
|
+
colors: string,
|
|
202
|
+
threshold: number,
|
|
203
|
+
x: number,
|
|
204
|
+
y: number,
|
|
205
|
+
ex: number,
|
|
206
|
+
ey: number,
|
|
207
|
+
): number;
|
|
208
|
+
/**
|
|
209
|
+
* 查找图片
|
|
210
|
+
* @param imageId 图片id
|
|
211
|
+
* @param templateImageId 模板图片id
|
|
212
|
+
* @param x 左上角x 全屏传0
|
|
213
|
+
* @param y 左上角y 全屏传0
|
|
214
|
+
* @param ex 右下角x 全屏传0
|
|
215
|
+
* @param ey 右下角y 全屏传0
|
|
216
|
+
* @param threshold 阈值 0.0-1.0
|
|
217
|
+
* @param limit 限制数量
|
|
218
|
+
* @param method 方法
|
|
219
|
+
* @param rgb 是否使用RGB找图,默认false
|
|
220
|
+
* @param options 选项
|
|
221
|
+
* @param options.scaleFactors 仅 method=99 生效。模板缩放比例列表(不是屏幕 scale)。
|
|
222
|
+
* 应围绕 baseScale=当前设备宽/截模板设备宽 生成,例如 baseScale 附近 ±0.05~0.1 共 3~7 档;
|
|
223
|
+
* 默认 [1.0, 0.9, 1.1, 0.8, 1.2] 只适合尺寸接近时的盲扫,跨大分辨率请按设备动态计算。
|
|
224
|
+
* @param options.orz 查找方向 1-8,与 findColor 的 orz 相同。不传或非 1-8 时仍按相似度从高到低返回;
|
|
225
|
+
* 传入 1-8 时按该方向取前 limit 个达标结果。limit=1 时只返回该方向第一个,不必把其余命中都找出来。
|
|
226
|
+
* method 0(SIFT)会先完成匹配再按方向排序截取。
|
|
227
|
+
* @returns 图片数组;method=99 时结果额外含 scaleX/scaleY
|
|
228
|
+
* @example
|
|
229
|
+
* const points = image.findImage("screen", "template.jpg", 0, 0, 100, 100, 0.9, 1, 5, false)
|
|
230
|
+
* if (points.length > 0) {
|
|
231
|
+
* logi("找到图片")
|
|
232
|
+
* }
|
|
233
|
+
*/
|
|
234
|
+
function findImage(
|
|
235
|
+
imageId: string,
|
|
236
|
+
templateImageId: string,
|
|
237
|
+
x: number,
|
|
238
|
+
y: number,
|
|
239
|
+
ex: number,
|
|
240
|
+
ey: number,
|
|
241
|
+
threshold: number,
|
|
242
|
+
limit: number,
|
|
243
|
+
method: number,
|
|
244
|
+
rgb?: boolean,
|
|
245
|
+
options?: {
|
|
246
|
+
scaleFactors?: number[];
|
|
247
|
+
orz?: number;
|
|
248
|
+
},
|
|
249
|
+
): {
|
|
250
|
+
index: number;
|
|
251
|
+
x: number;
|
|
252
|
+
y: number;
|
|
253
|
+
width: number;
|
|
254
|
+
height: number;
|
|
255
|
+
confidence: number;
|
|
256
|
+
centerX: number;
|
|
257
|
+
centerY: number;
|
|
258
|
+
ex: number;
|
|
259
|
+
ey: number;
|
|
260
|
+
/** 仅 method=99 返回:命中时模板的横向缩放比例 */
|
|
261
|
+
scaleX?: number;
|
|
262
|
+
/** 仅 method=99 返回:命中时模板的纵向缩放比例 */
|
|
263
|
+
scaleY?: number;
|
|
264
|
+
}[];
|
|
265
|
+
/**
|
|
266
|
+
* 按 kjst 模板找图
|
|
267
|
+
* @param imageId 图片id,通常为 `"screen"`
|
|
268
|
+
* @param kjstPath res 下的 kjst 文件名,不要带 `res/` 前缀
|
|
269
|
+
* @returns 矩形数组,坐标已换算到传入图片(`screen` 即屏幕)像素,可直接 click;OCR 命中额外含 `text`
|
|
270
|
+
* @example
|
|
271
|
+
* const hits = image.findImageEx("screen", "login.kjst")
|
|
272
|
+
* if (hits.length > 0) {
|
|
273
|
+
* logi(hits[0].x, hits[0].y)
|
|
274
|
+
* }
|
|
275
|
+
*/
|
|
276
|
+
function findImageEx(
|
|
277
|
+
imageId: string,
|
|
278
|
+
kjstPath: string,
|
|
279
|
+
): {
|
|
280
|
+
index: number;
|
|
281
|
+
x: number;
|
|
282
|
+
y: number;
|
|
283
|
+
width: number;
|
|
284
|
+
height: number;
|
|
285
|
+
confidence: number;
|
|
286
|
+
centerX: number;
|
|
287
|
+
centerY: number;
|
|
288
|
+
ex: number;
|
|
289
|
+
ey: number;
|
|
290
|
+
text?: string;
|
|
291
|
+
}[];
|
|
292
|
+
/**
|
|
293
|
+
* 裁剪图片
|
|
294
|
+
* @param imageId 图片id
|
|
295
|
+
* @param x 坐标x
|
|
296
|
+
* @param y 坐标y
|
|
297
|
+
* @param ex 坐标ex
|
|
298
|
+
* @param ey 坐标ey
|
|
299
|
+
* @returns 裁剪后的图片id
|
|
300
|
+
* @example
|
|
301
|
+
* const imageId = image.readImage("screen.jpg")
|
|
302
|
+
* if (imageId) {
|
|
303
|
+
* const clipImageId = image.clip(imageId, 0, 0, 100, 100)
|
|
304
|
+
* if (clipImageId) {
|
|
305
|
+
* logi("裁剪成功")
|
|
306
|
+
* }
|
|
307
|
+
* }
|
|
308
|
+
* image.release(imageId)
|
|
309
|
+
*/
|
|
310
|
+
function clip(
|
|
311
|
+
imageId: string,
|
|
312
|
+
x: number,
|
|
313
|
+
y: number,
|
|
314
|
+
ex: number,
|
|
315
|
+
ey: number,
|
|
316
|
+
): string | null;
|
|
317
|
+
/**
|
|
318
|
+
* 获取图片像素
|
|
319
|
+
* @param imageId 图片id
|
|
320
|
+
* @param x 坐标x
|
|
321
|
+
* @param y 坐标y
|
|
322
|
+
* @returns 颜色值
|
|
323
|
+
* @example
|
|
324
|
+
* const imageId = image.readImage("screen.jpg")
|
|
325
|
+
* if (imageId) {
|
|
326
|
+
* const color = image.pixel(imageId, 0, 0)
|
|
327
|
+
* logi(color)
|
|
328
|
+
* }
|
|
329
|
+
* image.release(imageId)
|
|
330
|
+
*/
|
|
331
|
+
function pixel(imageId: string, x: number, y: number): number;
|
|
332
|
+
/**
|
|
333
|
+
* 将整型的颜色值转成16进制RGB字符串
|
|
334
|
+
* @param color 颜色值
|
|
335
|
+
* @returns 16进制RGB字符串
|
|
336
|
+
* @example
|
|
337
|
+
* const imageId = image.readImage("screen.jpg")
|
|
338
|
+
* if (imageId) {
|
|
339
|
+
* const color = image.pixel(imageId, 0, 0)
|
|
340
|
+
* logi(image.argb(color))
|
|
341
|
+
* }
|
|
342
|
+
* image.release(imageId)
|
|
343
|
+
*/
|
|
344
|
+
function argb(color: number): string;
|
|
345
|
+
/**
|
|
346
|
+
* 二值化
|
|
347
|
+
* @param imageId 图片id
|
|
348
|
+
* @param threshold 阈值 0.0-255.0
|
|
349
|
+
* @returns 二值化后的图片id
|
|
350
|
+
* @example
|
|
351
|
+
* const imageId = image.readImage("screen.jpg")
|
|
352
|
+
* if (imageId) {
|
|
353
|
+
* const binaryzationImageId = image.binaryzation(imageId, 128)
|
|
354
|
+
* if (binaryzationImageId) {
|
|
355
|
+
* logi("二值化成功")
|
|
356
|
+
* }
|
|
357
|
+
* }
|
|
358
|
+
* image.release(imageId)
|
|
359
|
+
*/
|
|
360
|
+
function binaryzation(imageId: string, threshold: number): string | null;
|
|
361
|
+
/**
|
|
362
|
+
* 灰度化
|
|
363
|
+
* @param imageId 图片id
|
|
364
|
+
* @returns 灰度化后的图片id
|
|
365
|
+
* @example
|
|
366
|
+
* const imageId = image.readImage("screen.jpg")
|
|
367
|
+
* if (imageId) {
|
|
368
|
+
* const grayImageId = image.gray(imageId)
|
|
369
|
+
* if (grayImageId) {
|
|
370
|
+
* logi("灰度化成功")
|
|
371
|
+
* }
|
|
372
|
+
* }
|
|
373
|
+
* image.release(imageId)
|
|
374
|
+
*/
|
|
375
|
+
function gray(imageId: string): string | null;
|
|
376
|
+
/**
|
|
377
|
+
* base64转图片
|
|
378
|
+
* @param base64 base64字符串
|
|
379
|
+
* @returns 图片id
|
|
380
|
+
* @example
|
|
381
|
+
* const imageId = image.base64ToImage("data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==")
|
|
382
|
+
* if (imageId) {
|
|
383
|
+
* logi("base64转图片成功")
|
|
384
|
+
* }
|
|
385
|
+
* image.release(imageId)
|
|
386
|
+
*/
|
|
387
|
+
function base64ToImage(base64: string): string | null;
|
|
388
|
+
/**
|
|
389
|
+
* 图片转base64
|
|
390
|
+
* @param imageId 图片id
|
|
391
|
+
* @param format 格式
|
|
392
|
+
* @param q 质量 1-100 数字越大质量越高
|
|
393
|
+
* @returns base64字符串
|
|
394
|
+
* @example
|
|
395
|
+
* const imageId = image.readImage("screen.jpg")
|
|
396
|
+
* if (imageId) {
|
|
397
|
+
* const base64 = image.toBase64Format(imageId, "jpg", 100)
|
|
398
|
+
* logi(base64)
|
|
399
|
+
* }
|
|
400
|
+
* image.release(imageId)
|
|
401
|
+
*/
|
|
402
|
+
function toBase64Format(
|
|
403
|
+
imageId: string,
|
|
404
|
+
format: string,
|
|
405
|
+
q: number,
|
|
406
|
+
): string | null;
|
|
407
|
+
/**
|
|
408
|
+
* 扫描条码 支持一维码和二维码
|
|
409
|
+
* @param imageId 图片id
|
|
410
|
+
* @returns 条码内容
|
|
411
|
+
* @example
|
|
412
|
+
* const imageId = image.readImage("screen.jpg")
|
|
413
|
+
* if (imageId) {
|
|
414
|
+
* const code = image.scanCode(imageId)
|
|
415
|
+
* if (code) {
|
|
416
|
+
* logi(code)
|
|
417
|
+
* }
|
|
418
|
+
* }
|
|
419
|
+
*/
|
|
420
|
+
function scanCode(imageId: string): string | null;
|
|
421
|
+
/**
|
|
422
|
+
* 绘制矩形
|
|
423
|
+
* @param imageId 图片id
|
|
424
|
+
* @param x 坐标x
|
|
425
|
+
* @param y 坐标y
|
|
426
|
+
* @param ex 坐标ex
|
|
427
|
+
* @param ey 坐标ey
|
|
428
|
+
* @param color 颜色
|
|
429
|
+
* @param thickness 线宽
|
|
430
|
+
* @returns 无
|
|
431
|
+
* @example
|
|
432
|
+
* const imageId = image.readImage("screen.jpg")
|
|
433
|
+
* if (imageId) {
|
|
434
|
+
* image.drawRect(imageId, 0, 0, 100, 100, "#ff0000", 1)
|
|
435
|
+
* }
|
|
436
|
+
* image.release(imageId)
|
|
437
|
+
*/
|
|
438
|
+
function drawRect(
|
|
439
|
+
imageId: string,
|
|
440
|
+
x: number,
|
|
441
|
+
y: number,
|
|
442
|
+
ex: number,
|
|
443
|
+
ey: number,
|
|
444
|
+
color: string,
|
|
445
|
+
thickness: number,
|
|
446
|
+
): void;
|
|
447
|
+
}
|