Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@udarrr/template-matcher

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udarrr/template-matcher - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

48

dist/lib/template-matching-finder.class.js

@@ -11,6 +11,2 @@ "use strict";

const image_reader_class_1 = __importDefault(require("./image-reader.class"));
const screenshot_desktop_1 = __importDefault(require("screenshot-desktop"));
const buffer_image_size_1 = __importDefault(require("buffer-image-size"));
const image_size_1 = __importDefault(require("image-size"));
const path_1 = __importDefault(require("path"));
async function loadNeedle(image, roi) {

@@ -26,4 +22,4 @@ if (typeof image !== 'string') {

else {
const dimensions = (0, image_size_1.default)(image);
const rect = (0, image_processor_class_1.determineROI)(new nut_js_1.Image(dimensions.width, dimensions.height, Buffer.from([]), 1, ''), roi);
const screenPic = await nut_js_1.screen.grabRegion(roi);
const rect = (0, image_processor_class_1.determineROI)(screenPic, roi);
return { data: mat.getRegion(rect), rect: rect };

@@ -35,22 +31,20 @@ }

if (typeof image !== 'string' && image) {
return { data: await (0, image_processor_class_1.fromImageWithAlphaChannel)(image, roi), rect: null };
return { data: await (0, image_processor_class_1.fromImageWithAlphaChannel)(image, roi), rect: null, pixelDensity: image.pixelDensity };
}
else {
if (!image) {
const buffer = await (0, screenshot_desktop_1.default)({ format: 'bmp' });
const dimensions = (0, buffer_image_size_1.default)(buffer);
const mat = await (0, image_processor_class_1.fromImageWithAlphaChannel)(new nut_js_1.Image(dimensions.width, dimensions.height, buffer, 1, dimensions.type), roi);
return { data: await mat.flipAsync(0), rect: null };
const screenPic = await nut_js_1.screen.grab();
const mat = await (0, image_processor_class_1.fromImageWithAlphaChannel)(screenPic, roi);
return { data: mat, rect: null, pixelDensity: screenPic.pixelDensity };
}
else {
const baseName = path_1.default.basename(image);
const pathToHaystack = await (0, screenshot_desktop_1.default)({ filename: `${baseName}.bmp` });
let mat = await new image_reader_class_1.default().readToMat(pathToHaystack);
const screenPic = await nut_js_1.screen.grab();
let mat = await (0, image_processor_class_1.fromImageWithAlphaChannel)(screenPic, roi);
if (!roi) {
return { data: mat, rect: null };
return { data: mat, rect: null, pixelDensity: screenPic.pixelDensity };
}
else {
const dimensions = (0, image_size_1.default)(pathToHaystack);
const rect = (0, image_processor_class_1.determineROI)(new nut_js_1.Image(dimensions.width, dimensions.height, Buffer.from([]), 1, ''), roi);
return { data: mat.getRegion(rect), rect: rect };
const screenPic = await nut_js_1.screen.grabRegion(roi);
const rect = (0, image_processor_class_1.determineROI)(screenPic, roi);
return { data: mat.getRegion(rect), rect: rect, pixelDensity: screenPic.pixelDensity };
}

@@ -111,11 +105,11 @@ }

}
return await this.getValidatedMatches(matchResults, matchRequest, confidence);
return await this.getValidatedMatches(matchResults, haystack.pixelDensity, confidence);
}
async getValidatedMatches(matchResults, matchRequest, confidence) {
async getValidatedMatches(matchResults, pixelDensity, confidence) {
const matches = await Promise.all(matchResults).then((results) => {
results.forEach((matchResult) => {
matchResult.location.left /= matchRequest.haystack ? matchRequest.haystack.pixelDensity.scaleX : 1;
matchResult.location.width /= matchRequest.haystack ? matchRequest.haystack.pixelDensity.scaleX : 1;
matchResult.location.top /= matchRequest.haystack ? matchRequest.haystack.pixelDensity.scaleY : 1;
matchResult.location.height /= matchRequest.haystack ? matchRequest.haystack.pixelDensity.scaleY : 1;
matchResult.location.left /= pixelDensity.scaleX && pixelDensity.scaleY && pixelDensity.scaleX === pixelDensity.scaleY ? pixelDensity.scaleX : 1;
matchResult.location.width /= pixelDensity.scaleX && pixelDensity.scaleY && pixelDensity.scaleX === pixelDensity.scaleY ? pixelDensity.scaleX : 1;
matchResult.location.top /= pixelDensity.scaleX && pixelDensity.scaleY && pixelDensity.scaleX === pixelDensity.scaleY ? pixelDensity.scaleX : 1;
matchResult.location.height /= pixelDensity.scaleX && pixelDensity.scaleY && pixelDensity.scaleX === pixelDensity.scaleY ? pixelDensity.scaleX : 1;
});

@@ -132,3 +126,3 @@ return results.sort((first, second) => second.confidence - first.confidence);

else {
throw new Error(`Unable to locate on screen with template ${matchRequest.needle.id}, no match!`);
throw new Error(`Unable to locate on screen with template, no match!`);
}

@@ -142,3 +136,3 @@ }

const matches = await match_image_function_1.MatchTemplate.matchImages(haystack.data, needle.data, methodType, debug);
const result = await this.getValidatedMatches([matches.data], matchRequest, confidence);
const result = await this.getValidatedMatches([matches.data], haystack.pixelDensity, confidence);
return result[0];

@@ -148,3 +142,3 @@ }

const scaledResults = await this.searchMultipleScales(haystack.data, needle.data, confidence, scaleSteps, methodType, debug, true);
return (await this.getValidatedMatches([scaledResults[0]], matchRequest, confidence))[0];
return (await this.getValidatedMatches([scaledResults[0]], haystack.pixelDensity, confidence))[0];
}

@@ -151,0 +145,0 @@ }

{
"name": "@udarrr/template-matcher",
"version": "1.1.4",
"version": "1.1.5",
"main": "dist/index",

@@ -12,3 +12,5 @@ "typings": "dist/index",

},
"files": ["dist"],
"files": [
"dist"
],
"repository": {

@@ -59,6 +61,3 @@ "type": "git",

"dependencies": {
"buffer-image-size": "^0.6.4",
"image-size": "^0.9.4",
"opencv4nodejs-prebuilt": "5.3.4",
"screenshot-desktop": "^1.12.7"
"opencv4nodejs-prebuilt": "5.3.4"
},

@@ -77,4 +76,4 @@ "devDependencies": {

"peerDependencies": {
"@nut-tree/nut-js": "^2.0.0"
"@nut-tree/nut-js": "^2.3.0"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc