Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的代码中的轨迹栏没有显示任何值?_Python_Opencv - Fatal编程技术网

Python 我的代码中的轨迹栏没有显示任何值?

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

我正在学习使用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 (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改为最高值