【发布时间】:2015-11-25 15:44:12
【问题描述】:
如何要求在轨迹栏窗口上显示栏的范围(最大值、最小值)和当前的指针值?这是使用轨迹栏的示例。
# trackbar
import cv2
import numpy as np
def nothing(x):
pass
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')
# Create trackbars
cv2.createTrackbar('R', 'image', 255, 255, nothing)
cv2.createTrackbar('G', 'image', 0, 255, nothing)
cv2.createTrackbar('B', 'image', 0, 255, nothing)
# Create switch for on/off
switch = '0: OFF \n1: ON'
cv2.createTrackbar(switch, 'image', 0, 1, nothing)
while(1):
cv2.imshow('image',img)
k = cv2.waitKey(1) & 0xFF
if k == 27: # 27 is Escape
break
r = cv2.getTrackbarPos('R','image')
g = cv2.getTrackbarPos('G','image')
b = cv2.getTrackbarPos('B','image')
s = cv2.getTrackbarPos(switch,'image')
if s == 0:
img[:] = 0
else:
img[:] = [b,g,r]
cv2.destroyAllWindows()
【问题讨论】:
-
你知道怎么做吗?我有同样的问题:(
-
你好,我怕这太老了,我不记得了。对不起。