Open zheleznov22 opened 7 years ago
+1
I was able to get template match results by using the output of im.matchTemplateByMatrix
rather than im.matchTemplate
.
@peterbraden The release currently published to npm does not have the templateMatches
function correct? Am trying to build locally on macOS but build is failing with similar gyp errors mentioned in other issues.
26 days later I see there is no reply, so wanted to drop a hint for anyone else looking for a temporary (suboptimal) solution to this issue... It is possible to use Jimp.distance
to compare two image buffers read in by Jimp.
This looks something like this in my program:
Jimp.read(imageTemplates[i].matrix.toBuffer(), function (err, image1) {
Jimp.read(croppedScreenTarget.toBuffer(), function (err, image2) {
// ...
let distance = Jimp.distance(image1, image2);
if (distance < 0.25) {
robot.moveMouse(topLeft.x+15, topLeft.y+15);
// ...
}
// ...
}
}
Leaving the back-bending necessary to get the buffers in Jimp as an exercise for the reader. Not sure how big the performance hit with this workaround, and certainly less accurate than what OpenCV could give us if templateMatches
were implemented.
@leoj3n I started to use openCV and this library last week on my Macbook. And I just finished my little project using templateMatches function, so I am petty sure it is still exist in node-opencv.
As for the error, I think you can try this steps. It fixed my node-pre-gyp errors when I did npm istall.
@zheleznov22: Here is a minimal example for using templateMatching: https://github.com/strarsis/node-opencv-templatematching-test
Can anyone please tell me how is the "templateMatches" function supposed to be used? Here is the code example:
cv.readImage('./source.png', function(err, im) { if (err) return console.error('error loading image'); var output = im.matchTemplate('./template.png', 3); console.log(output); var matches = output.templateMatches(0.80, 1.0, 5, true, 0, 0); console.log(matches); });
This codes returns the error "templateMatches is not a function". output has the matrix as the first element, if we try to use it with templateMatches function:var matches = output[0].templateMatches(0.80, 1.0, 5, true, 0, 0);
as the result we will see the following:[ , , , , ]
What am I doing wrong?