图像处理练习
制作一个滑动条调色板,使用函数cv2.getTrackbarPos();cv2.creatTrackbar()
import cv2
import numpy as np
def nothing(x):
pass
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow(‘image‘)
”创建一个开关“
switch = ‘0:OFF\n1:ON‘
cv2.createTrackbar(switch,‘image‘,0,1,nothing)
”创建3个调色条“
cv2.createTrackbar(‘R‘,‘image‘,0,255,nothing)
cv2.createTrackbar(‘G‘,‘image‘,0,255,nothing)
cv2.createTrackbar(‘B‘,‘image‘,0,255,nothing)
while(1):
cv2.imshow(‘image‘, img)
k=cv2.waitKey(0)
if k == ord(‘q‘):#按q键退出
break
”从调色条 获取值“
r = cv2.getTrackbarPos(‘R‘,‘image‘)
g = cv2.getTrackbarPos(‘G‘,‘image‘)
b = cv2.getTrackbarPos(‘B‘,‘image‘)
”开关“
change = cv2.getTrackbarPos(switch, ‘image‘)
if k == ord(‘s‘) and change == 1:
img[:]=[r,g,b]
cv2.destroyAllWindows()
原文地址:http://blog.51cto.com/devops2016/2086831
时间: 2024-09-29 10:18:57