首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV -跟踪条滑块在视频中保持为零。

OpenCV -跟踪条滑块在视频中保持为零。
EN

Stack Overflow用户
提问于 2014-04-18 00:27:30
回答 1查看 4.7K关注 0票数 1

我试图使用滑块来控制HSV掩蔽的上下界。我可以得到滑块,但不能让它保持我设置的位置,每次新的框架被拉进来,它都会回到零。

代码语言:javascript
复制
import numpy as np
import cv2

def nothing(x):
    pass

cap = cv2.VideoCapture(0)

while(True):

    # Make a window for the video feed  
    cv2.namedWindow('frame',cv2.CV_WINDOW_AUTOSIZE)

    # Capture frame-by-frame
    ret, frame = cap.read()

    # Make the trackbar used for HSV masking    
    cv2.createTrackbar('HSV','frame',0,255,nothing)

    # Name the variable used for mask bounds
    j = cv2.getTrackbarPos('HSV','image')

    # Convert BGR to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    # define range of color in HSV
    lower = np.array([j-10,100,100])
    upper = np.array([j+10,255,255])

    # Threshold the HSV image to get only selected color
    mask = cv2.inRange(hsv, lower, upper)

    # Bitwise-AND mask the original image
    res = cv2.bitwise_and(frame,frame, mask= mask)

    # Display the resulting frame
    cv2.imshow('frame',res)

    # Press q to quit
    if cv2.waitKey(3) & 0xFF == ord('q'):
        break


# When everything is done, release the capture
cap.release()
cv2.destroyAllWindows()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-18 03:49:29

您正在创建轨道-栏内,而循环,这就是为什么你要得到新的轨道栏在每一个帧。

所以改变你的代码,

代码语言:javascript
复制
# Make a window for the video feed  
cv2.namedWindow('frame',cv2.CV_WINDOW_AUTOSIZE)
# Make the trackbar used for HSV masking    
cv2.createTrackbar('HSV','frame',0,255,nothing)

while(True):

    # Capture frame-by-frame
    ret, frame = cap.read()
    ........................
    ........................
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23145613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档