Python ';元组';对象没有属性';夹子';

Python ';元组';对象没有属性';夹子';,python,opencv,image-processing,tuples,Python,Opencv,Image Processing,Tuples,我在下面的代码中得到了一个我不理解的错误 imgColor = cv2.imread(fileName, cv2.IMREAD_COLOR) imgColor1= cv2.cvtColor(imgColor, cv2.COLOR_BGR2HSV) ret,thresh1 = cv2.threshold(imgColor1,127,255,cv2.THRESH_BINARY) ret,thresh2 = cv2.threshold(imgColor1,127,255,cv2.THRESH_BIN

我在下面的代码中得到了一个我不理解的错误

imgColor = cv2.imread(fileName, cv2.IMREAD_COLOR)
imgColor1= cv2.cvtColor(imgColor, cv2.COLOR_BGR2HSV)

ret,thresh1 = cv2.threshold(imgColor1,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(imgColor1,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(imgColor1,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(imgColor1,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(imgColor1,127,255,cv2.THRESH_TOZERO_INV)

threshold_titles = ('BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV')
images = [ thresh1, thresh2, thresh3, thresh4, thresh5]

threshold_images = {threshold : cv2.threshold(imgColor1,127,255, getattr(cv2,'THRESH_'+ threshold )) 
    for threshold in threshold_titles}
for threshold in threshold_images :
   cv2_imshow(threshold_images[threshold])
错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-31-2702c0b95a98> in <module>()
     13     for threshold in threshold_titles}
     14 for threshold in threshold_images :
---> 15    cv2_imshow(threshold_images[threshold])

/usr/local/lib/python3.6/dist-packages/google/colab/patches/__init__.py in cv2_imshow(a)
     20       image.
     21   """
---> 22   a = a.clip(0, 255).astype('uint8')
     23   # cv2 stores colors as BGR; convert to RGB
     24   if a.ndim == 3:

AttributeError: 'tuple' object has no attribute 'clip'

请解释为什么会发生这种情况,以及我如何解决这个问题。如果有人能对此问题提供任何建议,那就太好了。

您正在传递给cv2\u imshow cv2.threshold的结果,它是一个元组。您需要修改对的调用,例如

cv2\u imshow(阈值图像[阈值][1])

您正在传递给cv2\u imshow cv2.threshold的结果,它是一个元组。您需要修改对的调用,例如

cv2\u imshow(阈值图像[阈值][1])
color_spaces = ('RGB','GRAY','HSV','LAB','XYZ','YUV')
color_images = {color : cv2.cvtColor(imgColor, getattr(cv2,'COLOR_BGR2' + color))
    for color in color_spaces}
for color in color_images:
    cv2_imshow(color_images[color])