peterbraden/node-opencv

matchTemplate by matrix is not work.

Closed this issue · 2 comments

The following is very well:

import * as opencv from 'opencv';

opencv.readImage('img/sc1.png', (err, imWork) => {
    let result = imWork.matchTemplate('img/number/w0.png', 3);
    result[0].save('test/test.png');
});

However, the following error occurs:

import * as opencv from 'opencv';

opencv.readImage('img/sc1.png', (err, imWork) => {
    opencv.readImage('img/number/w0.png', (err, imNum) => {
        imWork.matchTemplate(imNum, 3);
    });
});
OpenCV(3.4.1) Error: Assertion failed ((depth == 0 || depth == 5) && type == _templ.type() && _img.dims() <= 2) in cv::matchTemplate, file C:\build\master_winpack-build-win64-vc14\opencv\modules\imgproc\src\templmatch.cpp, line 1102

Please tell me what I miss something.

I think the first way is to read the image file from disk every time.

I've already checked the following link:
#387

But it was not for my case.

Please help me.

Isn't it opencv.Matrix.matchTemplateByMatrix()?

Seeing the source src/Matrix.cc,
opencv.Matrix.matchTemplate() requires (string, unsigned int) as its arguments, and
opencv.Matrix.matchTemplateByMatrix() does (opencv.Matrix, unsigned int).

@jeemin1
grayed the image using cvtColor(cv.COLOR_BGR2GRAY) before matchTemplate