import numpy as np
import cv2
img = np.zeros((400,400,3), np.uint8)
cv2.namedWindow("image")defnothing(x):pass# create trackbars for color change
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(1)&0xffif k ==27:break# get current position of four trackbars
r = cv2.getTrackbarPos('R','image')
g = cv2.getTrackbarPos('G','image')
b = cv2.getTrackbarPos('B','image')
cv2.rectangle(img,(100,100),(200,200),(b, g, r),-1)
cv2.destroyAllWindows()