OpenCV 调整得到想要的颜色
import cv2
import numpy as np
cap = cv2.VideoCapture(0)#打开摄像头
pic=np.zeros((480, 640, 3),dtype=np.uint8)
def nothing():
pass
cv2.namedWindow("HSV",0)
cv2.resizeWindow("HSV",500,300)
cv2.createTrackbar("H_L","HSV",0,180,nothing)
cv2.createTrackbar("S_L","HSV",0,255,nothing)
cv2.createTrackbar("V_L","HSV",0,255,nothing)
cv2.createTrackbar("H_U","HSV",0,180,nothing)
cv2.createTrackbar("S_U","HSV",0,255,nothing)
cv2.createTrackbar("V_U","HSV",0,255,nothing)
while cap.isOpened():
_,frame = cap.read()
if not _:
break
imgray = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
cv2.imshow("frame",frame)
h_l = cv2.getTrackbarPos("H_L","HSV")
s_l = cv2.getTrackbarPos("S_L","HSV")
v_l = cv2.getTrackbarPos("V_L","HSV")
h_u = cv2.getTrackbarPos("H_U","HSV")
s_u = cv2.getTrackbarPos("S_U","HSV")
v_u = cv2.getTrackbarPos("V_U","HSV")
lower = np.array([h_l,s_l,v_l])
upper = np.array([h_u,s_u,v_u])
mask = cv2.inRange(imgray,lower,upper)
img = cv2.add(frame,pic,mask=mask)
cv2.imshow("img",img)
k = cv2.waitKey(20) &0xff
if k == 27:
break