我正在尝试使用OpenCV来比较两个RGB图像直方图,为此我想在Ruby中创建一个CVHistogram。我不确定params,因为我的代码有错误:
iplimg = OpenCV::IplImage.decode_image(open(icon).read)
dim = 3
sizes = [8,8,8]
ranges = [[0, 255],[0, 255],[0, 255]]
hist = OpenCV::CvHistogram.new(dim, sizes, OpenCV::CV_HIST_ARRAY, ranges, true)
h = hist.calc_hist([iplimg]) # produce error below
这是错误:
/tmp/opencv-tLdZ/opencv-2.4.9/modules/core/src/matrix.cpp:698:错误: (-5)函数cvarrToMat(OpenCV :: CvStsBadArg)中的未知数组类型
这是正确的方法吗?
答案 0 :(得分:0)
iplimg = OpenCV::IplImage.decode_image(open(icon).read) # RGB image
b, g, r = iplimg.split # Split RGB image to 1ch image array [b, g, r]
dim = 3
sizes = [8,8,8]
ranges = [[0, 255],[0, 255],[0, 255]]
hist = OpenCV::CvHistogram.new(dim, sizes, OpenCV::CV_HIST_ARRAY, ranges, true)
h = hist.calc_hist([r, g, b])