无法读取未定义的nodejs opencv

时间:2018-09-22 21:10:43

标签: node.js opencv

当我将open cv安装为节点mondule时,会出现此错误

const targetHist= cv.histogram.calcHist( img, [0], [size], [range], uniform);
                               ^
TypeError: Cannot read property 'calcHist' of undefined

如果我克隆该模块并将代码放入示例文件之一,那么它将起作用。 (https://github.com/peterbraden/node-opencv/blob/master/examples/calc-hist.js

我正在运行的代码是:

var cv = require('opencv');

cv.readImage('./coral.jpg', function (err, img) {


  if (err) {
      throw err;
    }

    const width = img.width();
    const height = img.height();

    if (width < 1 || height < 1) {
      throw new Error('Image has no size');
    }

    var size = 10,
        range = [0, 256],
        uniform = true

    const targetHist= cv.histogram.calcHist( img, [0], [size], [range], uniform);
    console.log(targetHist)
});

我正在使用的open cv版本是:“ opencv”:“ ^ 6.0.0”

0 个答案:

没有答案