@aspiresys/visor 1.0.2 → 1.1.0
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/app.js +1 -3
- package/dist/matcher.js +35 -18
- package/dist/mouse.js +2 -4
- package/dist/ocr.js +1 -6
- package/dist/path.js +1 -2
- package/dist/screen.js +3 -11
- package/dist/text.js +1 -3
- package/package.json +1 -1
package/dist/app.js
CHANGED
|
@@ -63,9 +63,7 @@ async function openApp(target) {
|
|
|
63
63
|
if (!resolved) {
|
|
64
64
|
throw new Error(`App not found: ${target}`);
|
|
65
65
|
}
|
|
66
|
-
const firstPath = resolved
|
|
67
|
-
.split("\n")[0]
|
|
68
|
-
.trim();
|
|
66
|
+
const firstPath = resolved.split("\n")[0].trim();
|
|
69
67
|
(0, logger_1.log)(`[APP] Resolved path: ${firstPath}`);
|
|
70
68
|
(0, child_process_1.exec)(`start "" "${firstPath}"`);
|
|
71
69
|
await new Promise(r => setTimeout(r, 5000));
|
package/dist/matcher.js
CHANGED
|
@@ -10,13 +10,10 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const pngjs_1 = require("pngjs");
|
|
11
11
|
const cv = require("@techstark/opencv-js");
|
|
12
12
|
const sharp_1 = __importDefault(require("sharp"));
|
|
13
|
+
const logger_1 = require("./logger");
|
|
13
14
|
async function loadTemplate(path) {
|
|
14
15
|
const buffer = fs_1.default.readFileSync(path);
|
|
15
|
-
const processed = await (0, sharp_1.default)(buffer)
|
|
16
|
-
.normalize()
|
|
17
|
-
.sharpen()
|
|
18
|
-
.png()
|
|
19
|
-
.toBuffer();
|
|
16
|
+
const processed = await (0, sharp_1.default)(buffer).normalize().sharpen().png().toBuffer();
|
|
20
17
|
const png = pngjs_1.PNG.sync.read(processed);
|
|
21
18
|
return cv.matFromImageData({
|
|
22
19
|
data: png.data,
|
|
@@ -24,21 +21,41 @@ async function loadTemplate(path) {
|
|
|
24
21
|
height: png.height
|
|
25
22
|
});
|
|
26
23
|
}
|
|
24
|
+
function resizeTemplate(template, scale) {
|
|
25
|
+
const resized = new cv.Mat();
|
|
26
|
+
const newWidth = Math.max(1, Math.floor(template.cols * scale));
|
|
27
|
+
const newHeight = Math.max(1, Math.floor(template.rows * scale));
|
|
28
|
+
cv.resize(template, resized, new cv.Size(newWidth, newHeight), 0, 0, scale < 1 ? cv.INTER_AREA : cv.INTER_CUBIC);
|
|
29
|
+
return resized;
|
|
30
|
+
}
|
|
27
31
|
function matchTemplate(screen, template, confidence = 0.8) {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const scales = Array.from({ length: 11 }, (_, i) => Number((0.5 + i * 0.1).toFixed(2)));
|
|
33
|
+
let bestMatch = null;
|
|
34
|
+
for (const scale of scales) {
|
|
35
|
+
const resizedTemplate = resizeTemplate(template, scale);
|
|
36
|
+
if (resizedTemplate.cols > screen.cols || resizedTemplate.rows > screen.rows) {
|
|
37
|
+
resizedTemplate.delete();
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const result = new cv.Mat();
|
|
41
|
+
cv.matchTemplate(screen, resizedTemplate, result, cv.TM_CCOEFF_NORMED);
|
|
42
|
+
const { maxLoc, maxVal } = cv.minMaxLoc(result);
|
|
43
|
+
(0, logger_1.log)(`[MATCH] Scale ${scale} -> ${maxVal}`);
|
|
44
|
+
result.delete();
|
|
45
|
+
if (maxVal >= confidence &&
|
|
46
|
+
(!bestMatch ||
|
|
47
|
+
maxVal > bestMatch.confidence)) {
|
|
48
|
+
bestMatch = {
|
|
49
|
+
x: maxLoc.x,
|
|
50
|
+
y: maxLoc.y,
|
|
51
|
+
width: resizedTemplate.cols,
|
|
52
|
+
height: resizedTemplate.rows,
|
|
53
|
+
confidence: maxVal
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
resizedTemplate.delete();
|
|
34
57
|
}
|
|
35
|
-
return
|
|
36
|
-
x: maxLoc.x,
|
|
37
|
-
y: maxLoc.y,
|
|
38
|
-
width: template.cols,
|
|
39
|
-
height: template.rows,
|
|
40
|
-
confidence: maxVal
|
|
41
|
-
};
|
|
58
|
+
return bestMatch;
|
|
42
59
|
}
|
|
43
60
|
function findAllMatches(screen, template, confidence = 0.8) {
|
|
44
61
|
const result = new cv.Mat();
|
package/dist/mouse.js
CHANGED
|
@@ -7,10 +7,8 @@ const config_1 = require("./config");
|
|
|
7
7
|
const logger_1 = require("./logger");
|
|
8
8
|
async function moveToRegion(region) {
|
|
9
9
|
const scaleFactor = config_1.visorConfig.scaleFactor;
|
|
10
|
-
const centerX = Math.floor((region.x + region.width / 2)
|
|
11
|
-
|
|
12
|
-
const centerY = Math.floor((region.y + region.height / 2)
|
|
13
|
-
/ scaleFactor);
|
|
10
|
+
const centerX = Math.floor((region.x + region.width / 2) / scaleFactor);
|
|
11
|
+
const centerY = Math.floor((region.y + region.height / 2) / scaleFactor);
|
|
14
12
|
(0, logger_1.log)("[MOUSE] Moving mouse to:", centerX, centerY);
|
|
15
13
|
await nut_js_1.mouse.move([
|
|
16
14
|
new nut_js_1.Point(centerX, centerY)
|
package/dist/ocr.js
CHANGED
|
@@ -65,12 +65,7 @@ async function extractTextFromRegion(region) {
|
|
|
65
65
|
config_1.visorConfig.scaleFactor)
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
const processed = await image
|
|
69
|
-
.grayscale()
|
|
70
|
-
.normalize()
|
|
71
|
-
.sharpen()
|
|
72
|
-
.png()
|
|
73
|
-
.toBuffer();
|
|
68
|
+
const processed = await image.grayscale().normalize().sharpen().png().toBuffer();
|
|
74
69
|
const worker = await getWorker();
|
|
75
70
|
const result = await worker.recognize(processed, {}, {
|
|
76
71
|
blocks: true,
|
package/dist/path.js
CHANGED
|
@@ -7,8 +7,7 @@ exports.resolveImagePath = resolveImagePath;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const config_1 = require("./config");
|
|
9
9
|
function resolveImagePath(image) {
|
|
10
|
-
if (image.includes("/") ||
|
|
11
|
-
image.includes("\\")) {
|
|
10
|
+
if (image.includes("/") || image.includes("\\")) {
|
|
12
11
|
return image;
|
|
13
12
|
}
|
|
14
13
|
return path_1.default.join(config_1.visorConfig.imagePath, image);
|
package/dist/screen.js
CHANGED
|
@@ -11,14 +11,8 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
11
11
|
const sharp_1 = __importDefault(require("sharp"));
|
|
12
12
|
const cv = require("@techstark/opencv-js");
|
|
13
13
|
async function captureScreen() {
|
|
14
|
-
const buffer = await (0, screenshot_desktop_1.default)({
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
const processed = await (0, sharp_1.default)(buffer)
|
|
18
|
-
.normalize()
|
|
19
|
-
.sharpen()
|
|
20
|
-
.png()
|
|
21
|
-
.toBuffer();
|
|
14
|
+
const buffer = await (0, screenshot_desktop_1.default)({ format: "png" });
|
|
15
|
+
const processed = await (0, sharp_1.default)(buffer).normalize().sharpen().png().toBuffer();
|
|
22
16
|
const png = pngjs_1.PNG.sync.read(processed);
|
|
23
17
|
return cv.matFromImageData({
|
|
24
18
|
data: png.data,
|
|
@@ -27,8 +21,6 @@ async function captureScreen() {
|
|
|
27
21
|
});
|
|
28
22
|
}
|
|
29
23
|
async function saveScreenshot(path) {
|
|
30
|
-
const img = await (0, screenshot_desktop_1.default)({
|
|
31
|
-
format: "png"
|
|
32
|
-
});
|
|
24
|
+
const img = await (0, screenshot_desktop_1.default)({ format: "png" });
|
|
33
25
|
fs_1.default.writeFileSync(path, img);
|
|
34
26
|
}
|
package/dist/text.js
CHANGED
|
@@ -31,9 +31,7 @@ async function findText(text, region) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
//console.log(words);
|
|
34
|
-
const match = words.find(w => w.text
|
|
35
|
-
.toLowerCase()
|
|
36
|
-
.includes(text.toLowerCase()));
|
|
34
|
+
const match = words.find(w => w.text.toLowerCase().includes(text.toLowerCase()));
|
|
37
35
|
if (!match) {
|
|
38
36
|
return null;
|
|
39
37
|
}
|