@udarrr/template-matcher
Advanced tools
Comparing version 1.1.9 to 1.2.0
@@ -9,3 +9,3 @@ import { Image, ImageFinderInterface, MatchRequest, MatchResult, Region } from '@nut-tree/nut-js'; | ||
}; | ||
declare type OptionsConfidnce = { | ||
declare type OptionsConfidence = { | ||
-readonly [Property in keyof Pick<MatchRequest, 'confidence'>]?: number; | ||
@@ -16,3 +16,3 @@ }; | ||
}; | ||
declare type CustomMatchRequest = OptionsHaystack & OptionsNeedle & OptionsConfidnce & OptionsSearchMultipleScales & { | ||
declare type CustomOptionsType = { | ||
customOptions?: { | ||
@@ -25,4 +25,9 @@ methodType?: MethodNameType; | ||
}; | ||
declare type CustomMatchRequest = OptionsHaystack & OptionsNeedle & OptionsConfidence & OptionsSearchMultipleScales & CustomOptionsType; | ||
export declare type CustomConfigType = OptionsConfidence & OptionsSearchMultipleScales & CustomOptionsType; | ||
export default class TemplateMatchingFinder implements ImageFinderInterface { | ||
private _config; | ||
constructor(); | ||
get(): CustomConfigType; | ||
set(config: CustomConfigType): void; | ||
private loadNeedle; | ||
@@ -29,0 +34,0 @@ private loadHaystack; |
@@ -8,3 +8,11 @@ "use strict"; | ||
class TemplateMatchingFinder { | ||
constructor() { } | ||
constructor() { | ||
this._config = { confidence: 0.8, searchMultipleScales: true, customOptions: { scaleSteps: [1, 0.9, 0.8, 0.7, 0.6, 0.5], methodType: match_image_function_1.MethodEnum.TM_CCOEFF_NORMED, debug: false } }; | ||
} | ||
get() { | ||
return this._config; | ||
} | ||
set(config) { | ||
this._config = { ...config, ...this._config }; | ||
} | ||
async loadNeedle(image) { | ||
@@ -49,3 +57,3 @@ if (typeof image !== 'string') { | ||
async initData(matchRequest) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; | ||
const customMatchRequest = matchRequest; | ||
@@ -56,10 +64,10 @@ const confidence = customMatchRequest.customOptions && ((_a = customMatchRequest.customOptions) === null || _a === void 0 ? void 0 : _a.methodType) === match_image_function_1.MethodEnum.TM_SQDIFF && matchRequest.confidence === 0.99 | ||
(customMatchRequest.customOptions && ((_c = customMatchRequest.customOptions) === null || _c === void 0 ? void 0 : _c.methodType) === match_image_function_1.MethodEnum.TM_CCORR_NORMED && matchRequest.confidence === 0.99) | ||
? 0.8 | ||
? this._config.confidence | ||
: matchRequest.confidence === 0.99 || typeof matchRequest.confidence === 'undefined' | ||
? 0.8 | ||
? this._config.confidence | ||
: matchRequest.confidence; | ||
const searchMultipleScales = customMatchRequest.searchMultipleScales ? customMatchRequest.searchMultipleScales : true; | ||
const scaleSteps = ((_d = customMatchRequest.customOptions) === null || _d === void 0 ? void 0 : _d.scaleSteps) || [1, 0.9, 0.8, 0.7, 0.6, 0.5]; | ||
const methodType = ((_e = customMatchRequest.customOptions) === null || _e === void 0 ? void 0 : _e.methodType) || match_image_function_1.MethodEnum.TM_CCOEFF_NORMED; | ||
const debug = ((_f = customMatchRequest.customOptions) === null || _f === void 0 ? void 0 : _f.debug) || false; | ||
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); | ||
@@ -69,3 +77,3 @@ if (!needle || needle.data.empty) { | ||
} | ||
const haystack = await this.loadHaystack(matchRequest.haystack, (_g = customMatchRequest.customOptions) === null || _g === void 0 ? void 0 : _g.roi); | ||
const haystack = await this.loadHaystack(matchRequest.haystack, (_k = customMatchRequest.customOptions) === null || _k === void 0 ? void 0 : _k.roi); | ||
if (!haystack || haystack.data.empty) { | ||
@@ -85,3 +93,3 @@ throw new Error(`Failed to load ${matchRequest && matchRequest.haystack && typeof matchRequest.haystack === 'string' && !matchRequest.haystack ? matchRequest.haystack : matchRequest.haystack.id}, got empty image.`); | ||
searchMultipleScales: searchMultipleScales, | ||
roi: (_h = customMatchRequest.customOptions) === null || _h === void 0 ? void 0 : _h.roi, | ||
roi: (_l = customMatchRequest.customOptions) === null || _l === void 0 ? void 0 : _l.roi, | ||
}; | ||
@@ -88,0 +96,0 @@ } |
{ | ||
"name": "@udarrr/template-matcher", | ||
"version": "1.1.9", | ||
"version": "1.2.0", | ||
"main": "dist/index", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
111865
1052