Python 我的代码中的轨迹栏没有显示任何值?
我正在学习使用OpenCV HSV检测特定颜色的教程。为了识别正确的HSV值,我(如教程中所示)添加了轨迹栏来检测HSV的上限和下限值。一切正常,但我的轨迹栏上没有显示任何值 我正在MacBookPro OS 10.13.6上使用PyCharm 2018.2.4进行此操作。当在我的虚拟环境中签入终端时,OpenCV显示为4.0.0-dev,python版本为3.7.1 这是我的密码:Python 我的代码中的轨迹栏没有显示任何值?,python,opencv,Python,Opencv,我正在学习使用OpenCV HSV检测特定颜色的教程。为了识别正确的HSV值,我(如教程中所示)添加了轨迹栏来检测HSV的上限和下限值。一切正常,但我的轨迹栏上没有显示任何值 我正在MacBookPro OS 10.13.6上使用PyCharm 2018.2.4进行此操作。当在我的虚拟环境中签入终端时,OpenCV显示为4.0.0-dev,python版本为3.7.1 这是我的密码: # script for detecting colours with OpenCV using HSV (Hu
# script for detecting colours with OpenCV using HSV (Hue, Saturation, Value)
# credits https://www.youtube.com/watch?v=AMFhjir4WgQ
import cv2
import numpy as np
def nothing(x):
#any function here
pass
cap = cv2.VideoCapture(0) #captures video from the main camera,
# create a trackbar window to help tune the detection and find the HSV
cv2.namedWindow("Trackbars")
# create the trackbars for each HSV value
cv2.createTrackbar("L-H", "Trackbars", 0, 180, nothing)
cv2.createTrackbar("L-S", "Trackbars", 0, 255, nothing)
cv2.createTrackbar("L-V", "Trackbars", 0, 255, nothing)
cv2.createTrackbar("U-H", "Trackbars", 180, 180, nothing)
cv2.createTrackbar("U-S", "Trackbars", 255, 255, nothing)
cv2.createTrackbar("U-V", "Trackbars", 255, 255, nothing)
while True:
_, frame = cap.read() # read each video frame
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # converts BGR colour to HSV
l_h = cv2.getTrackbarPos("L-H", "Trackbars")
l_s = cv2.getTrackbarPos("L-S", "Trackbars")
l_v = cv2.getTrackbarPos("L-V", "Trackbars")
u_h = cv2.getTrackbarPos("U-H", "Trackbars")
u_s = cv2.getTrackbarPos("U-S", "Trackbars")
u_v = cv2.getTrackbarPos("U-V", "Trackbars")
# set upper and lower red values
lower_red = np.array([l_h, l_s, l_v])
upper_red = np.array([u_h, u_s, u_v])
mask = cv2.inRange(hsv, lower_red, upper_red) # identify red in frame
#cv2.imshow("Frame", frame) # opens a window to show original video being captured
resize = cv2.resize(mask, (960, 540))
cv2.imshow("Mask", resize) # opens a window to show the mask
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
我不知道这是否有帮助,但你的色调应该在0-178范围,而不是0-180。 所以我把它从0-179改为最低值,从179-179改为最高值