Last Updated : 11 Aug, 2025
Creating a color palette helps in exploring and visualizing colors interactively. Using OpenCV in Python, we can add trackbars for Blue, Green and Red (BGR) channels. Adjusting these trackbars changes the values (0–255) in real time, making it easy to identify and use the corresponding RGB colors.
Prerequisites:
Install them using pip if not already installed:
Approachpip install opencv-python numpy
import cv2
import numpy as np
def emptyFunction():
pass
def main():
image = np.zeros((512, 512, 3), np.uint8)
windowName = "OpenCV Color Palette"
cv2.namedWindow(windowName)
cv2.createTrackbar('Blue', windowName, 0, 255, emptyFunction)
cv2.createTrackbar('Green', windowName, 0, 255, emptyFunction)
cv2.createTrackbar('Red', windowName, 0, 255, emptyFunction)
while True:
cv2.imshow(windowName, image)
if cv2.waitKey(1) == 27:
break
blue = cv2.getTrackbarPos('Blue', windowName)
green = cv2.getTrackbarPos('Green', windowName)
red = cv2.getTrackbarPos('Red', windowName)
image[:] = [blue, green, red]
print("BGR:", blue, green, red)
cv2.destroyAllWindows()
if __name__ == "__main__":
main()
Output:
Note: Above programs will not run on online IDE.
Explanation:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4