Add canny match template test

As we can pass matrix as template, detecting canny provide more robust
match if we only care about shape rather than contrast and color.
This commit is contained in:
Sen 2016-07-25 16:48:17 -04:00
parent e578cdb869
commit 495e06a591

View File

@ -127,7 +127,6 @@ test(".norm", function(assert){
var errorL2 = im.norm(im2, cv.Constants.NORM_L2); var errorL2 = im.norm(im2, cv.Constants.NORM_L2);
assert.equal(errorL2, 7295.591339980605); assert.equal(errorL2, 7295.591339980605);
errorL2 = im.norm(im, cv.Constants.NORM_L2); errorL2 = im.norm(im, cv.Constants.NORM_L2);
assert.equal(errorL2, 0); assert.equal(errorL2, 0);
assert.end(); assert.end();
@ -368,15 +367,29 @@ test('Mean', function(assert) {
test('MatchTemplateByMatrix', function(assert) { test('MatchTemplateByMatrix', function(assert) {
var cv = require('../lib/opencv'); var cv = require('../lib/opencv');
cv.readImage("./examples/files/car1.jpg", function(err, target){ var targetFilename = "./examples/files/car1.jpg";
cv.readImage("./examples/files/car1_template.jpg", function(err, template){ var templateFilename = "./examples/files/car1_template.jpg";
var res = target.matchTemplateByMatrix(template, cv.Constants.TM_CCORR_NORMED); cv.readImage(targetFilename, function(err, target){
cv.readImage(templateFilename, function(err, template){
var TM_CCORR_NORMED = 3;
var res = target.matchTemplateByMatrix(template, TM_CCORR_NORMED);
var minMax = res.minMaxLoc(); var minMax = res.minMaxLoc();
var topLeft = minMax.maxLoc; var topLeft = minMax.maxLoc;
assert.ok(topLeft, "Found Match"); assert.ok(topLeft, "RGB Found Match");
console.log(topLeft.x === 717); assert.equal(topLeft.x, 42, "match location x === 42");
assert.equal(topLeft.x, 717, "match location x === 717"); assert.equal(topLeft.y, 263, "match location y === 263");
assert.equal(topLeft.y, 0, "match location y === 717"); target.canny(5,300);
template.canny(5,300);
res = target.matchTemplateByMatrix(template, TM_CCORR_NORMED);
minMax = res.minMaxLoc();
topLeft = minMax.maxLoc;
target.save("./target.png");
template.save("./template.png");
// res.rectangle([topLeft.x, topLeft.y], [template.width(), template.height()], [0, 255,0], 2);
res.save("./result.png");
assert.ok(topLeft, "Canny edge Found Match");
assert.equal(topLeft.x, 42, "match location x === 42");
assert.equal(topLeft.y, 263, "match location y === 263");
assert.end(); assert.end();
}); });
}) })