@bettergi/utils 0.1.9 → 0.1.10
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/README.md +5 -5
- package/dist/ocr.d.ts +5 -3
- package/dist/ocr.js +8 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,13 +47,13 @@ await navigateToTab(() => {
|
|
|
47
47
|
> 对 RecognitionObject 代码的封装,对于简单的找图、找字操作,不再需要编写复杂的代码。
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
|
-
//
|
|
50
|
+
// 在整个画面内搜索图片,相似度0.8(默认),找不到返回 undefined
|
|
51
51
|
const i1 = findImage("assets/关闭.png");
|
|
52
52
|
|
|
53
|
-
//
|
|
54
|
-
const i2 = findImageInDirection("assets/关闭.png", "north-east");
|
|
53
|
+
// 在指定方向上搜索图片,相似度0.9,找不到返回 undefined
|
|
54
|
+
const i2 = findImageInDirection("assets/关闭.png", "north-east", 0.9);
|
|
55
55
|
|
|
56
|
-
//
|
|
56
|
+
// 在指定区域内搜索图片,相似度0.8(默认),找不到返回 undefined
|
|
57
57
|
const i3 = findImageWithinBounds("assets/关闭.png", 960, 0, 960, 1080);
|
|
58
58
|
|
|
59
59
|
// 在整个画面内搜索文本(不包含、忽略大小写),找不到返回 undefined
|
|
@@ -97,7 +97,7 @@ await assertRegionDisappearing(findButton, "点击购买按钮超时", () => fin
|
|
|
97
97
|
|
|
98
98
|
### 鼠标操作
|
|
99
99
|
|
|
100
|
-
>
|
|
100
|
+
> 对常见鼠标操作的封装,如鼠标的平滑移动、鼠标滚轮滚动、鼠标拖拽等。
|
|
101
101
|
|
|
102
102
|
```ts
|
|
103
103
|
// 鼠标从 (745, 610) 平滑自然地移动 (1920, 1080)
|
package/dist/ocr.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ type MatchDirection = "north" /** 上半边 */ | "north-east" /** 右上四分
|
|
|
3
3
|
/**
|
|
4
4
|
* 在整个画面内搜索图片
|
|
5
5
|
* @param path 图片路径
|
|
6
|
+
* @param similarity 相似度阈值(默认: 0.8)
|
|
6
7
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
7
8
|
*/
|
|
8
|
-
export declare const findImage: (path: string) => Region | undefined;
|
|
9
|
+
export declare const findImage: (path: string, similarity?: number) => Region | undefined;
|
|
9
10
|
/**
|
|
10
11
|
* 在指定区域内搜索图片
|
|
11
12
|
* @param path 图片路径
|
|
@@ -13,16 +14,17 @@ export declare const findImage: (path: string) => Region | undefined;
|
|
|
13
14
|
* @param y 垂直方向偏移量(像素)
|
|
14
15
|
* @param w 宽度
|
|
15
16
|
* @param h 高度
|
|
17
|
+
* @param similarity 相似度阈值(默认: 0.8)
|
|
16
18
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
17
19
|
*/
|
|
18
|
-
export declare const findImageWithinBounds: (path: string, x: number, y: number, w: number, h: number) => Region | undefined;
|
|
20
|
+
export declare const findImageWithinBounds: (path: string, x: number, y: number, w: number, h: number, similarity?: number) => Region | undefined;
|
|
19
21
|
/**
|
|
20
22
|
* 在指定方向上搜索图片
|
|
21
23
|
* @param path 图片路径
|
|
22
24
|
* @param direction 搜索方向
|
|
23
25
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
24
26
|
*/
|
|
25
|
-
export declare const findImageInDirection: (path: string, direction: MatchDirection) => Region | undefined;
|
|
27
|
+
export declare const findImageInDirection: (path: string, direction: MatchDirection, similarity?: number) => Region | undefined;
|
|
26
28
|
/** 文本搜索选项 */
|
|
27
29
|
type TextMatchOptions = {
|
|
28
30
|
/** 是否忽略大小写(默认: 是) */
|
package/dist/ocr.js
CHANGED
|
@@ -24,12 +24,14 @@ const directionToBounds = (direction) => {
|
|
|
24
24
|
/**
|
|
25
25
|
* 在整个画面内搜索图片
|
|
26
26
|
* @param path 图片路径
|
|
27
|
+
* @param similarity 相似度阈值(默认: 0.8)
|
|
27
28
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
28
29
|
*/
|
|
29
|
-
export const findImage = (path) => {
|
|
30
|
+
export const findImage = (path, similarity = 0.8) => {
|
|
30
31
|
const ir = captureGameRegion();
|
|
31
32
|
try {
|
|
32
33
|
const ro = RecognitionObject.templateMatch(file.readImageMatSync(path));
|
|
34
|
+
ro.threshold = similarity;
|
|
33
35
|
return findFirst(ir, ro, region => region.isExist());
|
|
34
36
|
}
|
|
35
37
|
catch (err) {
|
|
@@ -46,12 +48,14 @@ export const findImage = (path) => {
|
|
|
46
48
|
* @param y 垂直方向偏移量(像素)
|
|
47
49
|
* @param w 宽度
|
|
48
50
|
* @param h 高度
|
|
51
|
+
* @param similarity 相似度阈值(默认: 0.8)
|
|
49
52
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
50
53
|
*/
|
|
51
|
-
export const findImageWithinBounds = (path, x, y, w, h) => {
|
|
54
|
+
export const findImageWithinBounds = (path, x, y, w, h, similarity = 0.8) => {
|
|
52
55
|
const ir = captureGameRegion();
|
|
53
56
|
try {
|
|
54
57
|
const ro = RecognitionObject.templateMatch(file.readImageMatSync(path), x, y, w, h);
|
|
58
|
+
ro.threshold = similarity;
|
|
55
59
|
return findFirst(ir, ro, region => region.isExist());
|
|
56
60
|
}
|
|
57
61
|
catch (err) {
|
|
@@ -67,9 +71,9 @@ export const findImageWithinBounds = (path, x, y, w, h) => {
|
|
|
67
71
|
* @param direction 搜索方向
|
|
68
72
|
* @returns 如果找到匹配的图片区域,则返回该区域
|
|
69
73
|
*/
|
|
70
|
-
export const findImageInDirection = (path, direction) => {
|
|
74
|
+
export const findImageInDirection = (path, direction, similarity = 0.8) => {
|
|
71
75
|
const { x, y, w, h } = directionToBounds(direction);
|
|
72
|
-
return findImageWithinBounds(path, x, y, w, h);
|
|
76
|
+
return findImageWithinBounds(path, x, y, w, h, similarity);
|
|
73
77
|
};
|
|
74
78
|
/**
|
|
75
79
|
* 在整个画面内搜索文本
|