@bettergi/utils 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ocr.d.ts +9 -8
- package/dist/ocr.js +14 -12
- package/package.json +1 -1
package/dist/ocr.d.ts
CHANGED
|
@@ -5,17 +5,18 @@ export type ROInstance = InstanceType<typeof RecognitionObject>;
|
|
|
5
5
|
export type ROConfig = Partial<{
|
|
6
6
|
[K in keyof ROInstance as ROInstance[K] extends Function ? never : K]: ROInstance[K];
|
|
7
7
|
}>;
|
|
8
|
+
export type ImageMat = ReturnType<typeof file.readImageMatSync>;
|
|
8
9
|
export type MatchDirection = "north" /** 上半边 */ | "north-east" /** 右上四分之一 */ | "east" /** 右半边 */ | "south-east" /** 右下四分之一 */ | "south" /** 下半边 */ | "south-west" /** 左下四分之一 */ | "west" /** 左半边 */ | "north-west"; /** 左上四分之一 */
|
|
9
10
|
/**
|
|
10
11
|
* 在整个画面内搜索图片
|
|
11
|
-
* @param
|
|
12
|
+
* @param image 图片路径 或 图片矩阵
|
|
12
13
|
* @param config 识别对象配置
|
|
13
14
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
14
15
|
*/
|
|
15
|
-
export declare const findImage: (
|
|
16
|
+
export declare const findImage: (image: string | ImageMat, config?: ROConfig) => Region | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* 在指定区域内搜索图片
|
|
18
|
-
* @param
|
|
19
|
+
* @param image 图片路径 或 图片矩阵
|
|
19
20
|
* @param x 水平方向偏移量(像素)
|
|
20
21
|
* @param y 垂直方向偏移量(像素)
|
|
21
22
|
* @param w 宽度
|
|
@@ -23,10 +24,10 @@ export declare const findImage: (path: string, config?: ROConfig) => Region | un
|
|
|
23
24
|
* @param config 识别对象配置
|
|
24
25
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
25
26
|
*/
|
|
26
|
-
export declare const findImageWithinBounds: (
|
|
27
|
+
export declare const findImageWithinBounds: (image: string | ImageMat, x: number, y: number, w: number, h: number, config?: ROConfig) => Region | undefined;
|
|
27
28
|
/**
|
|
28
29
|
* 在指定坐标范围内搜索图片
|
|
29
|
-
* @param
|
|
30
|
+
* @param image 图片路径 或 图片矩阵
|
|
30
31
|
* @param left 左边界偏移量(像素)
|
|
31
32
|
* @param top 上边界偏移量(像素)
|
|
32
33
|
* @param right 右边界偏移量(像素)
|
|
@@ -34,15 +35,15 @@ export declare const findImageWithinBounds: (path: string, x: number, y: number,
|
|
|
34
35
|
* @param config 识别对象配置
|
|
35
36
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
36
37
|
*/
|
|
37
|
-
export declare const findImageBetweenCoordinates: (
|
|
38
|
+
export declare const findImageBetweenCoordinates: (image: string | ImageMat, left: number, top: number, right: number, bottom: number, config?: ROConfig) => Region | undefined;
|
|
38
39
|
/**
|
|
39
40
|
* 在指定方向上搜索图片
|
|
40
|
-
* @param
|
|
41
|
+
* @param image 图片路径 或 图片矩阵
|
|
41
42
|
* @param direction 搜索方向
|
|
42
43
|
* @param config 识别对象配置
|
|
43
44
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
44
45
|
*/
|
|
45
|
-
export declare const findImageInDirection: (
|
|
46
|
+
export declare const findImageInDirection: (image: string | ImageMat, direction: MatchDirection, config?: ROConfig) => Region | undefined;
|
|
46
47
|
/** 文本搜索选项 */
|
|
47
48
|
export type TextMatchOptions = {
|
|
48
49
|
/** 是否忽略大小写(默认: 是) */
|
package/dist/ocr.js
CHANGED
|
@@ -23,14 +23,15 @@ const directionToBounds = (direction) => {
|
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* 在整个画面内搜索图片
|
|
26
|
-
* @param
|
|
26
|
+
* @param image 图片路径 或 图片矩阵
|
|
27
27
|
* @param config 识别对象配置
|
|
28
28
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
29
29
|
*/
|
|
30
|
-
export const findImage = (
|
|
30
|
+
export const findImage = (image, config = {}) => {
|
|
31
31
|
const ir = captureGameRegion();
|
|
32
32
|
try {
|
|
33
|
-
const
|
|
33
|
+
const mat = typeof image === "string" ? file.readImageMatSync(image) : image;
|
|
34
|
+
const ro = RecognitionObject.templateMatch(mat);
|
|
34
35
|
Object.assign(ro, config);
|
|
35
36
|
return findFirst(ir, ro, region => region.isExist());
|
|
36
37
|
}
|
|
@@ -43,7 +44,7 @@ export const findImage = (path, config = {}) => {
|
|
|
43
44
|
};
|
|
44
45
|
/**
|
|
45
46
|
* 在指定区域内搜索图片
|
|
46
|
-
* @param
|
|
47
|
+
* @param image 图片路径 或 图片矩阵
|
|
47
48
|
* @param x 水平方向偏移量(像素)
|
|
48
49
|
* @param y 垂直方向偏移量(像素)
|
|
49
50
|
* @param w 宽度
|
|
@@ -51,10 +52,11 @@ export const findImage = (path, config = {}) => {
|
|
|
51
52
|
* @param config 识别对象配置
|
|
52
53
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
53
54
|
*/
|
|
54
|
-
export const findImageWithinBounds = (
|
|
55
|
+
export const findImageWithinBounds = (image, x, y, w, h, config = {}) => {
|
|
55
56
|
const ir = captureGameRegion();
|
|
56
57
|
try {
|
|
57
|
-
const
|
|
58
|
+
const mat = typeof image === "string" ? file.readImageMatSync(image) : image;
|
|
59
|
+
const ro = RecognitionObject.templateMatch(mat, x, y, w, h);
|
|
58
60
|
Object.assign(ro, config);
|
|
59
61
|
return findFirst(ir, ro, region => region.isExist());
|
|
60
62
|
}
|
|
@@ -67,7 +69,7 @@ export const findImageWithinBounds = (path, x, y, w, h, config = {}) => {
|
|
|
67
69
|
};
|
|
68
70
|
/**
|
|
69
71
|
* 在指定坐标范围内搜索图片
|
|
70
|
-
* @param
|
|
72
|
+
* @param image 图片路径 或 图片矩阵
|
|
71
73
|
* @param left 左边界偏移量(像素)
|
|
72
74
|
* @param top 上边界偏移量(像素)
|
|
73
75
|
* @param right 右边界偏移量(像素)
|
|
@@ -75,19 +77,19 @@ export const findImageWithinBounds = (path, x, y, w, h, config = {}) => {
|
|
|
75
77
|
* @param config 识别对象配置
|
|
76
78
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
77
79
|
*/
|
|
78
|
-
export const findImageBetweenCoordinates = (
|
|
79
|
-
return findImageWithinBounds(
|
|
80
|
+
export const findImageBetweenCoordinates = (image, left, top, right, bottom, config = {}) => {
|
|
81
|
+
return findImageWithinBounds(image, left, top, right - left, bottom - top, config);
|
|
80
82
|
};
|
|
81
83
|
/**
|
|
82
84
|
* 在指定方向上搜索图片
|
|
83
|
-
* @param
|
|
85
|
+
* @param image 图片路径 或 图片矩阵
|
|
84
86
|
* @param direction 搜索方向
|
|
85
87
|
* @param config 识别对象配置
|
|
86
88
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
87
89
|
*/
|
|
88
|
-
export const findImageInDirection = (
|
|
90
|
+
export const findImageInDirection = (image, direction, config = {}) => {
|
|
89
91
|
const { x, y, w, h } = directionToBounds(direction);
|
|
90
|
-
return findImageWithinBounds(
|
|
92
|
+
return findImageWithinBounds(image, x, y, w, h, config);
|
|
91
93
|
};
|
|
92
94
|
/**
|
|
93
95
|
* 在整个画面内搜索文本
|