Python 如果源映像和LUT看起来都兼容,为什么openCV cv2.LUT()会抛出断言?

Python 如果源映像和LUT看起来都兼容,为什么openCV cv2.LUT()会抛出断言?,python,python-3.x,opencv,runtime-error,cv2,Python,Python 3.x,Opencv,Runtime Error,Cv2,我在使用python 3.6.5中的openCV(4.0.0)将LUT应用于图像时遇到了一些问题 从文档中所示的256个元素的LUT(查找表)开始,并尝试将其应用于“一行源映像”(因为更复杂的映像也会给我带来问题),始终会产生关于通道不兼容、不连续或数据类型不正确(8位)的断言错误 但在打印向量信息、维度和通道、数据类型时,一切似乎都是正确的,我想(但我不知道如何在python中检查)连续性也很好 知道我为什么不能应用LUT吗 我创建了一个自定义函数来打印数组信息“print_2Darray_I

我在使用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'
_______输出_________

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'
“customColorPalette”的数组信息==>形状:(256,3)平均值:186.94661458333334数据类型:最大值和最小值:255 0 “test001”的数组信息==>形状:(256,3)平均值:183.9700520833334数据类型:最大值和最小值:255 0 --------------------------------------------------------------------------- 错误回溯(最近一次呼叫上次) 在里面 11打印阵列信息(customColorPalette,“customColorPalette”) 12打印阵列信息(test001,“test001”) --->13 cv2.LUT(testIMG、customColorPalette) 错误:OpenCV(4.0.0)C:\projects\OpenCV python\OpenCV\modules\core\src\lut.cpp:368:错误:(-215:断言失败)(lutcn==cn | | lutcn==1)和&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 我尝试将LUT应用于具有这些形状的图像,但得到了相同的错误: 形状:(120、160、3) 形状:(120160) 形状:(120,3) 形状:(256,3)


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

我想我找到了解决方案,它与语法有关。将LUT定义为:
customColorPalette=numpy.asarray([[(255255255),…,(255150,0)],dtype=numpy.uint8)
将解决此问题。请注意,它需要额外的方括号,这会将矩阵的形状更改为(1,256,3),但这似乎是我发现能够将其应用于图像的唯一方法。我想我找到了解决方案,它与语法有关。将LUT定义为:
customColorPalette=numpy.asarray([[(255255255),…,(255150,0)],dtype=numpy.uint8)
将解决此问题。请注意,它需要额外的方括号,这会将矩阵的形状更改为(1,256,3),但这似乎是我发现能够将其应用于图像的唯一方法。