TrackBar控件

目录

1. 介绍

2. 代码演示


1. 介绍

 

2. 代码演示

TrackBar控件_第1张图片

 

import cv2
import numpy as np
# 创建窗口
cv2.namedWindow('trackbar',cv2.WINDOW_NORMAL)
cv2.resizeWindow('trackbar',640,480)
# 定义回调函数
def callback(value):
    print(value)
# 创建三个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:
    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()



你可能感兴趣的:(opencv,python,opencv)