1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import cv2 import numpy as np
def callback(): pass
cv2.namedWindow('trackbar', cv2.WINDOW_NORMAL) cv2.resizeWindow('trackbar', 640, 480)
cv2.createTrackbar('R', 'trackbar', 0, 255, callback) cv2.createTrackbar('G', 'trackbar', 0, 255, callback) cv2.createTrackbar('B', 'trackbar', 0, 255, callback)
img = np.zeros((640, 480, 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(10) if key & 0xFF == ord('q'): break
cv2.destroyAllWindows()
|