@udarrr/template-matcher
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
106470
1008
+ Added@types/node@22.9.3(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removedbuffer-image-size@^0.6.4
- Removedimage-size@^0.9.4
- Removedscreenshot-desktop@^1.12.7
- Removed@types/node@22.10.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffer-image-size@0.6.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedimage-size@0.9.7(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedqueue@6.0.2(transitive)
- Removedrimraf@2.6.3(transitive)
- Removedscreenshot-desktop@1.15.0(transitive)
- Removedtemp@0.9.4(transitive)
- Removedundici-types@6.20.0(transitive)