@@ -127,7 +127,6 @@ test(".norm", function(assert){
127
127
128
128
var errorL2 = im . norm ( im2 , cv . Constants . NORM_L2 ) ;
129
129
assert . equal ( errorL2 , 7295.591339980605 ) ;
130
-
131
130
errorL2 = im . norm ( im , cv . Constants . NORM_L2 ) ;
132
131
assert . equal ( errorL2 , 0 ) ;
133
132
assert . end ( ) ;
@@ -368,15 +367,29 @@ test('Mean', function(assert) {
368
367
369
368
test ( 'MatchTemplateByMatrix' , function ( assert ) {
370
369
var cv = require ( '../lib/opencv' ) ;
371
- cv . readImage ( "./examples/files/car1.jpg" , function ( err , target ) {
372
- cv . readImage ( "./examples/files/car1_template.jpg" , function ( err , template ) {
373
- var res = target . matchTemplateByMatrix ( template , cv . Constants . TM_CCORR_NORMED ) ;
370
+ var targetFilename = "./examples/files/car1.jpg" ;
371
+ var templateFilename = "./examples/files/car1_template.jpg" ;
372
+ cv . readImage ( targetFilename , function ( err , target ) {
373
+ cv . readImage ( templateFilename , function ( err , template ) {
374
+ var TM_CCORR_NORMED = 3 ;
375
+ var res = target . matchTemplateByMatrix ( template , TM_CCORR_NORMED ) ;
374
376
var minMax = res . minMaxLoc ( ) ;
375
377
var topLeft = minMax . maxLoc ;
376
- assert . ok ( topLeft , "Found Match" ) ;
377
- console . log ( topLeft . x === 717 ) ;
378
- assert . equal ( topLeft . x , 717 , "match location x === 717" ) ;
379
- assert . equal ( topLeft . y , 0 , "match location y === 717" ) ;
378
+ assert . ok ( topLeft , "RGB Found Match" ) ;
379
+ assert . equal ( topLeft . x , 42 , "match location x === 42" ) ;
380
+ assert . equal ( topLeft . y , 263 , "match location y === 263" ) ;
381
+ target . canny ( 5 , 300 ) ;
382
+ template . canny ( 5 , 300 ) ;
383
+ res = target . matchTemplateByMatrix ( template , TM_CCORR_NORMED ) ;
384
+ minMax = res . minMaxLoc ( ) ;
385
+ topLeft = minMax . maxLoc ;
386
+ target . save ( "./target.png" ) ;
387
+ template . save ( "./template.png" ) ;
388
+ // res.rectangle([topLeft.x, topLeft.y], [template.width(), template.height()], [0, 255,0], 2);
389
+ res . save ( "./result.png" ) ;
390
+ assert . ok ( topLeft , "Canny edge Found Match" ) ;
391
+ assert . equal ( topLeft . x , 42 , "match location x === 42" ) ;
392
+ assert . equal ( topLeft . y , 263 , "match location y === 263" ) ;
380
393
assert . end ( ) ;
381
394
} ) ;
382
395
} )
0 commit comments