@aspiresys/visor 1.1.8 → 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 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
- return (0, matcher_1.matchTemplate)(screen, template, confidence);
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 processed = await (0, sharp_1.default)(buffer).normalize().sharpen().png().toBuffer();
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 scales = Array.from({ length: 11 }, (_, i) => Number((0.5 + i * 0.1).toFixed(2)));
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);
@@ -61,11 +60,13 @@ function matchTemplate(screen, template, confidence = 0.8) {
61
60
  };
62
61
  if (maxVal >= 0.98) {
63
62
  resizedTemplate.delete();
63
+ (0, logger_1.log)(`[MATCH] Total: ${Date.now() - start} ms`);
64
64
  return bestMatch;
65
65
  }
66
66
  }
67
67
  resizedTemplate.delete();
68
68
  }
69
+ (0, logger_1.log)(`[MATCH] Total: ${Date.now() - start} ms`);
69
70
  return bestMatch;
70
71
  }
71
72
  function findAllMatches(screen, template, confidence = 0.8) {
package/dist/ocr.js CHANGED
@@ -78,9 +78,3 @@ async function extractTextFromRegion(region) {
78
78
  (0, logger_1.log)(result.data.text);
79
79
  return result.data.text;
80
80
  }
81
- (async () => {
82
- const start = Date.now();
83
- const text = await extractTextFromRegion();
84
- console.log(`OCR Time: ${Date.now() - start} ms`);
85
- await terminateOCR();
86
- })();
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 processed = await (0, sharp_1.default)(buffer).normalize().sharpen().png().toBuffer();
16
- const png = pngjs_1.PNG.sync.read(processed);
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" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspiresys/visor",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {