@bettergi/utils 0.1.21 → 0.1.23
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 +2 -2
- package/dist/game.d.ts +1 -1
- package/dist/game.js +8 -8
- package/dist/ocr.d.ts +19 -14
- package/dist/ocr.js +43 -28
- package/dist/store.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ await navigateToTab(() => {
|
|
|
51
51
|
const i1 = findImage("assets/关闭.png", { use3Channels: true }); // 匹配颜色
|
|
52
52
|
|
|
53
53
|
// 在指定区域内搜索图片,找不到返回 undefined
|
|
54
|
-
const i2 = findImageWithinBounds("assets/关闭.png", 960, 0, 960, 1080);
|
|
54
|
+
const i2 = findImageWithinBounds("assets/关闭.png", 960, 0, 960, 1080, { threshold: 0.75 }); // 阈值0.75
|
|
55
55
|
|
|
56
56
|
// 在指定坐标范围内搜索图片,找不到返回 undefined
|
|
57
57
|
const i3 = findImageBetweenCoordinates("assets/关闭.png", 960, 0, 1920, 1080);
|
|
@@ -157,7 +157,7 @@ await mouseScrollDownLines(1, 115);
|
|
|
157
157
|
|
|
158
158
|
### 状态管理和持久化
|
|
159
159
|
|
|
160
|
-
> 基于深度 Proxy
|
|
160
|
+
> 基于深度 Proxy 实现的对象数据持久化,能够在数据被修改时自动同步至文件。使开发者能够像操作普通对象一样进行数据读写,而无需关心底层的持久化细节。
|
|
161
161
|
|
|
162
162
|
```ts
|
|
163
163
|
// 创建/读取存储对象,保存到存储文件 store/my-data.json 中
|
package/dist/game.d.ts
CHANGED
package/dist/game.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertRegionAppearing, assertRegionDisappearing } from "./asserts";
|
|
2
2
|
import { mouseMoveAlongWaypoints } from "./mouse";
|
|
3
|
-
import {
|
|
3
|
+
import { findTextWithinBounds, findTextWithinListView } from "./ocr";
|
|
4
4
|
/**
|
|
5
5
|
* 临时设置游戏分辨率和DPI缩放比例,执行指定动作后恢复
|
|
6
6
|
* 适用于使用了鼠标移动的操作,保证在不同的分辨率和DPI下都能正确地复现鼠标操作
|
|
@@ -10,13 +10,13 @@ import { findTextInDirection, findTextWithinBounds, findTextWithinListView } fro
|
|
|
10
10
|
* @param action 执行动作
|
|
11
11
|
*/
|
|
12
12
|
export const withGameMetrics = async (w, h, dpi, action) => {
|
|
13
|
-
const [_w, _h, _dpi] =
|
|
13
|
+
const [_w, _h, _dpi] = getGameMetrics();
|
|
14
14
|
try {
|
|
15
15
|
setGameMetrics(w, h, dpi);
|
|
16
16
|
return await action();
|
|
17
17
|
}
|
|
18
18
|
finally {
|
|
19
|
-
|
|
19
|
+
setGameMetrics(_w, _h, _dpi);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
@@ -71,14 +71,14 @@ export const openMenuPage = async (name, listView) => {
|
|
|
71
71
|
// 1.打开派蒙菜单
|
|
72
72
|
await openPaimonMenu();
|
|
73
73
|
// 2.搜索菜单页面按钮
|
|
74
|
+
const { x = 95, y = 330, w = 670, h = 730, lineHeight = 142 } = listView || {};
|
|
74
75
|
const button = await withGameMetrics(1920, 1080, 1.5, async () => {
|
|
75
|
-
|
|
76
|
-
return await findTextWithinListView(name, { x, y, w, h, lineHeight, scrollLines: 2 });
|
|
76
|
+
return await findTextWithinListView(name, { x, y, w, h, lineHeight, scrollLines: 5 });
|
|
77
77
|
});
|
|
78
78
|
if (!button)
|
|
79
79
|
throw new Error(`搜索菜单页面 ${name} 失败`);
|
|
80
80
|
// 3.点击打开菜单页面
|
|
81
|
-
await assertRegionDisappearing(() => findTextWithinBounds(name,
|
|
81
|
+
await assertRegionDisappearing(() => findTextWithinBounds(name, x, y, w, h), `打开菜单页面 ${name} 超时`, () => {
|
|
82
82
|
button.click();
|
|
83
83
|
});
|
|
84
84
|
};
|
|
@@ -108,8 +108,8 @@ export const setTimeTo = async (hour, minute, options) => {
|
|
|
108
108
|
// 拨动指针
|
|
109
109
|
await mouseMoveAlongWaypoints(waypoints, { shouldDrag: true });
|
|
110
110
|
// 点击确认按钮,等待调整结束
|
|
111
|
-
await assertRegionAppearing(() =>
|
|
112
|
-
|
|
111
|
+
await assertRegionAppearing(() => findTextWithinBounds("时间少于", 960, 540, 960, 540, { contains: true }), "调整时间超时", () => {
|
|
112
|
+
findTextWithinBounds("确认", 960, 540, 960, 540)?.click();
|
|
113
113
|
}, { maxAttempts: 20, retryInterval: 1000 });
|
|
114
114
|
});
|
|
115
115
|
// 4.返回主界面
|
package/dist/ocr.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RetryOptions } from "./workflow";
|
|
1
|
+
import { type RetryOptions } from "./workflow";
|
|
2
2
|
/** 识别对象实例 */
|
|
3
3
|
export type ROInstance = InstanceType<typeof RecognitionObject>;
|
|
4
4
|
/** 识别对象配置 */
|
|
@@ -11,7 +11,7 @@ export type MatchDirection = "north" /** 上半边 */ | "north-east" /** 右上
|
|
|
11
11
|
* 在整个画面内搜索图片
|
|
12
12
|
* @param image 图片路径 或 图片Mat
|
|
13
13
|
* @param config 识别对象配置
|
|
14
|
-
* @returns
|
|
14
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
15
15
|
*/
|
|
16
16
|
export declare const findImage: (image: string | ImageMat, config?: ROConfig) => Region | undefined;
|
|
17
17
|
/**
|
|
@@ -22,7 +22,7 @@ export declare const findImage: (image: string | ImageMat, config?: ROConfig) =>
|
|
|
22
22
|
* @param w 宽度
|
|
23
23
|
* @param h 高度
|
|
24
24
|
* @param config 识别对象配置
|
|
25
|
-
* @returns
|
|
25
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
26
26
|
*/
|
|
27
27
|
export declare const findImageWithinBounds: (image: string | ImageMat, x: number, y: number, w: number, h: number, config?: ROConfig) => Region | undefined;
|
|
28
28
|
/**
|
|
@@ -33,7 +33,7 @@ export declare const findImageWithinBounds: (image: string | ImageMat, x: number
|
|
|
33
33
|
* @param right 右边界偏移量(像素)
|
|
34
34
|
* @param bottom 下边界偏移量(像素)
|
|
35
35
|
* @param config 识别对象配置
|
|
36
|
-
* @returns
|
|
36
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
37
37
|
*/
|
|
38
38
|
export declare const findImageBetweenCoordinates: (image: string | ImageMat, left: number, top: number, right: number, bottom: number, config?: ROConfig) => Region | undefined;
|
|
39
39
|
/**
|
|
@@ -41,7 +41,7 @@ export declare const findImageBetweenCoordinates: (image: string | ImageMat, lef
|
|
|
41
41
|
* @param image 图片路径 或 图片Mat
|
|
42
42
|
* @param direction 搜索方向
|
|
43
43
|
* @param config 识别对象配置
|
|
44
|
-
* @returns
|
|
44
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
45
45
|
*/
|
|
46
46
|
export declare const findImageInDirection: (image: string | ImageMat, direction: MatchDirection, config?: ROConfig) => Region | undefined;
|
|
47
47
|
/** 文本匹配选项 */
|
|
@@ -56,7 +56,7 @@ export type TextMatchOptions = {
|
|
|
56
56
|
* @param text 待搜索文本
|
|
57
57
|
* @param options 搜索选项
|
|
58
58
|
* @param config 识别对象配置
|
|
59
|
-
* @returns
|
|
59
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
60
60
|
*/
|
|
61
61
|
export declare const findText: (text: string, options?: TextMatchOptions, config?: ROConfig) => Region | undefined;
|
|
62
62
|
/**
|
|
@@ -68,7 +68,7 @@ export declare const findText: (text: string, options?: TextMatchOptions, config
|
|
|
68
68
|
* @param h 高度
|
|
69
69
|
* @param options 搜索选项
|
|
70
70
|
* @param config 识别对象配置
|
|
71
|
-
* @returns
|
|
71
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
72
72
|
*/
|
|
73
73
|
export declare const findTextWithinBounds: (text: string, x: number, y: number, w: number, h: number, options?: TextMatchOptions, config?: ROConfig) => Region | undefined;
|
|
74
74
|
/**
|
|
@@ -80,7 +80,7 @@ export declare const findTextWithinBounds: (text: string, x: number, y: number,
|
|
|
80
80
|
* @param bottom 下边界偏移量(像素)
|
|
81
81
|
* @param options 搜索选项
|
|
82
82
|
* @param config 识别对象配置
|
|
83
|
-
* @returns
|
|
83
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
84
84
|
*/
|
|
85
85
|
export declare const findTextBetweenCoordinates: (text: string, left: number, top: number, right: number, bottom: number, options?: TextMatchOptions, config?: ROConfig) => Region | undefined;
|
|
86
86
|
/**
|
|
@@ -89,7 +89,7 @@ export declare const findTextBetweenCoordinates: (text: string, left: number, to
|
|
|
89
89
|
* @param direction 搜索方向
|
|
90
90
|
* @param options 搜索选项
|
|
91
91
|
* @param config 识别对象配置
|
|
92
|
-
* @returns
|
|
92
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
93
93
|
*/
|
|
94
94
|
export declare const findTextInDirection: (text: string, direction: MatchDirection, options?: TextMatchOptions, config?: ROConfig) => Region | undefined;
|
|
95
95
|
/** 列表视图参数 */
|
|
@@ -112,10 +112,11 @@ export type ListView = {
|
|
|
112
112
|
* @param condition 查找条件
|
|
113
113
|
* @param listView 列表视图参数
|
|
114
114
|
* @param retryOptions 重试选项
|
|
115
|
-
* @param sampling
|
|
115
|
+
* @param sampling 区域采样函数,通过采样区域画面变化判断列表是否触底(默认:底半区)
|
|
116
|
+
* @param threshold 采样区域匹配阈值(默认:0.9)
|
|
116
117
|
* @returns 如果找到匹配的区域,则返回该区域,否则返回 undefined
|
|
117
118
|
*/
|
|
118
|
-
export declare const findWithinListView: (condition: (listViewRegion: ImageRegion) => Region | undefined, listView: ListView, retryOptions?: RetryOptions, sampling?: (listViewRegion: ImageRegion) => ImageRegion) => Promise<Region | undefined>;
|
|
119
|
+
export declare const findWithinListView: (condition: (listViewRegion: ImageRegion) => Region | undefined, listView: ListView, retryOptions?: RetryOptions, sampling?: (listViewRegion: ImageRegion) => ImageRegion, threshold?: number) => Promise<Region | undefined>;
|
|
119
120
|
/**
|
|
120
121
|
* 在列表视图中滚动搜索文本
|
|
121
122
|
* @param text 待搜索文本
|
|
@@ -123,15 +124,19 @@ export declare const findWithinListView: (condition: (listViewRegion: ImageRegio
|
|
|
123
124
|
* @param matchOptions 搜索选项
|
|
124
125
|
* @param retryOptions 重试选项
|
|
125
126
|
* @param config 识别对象配置
|
|
127
|
+
* @param sampling 区域采样函数,通过采样区域画面变化判断列表是否触底(默认:底半区)
|
|
128
|
+
* @param threshold 采样区域匹配阈值(默认:0.9)
|
|
126
129
|
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
127
130
|
*/
|
|
128
|
-
export declare const findTextWithinListView: (text: string, listView: ListView, matchOptions?: TextMatchOptions, retryOptions?: RetryOptions, config?: ROConfig, sampling?: (listViewRegion: ImageRegion) => ImageRegion) => Promise<Region | undefined>;
|
|
131
|
+
export declare const findTextWithinListView: (text: string, listView: ListView, matchOptions?: TextMatchOptions, retryOptions?: RetryOptions, config?: ROConfig, sampling?: (listViewRegion: ImageRegion) => ImageRegion, threshold?: number) => Promise<Region | undefined>;
|
|
129
132
|
/**
|
|
130
133
|
* 在列表视图中查找图像
|
|
131
134
|
* @param image 图片路径 或 图片Mat
|
|
132
135
|
* @param listView 列表视图参数
|
|
133
|
-
* @param config 识别对象配置
|
|
134
136
|
* @param retryOptions 重试选项
|
|
137
|
+
* @param config 识别对象配置
|
|
138
|
+
* @param sampling 区域采样函数,通过采样区域画面变化判断列表是否触底(默认:底半区)
|
|
139
|
+
* @param threshold 采样区域匹配阈值(默认:0.9)
|
|
135
140
|
* @returns 如果找到匹配的区域,则返回该区域,否则返回 undefined
|
|
136
141
|
*/
|
|
137
|
-
export declare const findImageWithinListView: (image: string | ImageMat, listView: ListView,
|
|
142
|
+
export declare const findImageWithinListView: (image: string | ImageMat, listView: ListView, retryOptions?: RetryOptions, config?: ROConfig, sampling?: (listViewRegion: ImageRegion) => ImageRegion, threshold?: number) => Promise<Region | undefined>;
|
package/dist/ocr.js
CHANGED
|
@@ -17,7 +17,7 @@ const directionToBounds = (direction) => {
|
|
|
17
17
|
* 在整个画面内搜索图片
|
|
18
18
|
* @param image 图片路径 或 图片Mat
|
|
19
19
|
* @param config 识别对象配置
|
|
20
|
-
* @returns
|
|
20
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
21
21
|
*/
|
|
22
22
|
export const findImage = (image, config = {}) => {
|
|
23
23
|
const ir = captureGameRegion();
|
|
@@ -45,7 +45,7 @@ export const findImage = (image, config = {}) => {
|
|
|
45
45
|
* @param w 宽度
|
|
46
46
|
* @param h 高度
|
|
47
47
|
* @param config 识别对象配置
|
|
48
|
-
* @returns
|
|
48
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
49
49
|
*/
|
|
50
50
|
export const findImageWithinBounds = (image, x, y, w, h, config = {}) => {
|
|
51
51
|
const ir = captureGameRegion();
|
|
@@ -73,7 +73,7 @@ export const findImageWithinBounds = (image, x, y, w, h, config = {}) => {
|
|
|
73
73
|
* @param right 右边界偏移量(像素)
|
|
74
74
|
* @param bottom 下边界偏移量(像素)
|
|
75
75
|
* @param config 识别对象配置
|
|
76
|
-
* @returns
|
|
76
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
77
77
|
*/
|
|
78
78
|
export const findImageBetweenCoordinates = (image, left, top, right, bottom, config = {}) => {
|
|
79
79
|
return findImageWithinBounds(image, left, top, right - left, bottom - top, config);
|
|
@@ -83,7 +83,7 @@ export const findImageBetweenCoordinates = (image, left, top, right, bottom, con
|
|
|
83
83
|
* @param image 图片路径 或 图片Mat
|
|
84
84
|
* @param direction 搜索方向
|
|
85
85
|
* @param config 识别对象配置
|
|
86
|
-
* @returns
|
|
86
|
+
* @returns 如果找到匹配的图片区域,则返回该区域,否则返回 undefined
|
|
87
87
|
*/
|
|
88
88
|
export const findImageInDirection = (image, direction, config = {}) => {
|
|
89
89
|
const { x, y, w, h } = directionToBounds(direction);
|
|
@@ -122,7 +122,7 @@ const textMatch = (text, searchText, options) => {
|
|
|
122
122
|
* @param text 待搜索文本
|
|
123
123
|
* @param options 搜索选项
|
|
124
124
|
* @param config 识别对象配置
|
|
125
|
-
* @returns
|
|
125
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
126
126
|
*/
|
|
127
127
|
export const findText = (text, options, config = {}) => {
|
|
128
128
|
const ir = captureGameRegion();
|
|
@@ -151,7 +151,7 @@ export const findText = (text, options, config = {}) => {
|
|
|
151
151
|
* @param h 高度
|
|
152
152
|
* @param options 搜索选项
|
|
153
153
|
* @param config 识别对象配置
|
|
154
|
-
* @returns
|
|
154
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
155
155
|
*/
|
|
156
156
|
export const findTextWithinBounds = (text, x, y, w, h, options, config = {}) => {
|
|
157
157
|
const ir = captureGameRegion();
|
|
@@ -180,7 +180,7 @@ export const findTextWithinBounds = (text, x, y, w, h, options, config = {}) =>
|
|
|
180
180
|
* @param bottom 下边界偏移量(像素)
|
|
181
181
|
* @param options 搜索选项
|
|
182
182
|
* @param config 识别对象配置
|
|
183
|
-
* @returns
|
|
183
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
184
184
|
*/
|
|
185
185
|
export const findTextBetweenCoordinates = (text, left, top, right, bottom, options, config = {}) => {
|
|
186
186
|
return findTextWithinBounds(text, left, top, right - left, bottom - top, options, config);
|
|
@@ -191,7 +191,7 @@ export const findTextBetweenCoordinates = (text, left, top, right, bottom, optio
|
|
|
191
191
|
* @param direction 搜索方向
|
|
192
192
|
* @param options 搜索选项
|
|
193
193
|
* @param config 识别对象配置
|
|
194
|
-
* @returns
|
|
194
|
+
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
195
195
|
*/
|
|
196
196
|
export const findTextInDirection = (text, direction, options, config = {}) => {
|
|
197
197
|
const { x, y, w, h } = directionToBounds(direction);
|
|
@@ -202,28 +202,39 @@ export const findTextInDirection = (text, direction, options, config = {}) => {
|
|
|
202
202
|
* @param condition 查找条件
|
|
203
203
|
* @param listView 列表视图参数
|
|
204
204
|
* @param retryOptions 重试选项
|
|
205
|
-
* @param sampling
|
|
205
|
+
* @param sampling 区域采样函数,通过采样区域画面变化判断列表是否触底(默认:底半区)
|
|
206
|
+
* @param threshold 采样区域匹配阈值(默认:0.9)
|
|
206
207
|
* @returns 如果找到匹配的区域,则返回该区域,否则返回 undefined
|
|
207
208
|
*/
|
|
208
|
-
export const findWithinListView = async (condition, listView, retryOptions, sampling) => {
|
|
209
|
+
export const findWithinListView = async (condition, listView, retryOptions, sampling, threshold = 0.9) => {
|
|
209
210
|
const { x, y, w, h, lineHeight, scrollLines = 1, paddingX = 10, paddingY = 10 } = listView;
|
|
210
|
-
const { maxAttempts = 99, retryInterval =
|
|
211
|
-
sampling
|
|
211
|
+
const { maxAttempts = 99, retryInterval = 1200 } = retryOptions || {};
|
|
212
|
+
sampling ??= r => r.deriveCrop(1, r.height * 0.5, r.width - 1, r.height * 0.5);
|
|
212
213
|
const captureListViewRegion = () => captureGameRegion().deriveCrop(x, y, w, h);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (
|
|
214
|
+
const isReachedBottom = (() => {
|
|
215
|
+
let lastCaptured;
|
|
216
|
+
return () => {
|
|
217
|
+
const newRegion = captureListViewRegion();
|
|
218
|
+
if (!newRegion?.isExist())
|
|
218
219
|
return true;
|
|
220
|
+
try {
|
|
221
|
+
if (!lastCaptured)
|
|
222
|
+
return false;
|
|
223
|
+
const oldRegion = sampling(lastCaptured);
|
|
224
|
+
if (!oldRegion?.isExist())
|
|
225
|
+
return true;
|
|
226
|
+
// 根据采样区域画面是否变化,判断列表是否触底
|
|
227
|
+
const ro = RecognitionObject.templateMatch(oldRegion.srcMat);
|
|
228
|
+
ro.threshold = threshold;
|
|
229
|
+
ro.use3Channels = true;
|
|
230
|
+
ro.initTemplate();
|
|
231
|
+
return newRegion.find(ro)?.isExist();
|
|
219
232
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return false;
|
|
233
|
+
finally {
|
|
234
|
+
lastCaptured = newRegion;
|
|
223
235
|
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
};
|
|
236
|
+
};
|
|
237
|
+
})();
|
|
227
238
|
const isFoundOrReachedBottom = await waitForAction(() => condition(captureListViewRegion())?.isExist() || isReachedBottom(), async () => {
|
|
228
239
|
moveMouseTo(x + w - paddingX, y + paddingY); // 移动到滚动条附近
|
|
229
240
|
await sleep(50);
|
|
@@ -238,9 +249,11 @@ export const findWithinListView = async (condition, listView, retryOptions, samp
|
|
|
238
249
|
* @param matchOptions 搜索选项
|
|
239
250
|
* @param retryOptions 重试选项
|
|
240
251
|
* @param config 识别对象配置
|
|
252
|
+
* @param sampling 区域采样函数,通过采样区域画面变化判断列表是否触底(默认:底半区)
|
|
253
|
+
* @param threshold 采样区域匹配阈值(默认:0.9)
|
|
241
254
|
* @returns 如果找到匹配的文本区域,则返回该区域,否则返回 undefined
|
|
242
255
|
*/
|
|
243
|
-
export const findTextWithinListView = async (text, listView, matchOptions, retryOptions, config = {}, sampling) => {
|
|
256
|
+
export const findTextWithinListView = async (text, listView, matchOptions, retryOptions, config = {}, sampling, threshold = 0.9) => {
|
|
244
257
|
const ro = RecognitionObject.ocrThis;
|
|
245
258
|
if (Object.keys(config).length > 0) {
|
|
246
259
|
Object.assign(ro, config) && ro.initTemplate();
|
|
@@ -249,17 +262,19 @@ export const findTextWithinListView = async (text, listView, matchOptions, retry
|
|
|
249
262
|
return findFirstRegion(lvr, ro, region => {
|
|
250
263
|
return region.isExist() && textMatch(region.text, text, matchOptions);
|
|
251
264
|
});
|
|
252
|
-
}, listView, retryOptions, sampling);
|
|
265
|
+
}, listView, retryOptions, sampling, threshold);
|
|
253
266
|
};
|
|
254
267
|
/**
|
|
255
268
|
* 在列表视图中查找图像
|
|
256
269
|
* @param image 图片路径 或 图片Mat
|
|
257
270
|
* @param listView 列表视图参数
|
|
258
|
-
* @param config 识别对象配置
|
|
259
271
|
* @param retryOptions 重试选项
|
|
272
|
+
* @param config 识别对象配置
|
|
273
|
+
* @param sampling 区域采样函数,通过采样区域画面变化判断列表是否触底(默认:底半区)
|
|
274
|
+
* @param threshold 采样区域匹配阈值(默认:0.9)
|
|
260
275
|
* @returns 如果找到匹配的区域,则返回该区域,否则返回 undefined
|
|
261
276
|
*/
|
|
262
|
-
export const findImageWithinListView = async (image, listView, config = {},
|
|
277
|
+
export const findImageWithinListView = async (image, listView, retryOptions, config = {}, sampling, threshold = 0.9) => {
|
|
263
278
|
const mat = typeof image === "string" ? file.readImageMatSync(image) : image;
|
|
264
279
|
const ro = RecognitionObject.templateMatch(mat);
|
|
265
280
|
if (Object.keys(config).length > 0) {
|
|
@@ -268,5 +283,5 @@ export const findImageWithinListView = async (image, listView, config = {}, retr
|
|
|
268
283
|
return findWithinListView(ir => {
|
|
269
284
|
const region = ir.find(ro);
|
|
270
285
|
return region.isExist() ? region : undefined;
|
|
271
|
-
}, listView, retryOptions, sampling);
|
|
286
|
+
}, listView, retryOptions, sampling, threshold);
|
|
272
287
|
};
|
package/dist/store.js
CHANGED
|
@@ -60,7 +60,7 @@ export const useStore = (name) => {
|
|
|
60
60
|
* @param defaults 默认值数据对象
|
|
61
61
|
*/
|
|
62
62
|
export const useStoreWithDefaults = (name, defaults) => {
|
|
63
|
-
const
|
|
64
|
-
Object.assign(
|
|
65
|
-
return
|
|
63
|
+
const newStore = useStore(name);
|
|
64
|
+
Object.assign(newStore, deepMerge(defaults, newStore));
|
|
65
|
+
return newStore;
|
|
66
66
|
};
|