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 2.0.1 to 2.1.1

dist/lib/customTypes.d.ts

0

dist/index.d.ts

@@ -0,0 +0,0 @@ import TemplateMatchingFinder from './lib/template-matching-finder.class';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Image, Region } from '@nut-tree/nut-js';

@@ -0,0 +0,0 @@ "use strict";

14

dist/lib/match-image.function.d.ts
import { MatchResult } from '@nut-tree/nut-js';
import { Mat, Point2, Vec3 } from 'opencv4nodejs-prebuilt-install';
export declare enum MethodEnum {
TM_CCOEFF = "TM_CCOEFF",
TM_CCOEFF_NORMED = "TM_CCOEFF_NORMED",
TM_CCORR = "TM_CCORR",
TM_CCORR_NORMED = "TM_CCORR_NORMED",
TM_SQDIFF = "TM_SQDIFF",
TM_SQDIFF_NORMED = "TM_SQDIFF_NORMED"
}
export type MethodNameType = `${MethodEnum}`;
export type MatchedResults = {
results: Array<MatchResult>;
haystack: Mat;
};
import { MatchedResults, MethodNameType } from './customTypes';
export declare class MatchTemplate {

@@ -17,0 +5,0 @@ static matchImages(haystack: Mat, needle: Mat, matchedMethod: MethodNameType, debug?: boolean): Promise<{

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MatchTemplate = exports.MethodEnum = void 0;
exports.MatchTemplate = void 0;
let cv;

@@ -11,11 +11,3 @@ try {

const opencv4nodejs_prebuilt_install_1 = require("opencv4nodejs-prebuilt-install");
var MethodEnum;
(function (MethodEnum) {
MethodEnum["TM_CCOEFF"] = "TM_CCOEFF";
MethodEnum["TM_CCOEFF_NORMED"] = "TM_CCOEFF_NORMED";
MethodEnum["TM_CCORR"] = "TM_CCORR";
MethodEnum["TM_CCORR_NORMED"] = "TM_CCORR_NORMED";
MethodEnum["TM_SQDIFF"] = "TM_SQDIFF";
MethodEnum["TM_SQDIFF_NORMED"] = "TM_SQDIFF_NORMED";
})(MethodEnum = exports.MethodEnum || (exports.MethodEnum = {}));
const customTypes_1 = require("./customTypes");
class MatchTemplate {

@@ -25,3 +17,3 @@ static async matchImages(haystack, needle, matchedMethod, debug = false) {

const minMax = await match.minMaxLocAsync();
const isMethodTypeMaxOrMin = matchedMethod === MethodEnum.TM_SQDIFF_NORMED || matchedMethod === MethodEnum.TM_SQDIFF;
const isMethodTypeMaxOrMin = matchedMethod === customTypes_1.MethodEnum.TM_SQDIFF_NORMED || matchedMethod === customTypes_1.MethodEnum.TM_SQDIFF;
let locType = isMethodTypeMaxOrMin ? 'minLoc' : 'maxLoc';

@@ -46,3 +38,3 @@ if (debug) {

let prevMinLoc, prevMaxLoc = {};
const isMethodTypeMaxOrMin = matchedMethod === MethodEnum.TM_SQDIFF_NORMED || matchedMethod === MethodEnum.TM_SQDIFF;
const isMethodTypeMaxOrMin = matchedMethod === customTypes_1.MethodEnum.TM_SQDIFF_NORMED || matchedMethod === customTypes_1.MethodEnum.TM_SQDIFF;
let locType = isMethodTypeMaxOrMin ? 'minLoc' : 'maxLoc';

@@ -49,0 +41,0 @@ while (isMethodTypeMaxOrMin ? minVal <= confidence : maxVal > confidence) {

@@ -0,0 +0,0 @@ import { Region } from '@nut-tree/nut-js';

@@ -0,0 +0,0 @@ "use strict";

@@ -1,15 +0,8 @@

import { Image, ImageFinderInterface, MatchRequest, MatchResult, Region } from '@nut-tree/nut-js';
import { MethodNameType } from './match-image.function';
type CustomOptionsType = {
methodType?: MethodNameType;
searchMultipleScales?: boolean;
scaleSteps?: Array<number>;
debug?: boolean;
roi?: Region;
};
import { ImageFinderInterface, MatchRequest, MatchResult } from '@nut-tree/nut-js';
import { CustomConfigType, CustomMatchRequest } from './customTypes';
export default class TemplateMatchingFinder implements ImageFinderInterface {
private _config;
constructor();
getConfig(): Partial<MatchRequest<string | Image, CustomOptionsType>>;
setConfig(config: CustomOptionsType): void;
getConfig(): CustomConfigType;
setConfig(config: CustomConfigType): void;
private loadNeedle;

@@ -19,7 +12,7 @@ private loadHaystack;

private initData;
findMatches<CustomOptionsType>(matchRequest: MatchRequest<Image | string, CustomOptionsType>): Promise<MatchResult[]>;
findMatches(matchRequest: MatchRequest | CustomMatchRequest): Promise<MatchResult[]>;
private getIncreasedRectByPixelDensity;
private getDecreasedRectByPixelDensity;
private getValidatedMatches;
findMatch<CustomOptionsType>(matchRequest: MatchRequest<Image | string, CustomOptionsType>): Promise<MatchResult>;
findMatch(matchRequest: MatchRequest | CustomMatchRequest): Promise<MatchResult>;
private searchMultipleScales;

@@ -29,3 +22,2 @@ private scaleHaystack;

}
export {};
//# sourceMappingURL=template-matching-finder.class.d.ts.map

@@ -12,5 +12,6 @@ "use strict";

const image_processor_class_1 = require("./image-processor.class");
const customTypes_1 = require("./customTypes");
class TemplateMatchingFinder {
constructor() {
this._config = { confidence: 0.8, providerData: { searchMultipleScales: true, scaleSteps: [1, 0.9, 0.8, 0.7, 0.6, 0.5], methodType: match_image_function_1.MethodEnum.TM_CCOEFF_NORMED, debug: false } };
this._config = { confidence: 0.8, searchMultipleScales: true, customOptions: { scaleSteps: [1, 0.9, 0.8, 0.7, 0.6, 0.5], methodType: customTypes_1.MethodEnum.TM_CCOEFF_NORMED, debug: false } };
}

@@ -62,7 +63,8 @@ getConfig() {

async initData(matchRequest) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
const confidence = matchRequest.providerData && ((_a = matchRequest.providerData) === null || _a === void 0 ? void 0 : _a.methodType) === match_image_function_1.MethodEnum.TM_SQDIFF && matchRequest.confidence === 0.99
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
const customMatchRequest = matchRequest;
const confidence = customMatchRequest.customOptions && ((_a = customMatchRequest.customOptions) === null || _a === void 0 ? void 0 : _a.methodType) === customTypes_1.MethodEnum.TM_SQDIFF && matchRequest.confidence === 0.99
? 0.998
: (matchRequest.providerData && ((_b = matchRequest.providerData) === null || _b === void 0 ? void 0 : _b.methodType) === match_image_function_1.MethodEnum.TM_CCOEFF_NORMED) ||
(matchRequest.providerData && ((_c = matchRequest.providerData) === null || _c === void 0 ? void 0 : _c.methodType) === match_image_function_1.MethodEnum.TM_CCORR_NORMED && matchRequest.confidence === 0.99)
: (customMatchRequest.customOptions && ((_b = customMatchRequest.customOptions) === null || _b === void 0 ? void 0 : _b.methodType) === customTypes_1.MethodEnum.TM_CCOEFF_NORMED) ||
(customMatchRequest.customOptions && ((_c = customMatchRequest.customOptions) === null || _c === void 0 ? void 0 : _c.methodType) === customTypes_1.MethodEnum.TM_CCORR_NORMED && matchRequest.confidence === 0.99)
? this._config.confidence

@@ -72,6 +74,6 @@ : matchRequest.confidence === 0.99 || typeof matchRequest.confidence === 'undefined'

: matchRequest.confidence;
const searchMultipleScales = ((_d = matchRequest.providerData) === null || _d === void 0 ? void 0 : _d.searchMultipleScales) ? (_e = matchRequest.providerData) === null || _e === void 0 ? void 0 : _e.searchMultipleScales : (_f = this._config.providerData) === null || _f === void 0 ? void 0 : _f.searchMultipleScales;
const scaleSteps = ((_g = matchRequest.providerData) === null || _g === void 0 ? void 0 : _g.scaleSteps) || ((_h = this._config.providerData) === null || _h === void 0 ? void 0 : _h.scaleSteps);
const methodType = ((_j = matchRequest.providerData) === null || _j === void 0 ? void 0 : _j.methodType) || ((_k = this._config.providerData) === null || _k === void 0 ? void 0 : _k.methodType);
const debug = ((_l = matchRequest.providerData) === null || _l === void 0 ? void 0 : _l.debug) || ((_m = this._config.providerData) === null || _m === void 0 ? void 0 : _m.debug);
const searchMultipleScales = customMatchRequest.searchMultipleScales ? customMatchRequest.searchMultipleScales : this._config.searchMultipleScales;
const scaleSteps = ((_d = customMatchRequest.customOptions) === null || _d === void 0 ? void 0 : _d.scaleSteps) || ((_e = this._config.customOptions) === null || _e === void 0 ? void 0 : _e.scaleSteps);
const methodType = ((_f = customMatchRequest.customOptions) === null || _f === void 0 ? void 0 : _f.methodType) || ((_g = this._config.customOptions) === null || _g === void 0 ? void 0 : _g.methodType);
const debug = ((_h = customMatchRequest.customOptions) === null || _h === void 0 ? void 0 : _h.debug) || ((_j = this._config.customOptions) === null || _j === void 0 ? void 0 : _j.debug);
const needle = await this.loadNeedle(matchRequest.needle);

@@ -81,7 +83,7 @@ if (!needle || needle.data.empty) {

}
const haystack = await this.loadHaystack(matchRequest.haystack, (_o = matchRequest.providerData) === null || _o === void 0 ? void 0 : _o.roi);
const haystack = await this.loadHaystack(matchRequest.haystack, (_k = customMatchRequest.customOptions) === null || _k === void 0 ? void 0 : _k.roi);
if (!haystack || haystack.data.empty) {
throw new Error(`Failed to load ${matchRequest && matchRequest.haystack && typeof matchRequest.haystack === 'string' && !matchRequest.haystack ? matchRequest.haystack : matchRequest.haystack.id}, got empty image.`);
}
if ((_p = matchRequest.providerData) === null || _p === void 0 ? void 0 : _p.searchMultipleScales) {
if (matchRequest.searchMultipleScales) {
this.throwOnTooLargeNeedle(haystack.data, needle.data, scaleSteps[scaleSteps.length - 1]);

@@ -97,3 +99,3 @@ }

searchMultipleScales: searchMultipleScales,
roi: (_q = matchRequest.providerData) === null || _q === void 0 ? void 0 : _q.roi,
roi: (_l = customMatchRequest.customOptions) === null || _l === void 0 ? void 0 : _l.roi,
};

@@ -100,0 +102,0 @@ }

{
"name": "@udarrr/template-matcher",
"version": "2.0.1",
"version": "2.1.1",
"main": "dist/index",

@@ -55,3 +55,3 @@ "typings": "dist/index",

"opencv4nodejs-prebuilt-install": "^4.1.146",
"@nut-tree/nut-js": "^3.1.1"
"@nut-tree/nut-js": "^2.3.0"
},

@@ -58,0 +58,0 @@ "engines": {

@@ -1,2 +0,2 @@

# OpenCV 4.1.1 Template Matching Image Finder
# OpenCV 4.1.1 Template Matching Image Finder

@@ -9,5 +9,5 @@ ![Tested](https://github.com/udarrr/TemplateMatcher/workflows/Tests/badge.svg)

- increased accuracy
- increased performance
- added some customOptions for arguments `providerData` in [nutjs](https://github.com/nut-tree/nut.js/blob/develop/lib/optionalsearchparameters.class.ts) implemented in nutjs > version 3, also available in standalone
- incresed accuracy (x10)
- incresed perfomance (~x2)
- added some customOptions for arguments `params?: OptionalSearchParameters` in [nutjs](https://github.com/nut-tree/nut.js/blob/develop/lib/optionalsearchparameters.class.ts) !not implemented in nutjs yet, but available in standalone
- added standalone

@@ -49,11 +49,11 @@

```javascript
//@udarrr/template-matcher@2.0.1 with nutjs 3.1.1 options
//nutjs options
{
confidence?: number,
providerData?: {
searchMultipleScales?: boolean,
methodType?: MethodNameType;
scaleSteps?: Array<number>;
roi?: Region;
debug?: boolean
searchMultipleScales?: boolean,
customOptions?: {
methodType: MethodNameType;
scaleSteps: Array<number>;
roi: Region;
debug: boolean
},

@@ -64,3 +64,3 @@ }

```typescript
//standalone @udarrr/template-matcher@2.0.1
//standalone
{

@@ -70,8 +70,8 @@ haystack?: string | Image,

confidence?: number,
providerData?: {
searchMultipleScales?: boolean,
methodType?: MethodNameType;
scaleSteps?: Array<number>;
roi?: Region;
debug?: boolean
searchMultipleScales?: boolean,
customOptions?: {
methodType: MethodNameType;
scaleSteps: Array<number>;
roi: Region;
debug: boolean
},

@@ -78,0 +78,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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