Skip to content

Commit 1d1a864

Browse files
committed
(#101) Improved error message if match confidence is not sufficient
1 parent 7032506 commit 1d1a864

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/provider/opencv/template-matching-finder.class.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ export class TemplateMatchingFinder implements FinderInterface {
179179
const potentialMatches = matches
180180
.filter(match => match.confidence >= matchRequest.confidence);
181181
if (potentialMatches.length === 0) {
182-
reject(`Unable to locate ${matchRequest.pathToNeedle}, no match!`);
182+
const bestMatch = matches.sort((a, b) => a.confidence - b.confidence).pop();
183+
if (bestMatch) {
184+
reject(`No match with required confidence ${matchRequest.confidence}. Best match: ${bestMatch.confidence} at ${bestMatch.location}`)
185+
} else {
186+
reject(`Unable to locate ${matchRequest.pathToNeedle}, no match!`);
187+
}
183188
}
184189
resolve(potentialMatches[0]);
185190
} catch (e) {

0 commit comments

Comments
 (0)