Last active
July 18, 2018 03:29
-
-
Save BlogBlocks/4fd50e32bacc3e94702ac6156e2636e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://github.com/amalzaga/python-opencv/blob/master/rgb-hsv.py | |
| # Creates a solid color image wich can be changed by using two sets | |
| # of trackbars RGB and HSV. Changing one affects the other | |
| # It is a practical way to better understanding of colorspaces. | |
| # | |
| # Written by Amador Alzaga | |
| import cv2 | |
| import numpy as np | |
| def nothing(x): | |
| pass | |
| # Create a black image, a window | |
| img = np.zeros((300,512,3), np.uint8) | |
| cv2.namedWindow('image') | |
| # 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) | |
| # create switch for ON/OFF functionality | |
| switch = '0 : OFF \n1 : ON' | |
| cv2.createTrackbar(switch, 'image',0,1,nothing) | |
| while(1): | |
| cv2.imshow('image',img) | |
| k = cv2.waitKey(1) & 0xFF | |
| if k == 27: | |
| break | |
| # get current positions of four trackbars | |
| r = cv2.getTrackbarPos('R','image') | |
| g = cv2.getTrackbarPos('G','image') | |
| b = cv2.getTrackbarPos('B','image') | |
| s = cv2.getTrackbarPos(switch,'image') | |
| if s == 0: | |
| img[:] = 0 | |
| else: | |
| img[:] = [b,g,r] | |
| cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment