如何在节点js中进行np.where以便与node-opencv进行模板匹配

时间:2017-06-19 19:19:45

标签: python node.js opencv numpy node-opencv

我有这个代码在python中完全符合我的要求:

import cv2
import numpy as np

img_rgb = cv2.imread('large.jpg')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('small.jpg',0)
w, h = template.shape[::-1]

res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.9
print(res)
loc = np.where( res >= threshold)
print(loc)
for pt in zip(*loc[::-1]):
    cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

cv2.imwrite('res.png',img_rgb)

我正在使用node-opencv,到目前为止我有这段代码:

const cv = require('opencv');

cv.readImage("./samples/profileImgs/large.jpg", function (err, largeImg) {
    const res = largeImg.matchTemplate("./samples/profileImgs/small.jpg", 0);
    console.log(res);
});

哪个输出:

  

[[Matrix 1044x1820],185,68,101,37]

我想知道如何在js中对Matrix进行np.where( res >= threshold),任何等效的库?

0 个答案:

没有答案