justadudewhohacks / opencv4nodejs

Nodejs bindings to OpenCV 3 and OpenCV 4
MIT License
4.97k stars 827 forks source link

Error: CalcHist - object has no property: ranges #865

Open black-posterus opened 1 year ago

black-posterus commented 1 year ago

使用官方进行读取图片并进行直方图计算 代码如下

  const img = cv.imread(imgPath, cv.IMREAD_GRAYSCALE);
  const histSize = [256];
  const channels = [0];
  const ranges = [0, 256];
  console.log('img',img)
  const hist = cv.calcHist(img, channels, new cv.Mat([256], [1], cv.CV_32F), histSize, ranges);
  return hist;

打印的图片数据如下

img Mat {
  step: 375,
  elemSize: 1,
  sizes: [ 3243, 375 ],
  empty: false,
  depth: 0,
  dims: 2,
  channels: 1,
  type: 0,
  cols: 375,
  rows: 3243 }

报错Error: CalcHist - object has no property: ranges at Error (native) at calcHistogram (/app/histogram_opencv.js:30:19) at calcImageSimilarity (/app/histogram_opencv.js:35:17) at processImages (/app/histogram_opencv.js:60:28) at Object. (/app/histogram_opencv.js:70:1) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3)

luoxihui commented 1 year ago

你好,方便给我一份编译之后的opencv4nodejs么,我本机怎么都安装不上,试了网上各种办法,放弃了,想着直接拷贝到项目内部引用