@@ -132,29 +132,24 @@ export default class TemplateMatchingFinder implements FinderInterface {
132
132
}
133
133
134
134
public async findMatch ( matchRequest : MatchRequest , debug : boolean = false ) : Promise < MatchResult > {
135
- return new Promise < MatchResult > ( async ( resolve , reject ) => {
136
- try {
137
- const matches = await this . findMatches ( matchRequest , debug ) ;
138
- const potentialMatches = matches
139
- . filter ( match => match . confidence >= matchRequest . confidence ) ;
140
- if ( potentialMatches . length === 0 ) {
141
- matches . sort ( ( a , b ) => a . confidence - b . confidence ) ;
142
- const bestMatch = matches . pop ( ) ;
143
- if ( bestMatch ) {
144
- if ( bestMatch . error ) {
145
- reject ( bestMatch . error . message )
146
- } else {
147
- reject ( `No match with required confidence ${ matchRequest . confidence } . Best match: ${ bestMatch . confidence } at ${ bestMatch . location } ` )
148
- }
149
- } else {
150
- reject ( `Unable to locate ${ matchRequest . pathToNeedle } , no match!` ) ;
151
- }
135
+
136
+ const matches = await this . findMatches ( matchRequest , debug ) ;
137
+ const potentialMatches = matches
138
+ . filter ( match => match . confidence >= matchRequest . confidence ) ;
139
+ if ( potentialMatches . length === 0 ) {
140
+ matches . sort ( ( a , b ) => a . confidence - b . confidence ) ;
141
+ const bestMatch = matches . pop ( ) ;
142
+ if ( bestMatch ) {
143
+ if ( bestMatch . error ) {
144
+ throw new Error ( bestMatch . error . message )
145
+ } else {
146
+ throw new Error ( `No match with required confidence ${ matchRequest . confidence } . Best match: ${ bestMatch . confidence } at ${ bestMatch . location } ` )
152
147
}
153
- resolve ( potentialMatches [ 0 ] ) ;
154
- } catch ( e ) {
155
- reject ( e ) ;
148
+ } else {
149
+ throw new Error ( `Unable to locate ${ matchRequest . pathToNeedle } , no match!` ) ;
156
150
}
157
- } ) ;
151
+ }
152
+ return potentialMatches [ 0 ] ;
158
153
}
159
154
160
155
private searchMultipleScales ( needle : cv . Mat , haystack : cv . Mat ) {
0 commit comments