(-215:Утверждение не выполнено)

#python #colors #runtime-error #hsv

Вопрос:

Я подписываю прилагаемый код, но возникает следующая ошибка:

строка 21, в pick_color image_mask = cv2.inRange(image_hsv, нижний, верхний) cv2.ошибка: OpenCV(4.5.1) /tmp/pip-req-сборка-ms668fyv/opencv/модули/ядро/src/арифметика.cpp:1799: ошибка: (-215:Утверждение не выполнено) lb.тип() == ub.тип() в функции «inRange»

 import cv2
import numpy as np

image_hsv = None   # global ;(
pixel = (20,60,80) # some stupid default

# mouse callback function
def pick_color(event,x,y,flags,param):
    if event == cv2.EVENT_LBUTTONDOWN:
        pixel = image_hsv [y, x]
        lower = np.array([], dtype=np.uint8)
        upper = np.array([], dtype=np.uint8)

        #you might want to adjust the ranges( -10, etc):
        #upper =  np.array([pixel[0]   10, pixel[1]   10, pixel[2]   40])
        #lower =  np.array([pixel[0] - 10, pixel[1] - 10, pixel[2] - 40])
        upper =  np.array([pixel[0]   10, pixel[1]   10, pixel[2]   40])
        lower =  np.array([pixel[0], pixel[1], pixel[2]])
        print (type(lower), type(upper))
        image_mask = cv2.inRange(image_hsv, lower, upper)
        cv2.imshow("mask", image_mask)

def main(image_to_be_read):
    import sys
    global image_hsv, pixel # so we can use it in mouse callback

    image_src = cv2.imread(image_to_be_read)  # pick.py my.png
    image_hsv = cv2.cvtColor(image_src,cv2.COLOR_BGR2HSV)
    if image_src is None:
        print ("the image read is None............")
        return
    cv2.imshow("bgr",image_src)

    ## NEW ##
    cv2.namedWindow('hsv')
    cv2.setMouseCallback('hsv', pick_color)

    # now click into the hsv img , and look at values:
    image_hsv = cv2.cvtColor(image_src,cv2.COLOR_BGR2HSV)
    cv2.imshow("hsv",image_hsv)

    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__=='__main__':
    image_name = '/home/carlos/pic/TEST_IMAGES/Test_1_R/DJI_0150_R.jpg'
    main(image_name)