@aspiresys/visor 1.1.7 → 1.1.9
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/index.js +4 -1
- package/dist/matcher.js +9 -4
- package/dist/ocr.js +1 -1
- package/dist/screen.js +3 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -163,10 +163,13 @@ class Visor {
|
|
|
163
163
|
* await visor.find("save.png");
|
|
164
164
|
*/
|
|
165
165
|
async find(image, confidence = 0.8) {
|
|
166
|
+
const start = Date.now();
|
|
166
167
|
const screen = await (0, screen_1.captureScreen)();
|
|
167
168
|
const template = await (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
|
|
168
169
|
try {
|
|
169
|
-
|
|
170
|
+
const result = (0, matcher_1.matchTemplate)(screen, template, confidence);
|
|
171
|
+
(0, logger_1.log)(`[FIND] Total: ${Date.now() - start} ms`);
|
|
172
|
+
return result;
|
|
170
173
|
}
|
|
171
174
|
finally {
|
|
172
175
|
screen.delete();
|
package/dist/matcher.js
CHANGED
|
@@ -10,7 +10,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const pngjs_1 = require("pngjs");
|
|
11
11
|
const cv = require("@techstark/opencv-js");
|
|
12
12
|
const templateCache = new Map();
|
|
13
|
-
const sharp_1 = __importDefault(require("sharp"));
|
|
14
13
|
const logger_1 = require("./logger");
|
|
15
14
|
async function loadTemplate(path) {
|
|
16
15
|
if (templateCache.has(path)) {
|
|
@@ -19,8 +18,7 @@ async function loadTemplate(path) {
|
|
|
19
18
|
}
|
|
20
19
|
(0, logger_1.log)(`[CACHE] Loading template: ${path}`);
|
|
21
20
|
const buffer = fs_1.default.readFileSync(path);
|
|
22
|
-
const
|
|
23
|
-
const png = pngjs_1.PNG.sync.read(processed);
|
|
21
|
+
const png = pngjs_1.PNG.sync.read(buffer);
|
|
24
22
|
const template = cv.matFromImageData({
|
|
25
23
|
data: png.data,
|
|
26
24
|
width: png.width,
|
|
@@ -37,7 +35,8 @@ function resizeTemplate(template, scale) {
|
|
|
37
35
|
return resized;
|
|
38
36
|
}
|
|
39
37
|
function matchTemplate(screen, template, confidence = 0.8) {
|
|
40
|
-
const
|
|
38
|
+
const start = Date.now();
|
|
39
|
+
const scales = [1.0, 0.9, 1.1, 0.8, 1.2, 0.7, 1.3, 0.6, 1.4, 0.5, 1.5];
|
|
41
40
|
let bestMatch = null;
|
|
42
41
|
for (const scale of scales) {
|
|
43
42
|
const resizedTemplate = resizeTemplate(template, scale);
|
|
@@ -59,9 +58,15 @@ function matchTemplate(screen, template, confidence = 0.8) {
|
|
|
59
58
|
height: resizedTemplate.rows,
|
|
60
59
|
confidence: maxVal,
|
|
61
60
|
};
|
|
61
|
+
if (maxVal >= 0.98) {
|
|
62
|
+
resizedTemplate.delete();
|
|
63
|
+
(0, logger_1.log)(`[MATCH] Total: ${Date.now() - start} ms`);
|
|
64
|
+
return bestMatch;
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
resizedTemplate.delete();
|
|
64
68
|
}
|
|
69
|
+
(0, logger_1.log)(`[MATCH] Total: ${Date.now() - start} ms`);
|
|
65
70
|
return bestMatch;
|
|
66
71
|
}
|
|
67
72
|
function findAllMatches(screen, template, confidence = 0.8) {
|
package/dist/ocr.js
CHANGED
package/dist/screen.js
CHANGED
|
@@ -8,17 +8,16 @@ exports.saveScreenshot = saveScreenshot;
|
|
|
8
8
|
const screenshot_desktop_1 = __importDefault(require("screenshot-desktop"));
|
|
9
9
|
const pngjs_1 = require("pngjs");
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const sharp_1 = __importDefault(require("sharp"));
|
|
12
11
|
const cv = require("@techstark/opencv-js");
|
|
13
12
|
async function captureScreen() {
|
|
14
13
|
const buffer = await (0, screenshot_desktop_1.default)({ format: "png" });
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
return cv.matFromImageData({
|
|
14
|
+
const png = pngjs_1.PNG.sync.read(buffer);
|
|
15
|
+
const mat = cv.matFromImageData({
|
|
18
16
|
data: png.data,
|
|
19
17
|
width: png.width,
|
|
20
18
|
height: png.height,
|
|
21
19
|
});
|
|
20
|
+
return mat;
|
|
22
21
|
}
|
|
23
22
|
async function saveScreenshot(path) {
|
|
24
23
|
const img = await (0, screenshot_desktop_1.default)({ format: "png" });
|