opencv创建多个滑动块,调节多个不同区域的灰度,代码直接如下,
import cv2 as cv
import numpy as np
def nothing(x):
pass
# 创建一副黑色图像
img = np.zeros((1080, 1920), np.uint8)
# 设置滑动条组件
cv.namedWindow('image')
cv.createTrackbar('C1', 'image', 0, 255, nothing)
cv.createTrackbar('C2', 'image', 0, 255, nothing)
cv.createTrackbar('C3', 'image', 0, 255, nothing)
cv.createTrackbar('C4', 'image', 0, 255, nothing)
# 开关,控制是否启用滑动条
switch = '0:OFFn1:ON'
cv.createTrackbar(switch, 'image', 0, 1, nothing)
while True:
cv.imshow('image', img)
k = cv.waitKey(1) & 0xFF
if k == 27:
break
C1 = cv.getTrackbarPos('C1', 'image')
C2 = cv.getTrackbarPos('C2', 'image')
C3 = cv.getTrackbarPos('C3', 'image')
C4 = cv.getTrackbarPos('C4', 'image')
s = cv.getTrackbarPos(switch, 'image')
if s == 0:
img[:] = 0
else:
img[0:1080, 0:480] = [C1]
img[0:1080, 480:960] = [C2]
img[0:1080, 960:1440] = [C3]
img[0:1080, 1440:1920] = [C4]
cv.imwrite('./control_huidu.jpg', img)
# 销毁窗口
cv.destroyAllWindows()



