如果源图像和LUT似乎都兼容,为什么openCV cv2.LUT()会引发断言?

时间:2019-02-08 03:13:40

标签: python python-3.x opencv runtime-error cv2

我遇到一些问题,以便能够在python 3.6.5中使用openCV(4.0.0)将LUT应用于图像

从文档中指出的256个元素的LUT(查找表)开始,并尝试将其应用于“一线源图像”(因为更复杂的图像也给我带来了问题),始终会产生一个有关通道不兼容,不连续或不是正确的数据类型(8位)的断言错误。

但是在打印矢量信息,尺寸和通道,数据类型时,一切似乎都是正确的,而且我猜(但我不知道如何检查python)的连续性也很好。

有人知道为什么我无法应用LUT吗?

我创建了一个自定义函数来打印数组信息'print_2Darray_Info()',以检查形状,数据类型,平均值和最大值/最小值。

_______代码_________

customColorPalette = numpy.asarray([(255,255,255), ... , ( 255,150,0)],dtype=numpy.uint8)

testIMG = numpy.asarray([(1,1,1), ... ,( 255,255,0)],dtype=numpy.uint8)

print_2Darray_Info(customColorPalette,"customColorPalette")

print_2Darray_Info(test001,"test001")

cv2.LUT(arr8C3,customColorPalette)

_______输出_________

Array info for 'customColorPalette' ==> shape:  (256, 3)  Mean:  186.94661458333334  datatype:  <class 'numpy.uint8'>  Max and Min:  255 0
Array info for 'test001' ==> shape:  (256, 3)  Mean:  183.97005208333334  datatype:  <class 'numpy.uint8'>  Max and Min:  255 0
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-192-aff71f46c372> in <module>
     11 print_2Darray_Info(customColorPalette,"customColorPalette")
     12 print_2Darray_Info(test001,"test001")
---> 13 cv2.LUT(testIMG,customColorPalette)

error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\core\src\lut.cpp:368: error: (-215:Assertion failed) (lutcn == cn || lutcn == 1) && _lut.total() == 256 && _lut.isContinuous() && (depth == CV_8U || depth == CV_8S) in function 'cv::LUT'

我尝试将LUT应用于具有这些形状的图像,并得到相同的错误: 形状:(120、160、3) 形状:(120、160) 形状:(120,3) 形状:(256,3)

我希望断言能够成功,并将LUT应用于src映像。

0 个答案:

没有答案