@udarrr/template-matcher
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -82,5 +82,2 @@ "use strict"; | ||
matchedResults.push(new nut_js_1.MatchResult(isMethodTypeMaxOrMin ? 1.0 - minMax.minVal : minMax.maxVal, new nut_js_1.Region(minMax[locType].x, minMax[locType].y, needle.cols, needle.rows))); | ||
if (firstMach && matchedResults.length && matchedResults[0].confidence >= confidence) { | ||
return { results: matchedResults, haystack: haystack }; | ||
} | ||
if (debug) { | ||
@@ -90,2 +87,5 @@ cv.imshow('debug iteration', haystack); | ||
} | ||
if (firstMach && matchedResults.length && matchedResults[0].confidence >= confidence) { | ||
return { results: matchedResults, haystack: haystack }; | ||
} | ||
} | ||
@@ -92,0 +92,0 @@ } |
@@ -11,3 +11,2 @@ import { ImageFinderInterface, MatchRequest, MatchResult } from '@nut-tree/nut-js'; | ||
export default class TemplateMatchingFinder implements ImageFinderInterface { | ||
private scaleSteps; | ||
constructor(); | ||
@@ -14,0 +13,0 @@ private initData; |
@@ -20,13 +20,10 @@ "use strict"; | ||
class TemplateMatchingFinder { | ||
constructor() { | ||
this.scaleSteps = [1, 0.9, 0.8, 0.7, 0.6, 0.5]; | ||
} | ||
constructor() { } | ||
async initData(matchRequest) { | ||
var _a, _b, _c, _d, _e; | ||
let confidence = ((matchRequest.customOptions && ((_a = matchRequest.customOptions) === null || _a === void 0 ? void 0 : _a.methodType) === match_image_function_1.MethodEnum.TM_SQDIFF_NORMED) || | ||
(matchRequest.customOptions && ((_b = matchRequest.customOptions) === null || _b === void 0 ? void 0 : _b.methodType) === match_image_function_1.MethodEnum.TM_SQDIFF)) && | ||
matchRequest.confidence === 0.99 | ||
var _a, _b, _c, _d, _e, _f; | ||
const customMatchRequest = matchRequest; | ||
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 | ||
? 0.998 | ||
: (matchRequest.customOptions && ((_c = matchRequest.customOptions) === null || _c === void 0 ? void 0 : _c.methodType) === match_image_function_1.MethodEnum.TM_CCOEFF_NORMED) || | ||
(matchRequest.customOptions && ((_d = matchRequest.customOptions) === null || _d === void 0 ? void 0 : _d.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) === match_image_function_1.MethodEnum.TM_CCOEFF_NORMED) || | ||
(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 | ||
@@ -36,3 +33,5 @@ : matchRequest.confidence === 0.99 | ||
: matchRequest.confidence; | ||
let scaleSteps = ((_e = matchRequest.customOptions) === null || _e === void 0 ? void 0 : _e.scaleSteps) || this.scaleSteps; | ||
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 needle = await loadNeedle(matchRequest.needle); | ||
@@ -49,14 +48,13 @@ if (!needle || needle.empty) { | ||
} | ||
return { haystack: haystack, needle: needle, confidence: confidence, scaleSteps: scaleSteps }; | ||
return { haystack: haystack, needle: needle, confidence: confidence, scaleSteps: scaleSteps, methodType: methodType, debug: debug }; | ||
} | ||
async findMatches(matchRequest) { | ||
var _a, _b, _c, _d; | ||
let matchResults = []; | ||
let { haystack, needle, confidence, scaleSteps } = await this.initData(matchRequest); | ||
let { haystack, needle, confidence, scaleSteps, methodType, debug } = await this.initData(matchRequest); | ||
if (!matchRequest.searchMultipleScales) { | ||
const overwrittenResults = await match_image_function_1.MatchTemplate.matchImagesByWriteOverFounded(haystack, needle, confidence, (_a = matchRequest.customOptions) === null || _a === void 0 ? void 0 : _a.methodType, (_b = matchRequest.customOptions) === null || _b === void 0 ? void 0 : _b.debug); | ||
const overwrittenResults = await match_image_function_1.MatchTemplate.matchImagesByWriteOverFounded(haystack, needle, confidence, methodType, debug); | ||
matchResults.push(...overwrittenResults.results); | ||
} | ||
else { | ||
const scaledResults = await this.searchMultipleScales(haystack, needle, confidence, scaleSteps, (_c = matchRequest.customOptions) === null || _c === void 0 ? void 0 : _c.methodType, (_d = matchRequest.customOptions) === null || _d === void 0 ? void 0 : _d.debug); | ||
const scaledResults = await this.searchMultipleScales(haystack, needle, confidence, scaleSteps, methodType, debug); | ||
matchResults.push(...scaledResults); | ||
@@ -90,6 +88,6 @@ } | ||
async findMatch(matchRequest) { | ||
var _a, _b, _c, _d; | ||
let { haystack, needle, confidence, scaleSteps } = await this.initData(matchRequest); | ||
var _a; | ||
let { haystack, needle, confidence, scaleSteps, methodType, debug } = await this.initData(matchRequest); | ||
if (!matchRequest.searchMultipleScales) { | ||
const matches = await match_image_function_1.MatchTemplate.matchImages(haystack, needle, (_a = matchRequest.customOptions) === null || _a === void 0 ? void 0 : _a.methodType, (_b = matchRequest.customOptions) === null || _b === void 0 ? void 0 : _b.debug); | ||
const matches = await match_image_function_1.MatchTemplate.matchImages(haystack, needle, methodType, (_a = matchRequest.customOptions) === null || _a === void 0 ? void 0 : _a.debug); | ||
const result = await this.getValidatedMatches([matches.data], matchRequest, confidence); | ||
@@ -99,7 +97,7 @@ return result[0]; | ||
else { | ||
const scaledResults = await this.searchMultipleScales(haystack, needle, confidence, scaleSteps, (_c = matchRequest.customOptions) === null || _c === void 0 ? void 0 : _c.methodType, (_d = matchRequest.customOptions) === null || _d === void 0 ? void 0 : _d.debug, true); | ||
const scaledResults = await this.searchMultipleScales(haystack, needle, confidence, scaleSteps, methodType, debug, true); | ||
return (await this.getValidatedMatches([scaledResults[0]], matchRequest, confidence))[0]; | ||
} | ||
} | ||
async searchMultipleScales(haystack, needle, confidence = 0.8, scaleSteps = this.scaleSteps, methodType = match_image_function_1.MethodEnum.TM_CCOEFF_NORMED, debug = false, firstMach = false) { | ||
async searchMultipleScales(haystack, needle, confidence, scaleSteps, methodType, debug, firstMach = false) { | ||
const results = []; | ||
@@ -118,3 +116,3 @@ const needleData = await this.scaleNeedle(haystack, needle, confidence, scaleSteps, methodType, debug, firstMach); | ||
} | ||
async scaleHaystack(haystack, needle, confidence = 0.8, scaleSteps = this.scaleSteps, methodType = match_image_function_1.MethodEnum.TM_CCOEFF_NORMED, debug = false, firstMach = false) { | ||
async scaleHaystack(haystack, needle, confidence, scaleSteps, methodType, debug, firstMach = false) { | ||
const results = []; | ||
@@ -140,3 +138,3 @@ let overWrittenScaledHaystackResult = { results: results, haystack: haystack }; | ||
} | ||
async scaleNeedle(haystack, needle, confidence = 0.8, scaleSteps = this.scaleSteps, methodType = match_image_function_1.MethodEnum.TM_CCOEFF_NORMED, debug = false, firstMatch = false) { | ||
async scaleNeedle(haystack, needle, confidence = 0.8, scaleSteps, methodType, debug, firstMatch = false) { | ||
const results = []; | ||
@@ -143,0 +141,0 @@ let overWrittenScaledNeedleResult = { results: results, haystack: haystack }; |
{ | ||
"name": "@udarrr/template-matcher", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
96004
959