def color_picker(rect):
global img,img_gray2,hsv
roi=img[rect[0][1]:rect[1][1],rect[0][0]:rect[1][0]]
b,g,r,_=np.uint8(cv2.mean(roi))
color=cv2.cvtColor(np.uint8([[[b,g,r]]]),cv2.COLOR_BGR2HSV)
h= color[0][0][0]
# define range of blue color in HSV
lower = np.array([h-10,50,50])
upper = np.array([h+10,255,255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower, upper)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(img,img, mask= mask)
res2=cv2.bitwise_and(img_gray2,img_gray2, mask= cv2.bitwise_not(mask))
return res+res2
评论列表
文章目录