问题遇到的现象和发生背景
定位到目标图像区域
问题相关代码,请勿粘贴截图
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # 转化为 HSV 格式
thresh1 = np.array([190, 0.35, 0.3]) # 目标的低阈值
thresh2 = np.array([245, 1, 1]) # 目标的高阈值
img_1 = cv2.inRange(img_hsv, lowerb = thresh1, upperb = thresh2)
cv2.imshow('原始图像', img) # 显示图像
cv2.imshow('截取图像', img_1)
cv2.waitKey(0)
cv2.destroyAllWindows()
运行结果及报错内容
Traceback (most recent call last):
File "D:/Program Files/pythonProject233/6.py", line 12, in
img_1 = cv2.inRange(img_hsv, lowerb = thresh1, upperb = thresh2)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\core\src\arithm.cpp:1782: error: (-215:Assertion failed) lb.type() == ub.type() in function 'cv::inRange'