滑动轨迹栏作调色板
cv.createTrackbar(‘R’, ‘image’, 0, 255, nothing)
参数:哪个滑动轨迹栏,哪个窗口,最小值,最大值,回调函数
cv.getTrackbarPos(‘R’, ‘image’)
参数:轨迹栏名,窗口名
import numpy as np
import cv2 as cvdef nothing(x):pass
img = np.zeros((600, 512, 3), np.uint8)
cv.namedWindow('image', 0)cv.createTrackbar('R', 'image', 0, 255, nothing)
cv.createTrackbar('G', 'image', 0, 255, nothing)
cv.createTrackbar('B', 'image', 0, 255, nothing)switch = 'OFF : ON'
cv.createTrackbar(switch, 'image', 0, 1, nothing)while(1):cv.imshow('image', img)k = cv.waitKey(1) & 0xFFif k == 27:breakr = cv.getTrackbarPos('R', 'image')g = cv.getTrackbarPos('G', 'image')b = cv.getTrackbarPos('B', 'image')s = cv.getTrackbarPos(switch, 'image')if s == 0:img[:] = 0else:img[:] = [b, g, r] # *****************cv.destroyAllWindows()