import numpy as np
import cv2 as cv


def nothing(x):
    pass


# Create a black image, a window
img = np.zeros((300, 512, 3), np.uint8)
cv.namedWindow('image')

# create trackbars for color change
cv.createTrackbar('R', 'image', 0, 255, nothing)
cv.createTrackbar('G', 'image', 0, 255, nothing)
cv.createTrackbar('B', 'image', 0, 255, nothing)

# create switch for ON/OFF functionality
switch = 'OFF/ON'
cv.createTrackbar(switch, 'image', 0, 1, nothing)

while True:
    # get current positions of four trackbars
    r = cv.getTrackbarPos('R', 'image')
    g = cv.getTrackbarPos('G', 'image')
    b = cv.getTrackbarPos('B', 'image')
    s = cv.getTrackbarPos(switch, 'image')

    # 스위치가 꺼져 있으면 흑백, 켜져 있으면 색상
    if s == 0:
        img[:] = 0
    else:
        img[:] = [b, g, r]
    
    # 이미지 표시
    cv.imshow('image', img)
    if cv.waitKey(10) > 0:
        break
cv.destroyAllWindows()

[((10, 6, 10, 39), 'numpy.zeros', 'np.zeros', ({(10, 15, 10, 28): '(300, 512, 3)', (10, 30, 10, 38): 'np.uint8'}, {}), '((300, 512, 3), np.uint8)', True, 'import numpy as np\n'), ((11, 0, 11, 23), 'cv2.namedWindow', 'cv.namedWindow', ({(11, 15, 11, 22): '"""image"""'}, {}), "('image')", True, 'import cv2 as cv\n'), ((14, 0, 14, 48), 'cv2.createTrackbar', 'cv.createTrackbar', ({(14, 18, 14, 21): '"""R"""', (14, 23, 14, 30): '"""image"""', (14, 32, 14, 33): '(0)', (14, 35, 14, 38): '(255)', (14, 40, 14, 47): 'nothing'}, {}), "('R', 'image', 0, 255, nothing)", True, 'import cv2 as cv\n'), ((15, 0, 15, 48), 'cv2.createTrackbar', 'cv.createTrackbar', ({(15, 18, 15, 21): '"""G"""', (15, 23, 15, 30): '"""image"""', (15, 32, 15, 33): '(0)', (15, 35, 15, 38): '(255)', (15, 40, 15, 47): 'nothing'}, {}), "('G', 'image', 0, 255, nothing)", True, 'import cv2 as cv\n'), ((16, 0, 16, 48), 'cv2.createTrackbar', 'cv.createTrackbar', ({(16, 18, 16, 21): '"""B"""', (16, 23, 16, 30): '"""image"""', (16, 32, 16, 33): '(0)', (16, 35, 16, 38): '(255)', (16, 40, 16, 47): 'nothing'}, {}), "('B', 'image', 0, 255, nothing)", True, 'import cv2 as cv\n'), ((20, 0, 20, 49), 'cv2.createTrackbar', 'cv.createTrackbar', ({(20, 18, 20, 24): 'switch', (20, 26, 20, 33): '"""image"""', (20, 35, 20, 36): '(0)', (20, 38, 20, 39): '(1)', (20, 41, 20, 48): 'nothing'}, {}), "(switch, 'image', 0, 1, nothing)", True, 'import cv2 as cv\n'), ((39, 0, 39, 22), 'cv2.destroyAllWindows', 'cv.destroyAllWindows', ({}, {}), '()', True, 'import cv2 as cv\n'), ((24, 8, 24, 39), 'cv2.getTrackbarPos', 'cv.getTrackbarPos', ({(24, 26, 24, 29): '"""R"""', (24, 31, 24, 38): '"""image"""'}, {}), "('R', 'image')", True, 'import cv2 as cv\n'), ((25, 8, 25, 39), 'cv2.getTrackbarPos', 'cv.getTrackbarPos', ({(25, 26, 25, 29): '"""G"""', (25, 31, 25, 38): '"""image"""'}, {}), "('G', 'image')", True, 'import cv2 as cv\n'), ((26, 8, 26, 39), 'cv2.getTrackbarPos', 'cv.getTrackbarPos', ({(26, 26, 26, 29): '"""B"""', (26, 31, 26, 38): '"""image"""'}, {}), "('B', 'image')", True, 'import cv2 as cv\n'), ((27, 8, 27, 42), 'cv2.getTrackbarPos', 'cv.getTrackbarPos', ({(27, 26, 27, 32): 'switch', (27, 34, 27, 41): '"""image"""'}, {}), "(switch, 'image')", True, 'import cv2 as cv\n'), ((36, 4, 36, 27), 'cv2.imshow', 'cv.imshow', ({(36, 14, 36, 21): '"""image"""', (36, 23, 36, 26): 'img'}, {}), "('image', img)", True, 'import cv2 as cv\n'), ((37, 7, 37, 21), 'cv2.waitKey', 'cv.waitKey', ({(37, 18, 37, 20): '(10)'}, {}), '(10)', True, 'import cv2 as cv\n')]