Working with a GUI
By now we are aware of how to create a named window using the call of the OpenCV cv2.namedWindow() function. We will now demonstrate how to create trackbars using the cv2.CreateTrackbar() function, how to associate it with a named window, and how to use those trackbars to choose the value of the color channels in the RGB colorspace. Let's get started with the following code:
import numpy as np
import cv2
def empty(z):
pass
image = np.zeros((300, 512, 3), np.uint8)
cv2.namedWindow('Palette')
cv2.createTrackbar('B', 'Palette', 0, 255, empty)
cv2.createTrackbar('G', 'Palette', 0, 255, empty)
cv2.createTrackbar('R', 'Palette', 0, 255, empty)
while(True):
cv2.imshow('Palette', image)
if cv2.waitKey(1) == 27 :
break
blue = cv2.getTrackbarPos('B', 'Palette')
green = cv2.getTrackbarPos('G', 'Palette')
red = cv2.getTrackbarPos...