# createTrackbar(trackbarname, winname, value, count, onChange)创建TrackBar控件,value为trackbar的默认值,count为bar的最大值,最小值为0 # getTrackbarPos(trackbarname, winname)获取TrackBar当前值
# createTrackbar(trackbarname, winname, value, count, onChange)创建TrackBar控件,value为trackbar的默认值
# count为bar的最大值,最小值为0
# getTrackbarPos(trackbarname, winname)获取TrackBar当前值
# trackbar demo
import cv2
import numpy as np
# 创建窗口
cv2.namedWindow('trackbar', cv2.WINDOW_NORMAL)
cv2.resizeWindow('trackbar', 640, 480)
# 定义回调函数
def callback(value):
# print(value)
pass
# 创建三个trackbar
cv2.createTrackbar('R', 'trackbar', 0, 255, callback)
cv2.createTrackbar('G', 'trackbar', 0, 255, callback)
cv2.createTrackbar('B', 'trackbar', 0, 255, callback)
# 创建背景图片
img = np.zeros((480, 640, 3), np.uint8)
while True:
# 获取当前trackbar的值
r = cv2.getTrackbarPos('R', 'trackbar')
g = cv2.getTrackbarPos('G', 'trackbar')
b = cv2.getTrackbarPos('B', 'trackbar')
# 用获取到的三个值修改背景图片颜色
# 将第三个维度的值取出来
img[:] = [b, g, r]
cv2.imshow('trackbar', img)
key = cv2.waitKey(1)
if key == ord('q'):
break
cv2.destroyAllWindows()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)