-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mask parameter to matrix.matchTemplate
add examples for matchTemplate with and without mask.
- Loading branch information
Arthur Cinader
committed
Jun 23, 2016
1 parent
5fb426a
commit f920053
Showing
7 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// see https://github.com/Itseez/opencv/blob/master/samples/cpp/mask_tmpl.cpp | ||
const cv = require('../lib/opencv'); | ||
|
||
const TM_CCORR_NORMED = 3 | ||
const imageFilename = 'files/lena_tmpl.jpg'; | ||
const templateFilename = 'files/tmpl.png'; | ||
const maskFilename = 'files/mask.png'; | ||
const outFilename = 'tmp/match-template-mask.png'; | ||
|
||
cv.readImage(imageFilename, function(err, im) { | ||
if (err) throw err; | ||
cv.readImage(templateFilename, function (err, tmpl) { | ||
if (err) throw err; | ||
const res = im.matchTemplate(templateFilename, TM_CCORR_NORMED, maskFilename); | ||
const minMax = res.minMaxLoc(); | ||
const topLeft = minMax.maxLoc; | ||
im.rectangle([topLeft.x, topLeft.y], [tmpl.width(), tmpl.height()], [0, 255,0], 2); | ||
|
||
im.save(outFilename); | ||
console.log('Image saved to ' + outFilename); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const cv = require('../lib/opencv'); | ||
|
||
const TM_CCORR_NORMED = 3; | ||
const imageFilename = 'files/stuff.png'; | ||
const templateFilename = 'files/stuff-template.png'; | ||
const outFilename = 'tmp/match-template.png'; | ||
|
||
cv.readImage(imageFilename, function (err, im) { | ||
if (err) throw err; | ||
cv.readImage(templateFilename, function (err, tmpl) { | ||
if (err) throw err; | ||
const res = im.matchTemplate(templateFilename, TM_CCORR_NORMED); | ||
const minMax = res.minMaxLoc(); | ||
const topLeft = minMax.maxLoc; | ||
im.rectangle([topLeft.x, topLeft.y], [tmpl.width(), tmpl.height()], [0, 255,0], 2); | ||
|
||
im.save(outFilename); | ||
console.log('Image saved to ' + outFilename); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters