@@ -127,7 +127,6 @@ test(".norm", function(assert){
127127
128128 var errorL2 = im . norm ( im2 , cv . Constants . NORM_L2 ) ;
129129 assert . equal ( errorL2 , 7295.591339980605 ) ;
130-
131130 errorL2 = im . norm ( im , cv . Constants . NORM_L2 ) ;
132131 assert . equal ( errorL2 , 0 ) ;
133132 assert . end ( ) ;
@@ -368,15 +367,29 @@ test('Mean', function(assert) {
368367
369368test ( 'MatchTemplateByMatrix' , function ( assert ) {
370369 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 ) ;
374376 var minMax = res . minMaxLoc ( ) ;
375377 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" ) ;
380393 assert . end ( ) ;
381394 } ) ;
382395 } )
0 commit comments