@aspiresys/visor 1.0.1 → 1.0.2

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
@@ -162,7 +162,7 @@ class Visor {
162
162
  */
163
163
  async find(image, confidence = 0.8) {
164
164
  const screen = await (0, screen_1.captureScreen)();
165
- const template = (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
165
+ const template = await (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
166
166
  try {
167
167
  return (0, matcher_1.matchTemplate)(screen, template, confidence);
168
168
  }
@@ -217,7 +217,7 @@ class Visor {
217
217
  */
218
218
  async findAll(image, confidence = 0.8) {
219
219
  const screen = await (0, screen_1.captureScreen)();
220
- const template = (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
220
+ const template = await (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
221
221
  try {
222
222
  return (0, matcher_1.findAllMatches)(screen, template, confidence);
223
223
  }
@@ -914,7 +914,7 @@ CONF:${m.confidence.toFixed(3)}
914
914
  const screen = await (0, screen_1.captureScreen)();
915
915
  try {
916
916
  for (const image of images) {
917
- const template = (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
917
+ const template = await (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
918
918
  try {
919
919
  const region = (0, matcher_1.matchTemplate)(screen, template, confidence);
920
920
  if (region) {
package/dist/matcher.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { Region } from "./types";
2
- export declare function loadTemplate(path: string): any;
2
+ export declare function loadTemplate(path: string): Promise<any>;
3
3
  export declare function matchTemplate(screen: any, template: any, confidence?: number): Region | null;
4
4
  export declare function findAllMatches(screen: any, template: any, confidence?: number): Region[];
package/dist/matcher.js CHANGED
@@ -9,9 +9,15 @@ exports.findAllMatches = findAllMatches;
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const pngjs_1 = require("pngjs");
11
11
  const cv = require("@techstark/opencv-js");
12
- function loadTemplate(path) {
12
+ const sharp_1 = __importDefault(require("sharp"));
13
+ async function loadTemplate(path) {
13
14
  const buffer = fs_1.default.readFileSync(path);
14
- const png = pngjs_1.PNG.sync.read(buffer);
15
+ const processed = await (0, sharp_1.default)(buffer)
16
+ .normalize()
17
+ .sharpen()
18
+ .png()
19
+ .toBuffer();
20
+ const png = pngjs_1.PNG.sync.read(processed);
15
21
  return cv.matFromImageData({
16
22
  data: png.data,
17
23
  width: png.width,
package/dist/screen.js CHANGED
@@ -8,12 +8,18 @@ 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"));
11
12
  const cv = require("@techstark/opencv-js");
12
13
  async function captureScreen() {
13
14
  const buffer = await (0, screenshot_desktop_1.default)({
14
15
  format: "png"
15
16
  });
16
- const png = pngjs_1.PNG.sync.read(buffer);
17
+ const processed = await (0, sharp_1.default)(buffer)
18
+ .normalize()
19
+ .sharpen()
20
+ .png()
21
+ .toBuffer();
22
+ const png = pngjs_1.PNG.sync.read(processed);
17
23
  return cv.matFromImageData({
18
24
  data: png.data,
19
25
  width: png.width,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspiresys/visor",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {