[OpenCv-python 기초 ]:trackBar 생성하기

2018. 5. 30. 13:30Python-이론/python-opencv

trackBar생성하기



트랙바에서 RGB를 생성하여 적용시켜 보겠습니다.

import cv2
import numpy as np

def onChange(x):
    pass

img = np.zeros((1024 , 1024, 3), np.uint8)
cv2.namedWindow('trackBar',cv2.WINDOW_NORMAL)
cv2.createTrackbar('R', 'trackBar',0,255, onChange)
cv2.createTrackbar('G', 'trackBar', 0, 255, onChange)
cv2.createTrackbar('B','trackBar', 0, 255, onChange)

while True:
    cv2.imshow('trackBar', img)
    R = cv2.getTrackbarPos('R', 'trackBar')
    G = cv2.getTrackbarPos('G', 'trackBar')
    B = cv2.getTrackbarPos('B', 'trackBar')

    img[:] = [B,G,R]
    k = cv2.waitKey(1)
    if k == 27:
        break

cv2.destroyAllWindows()
적용 X

 
빨간색

 
파란색

 
초록색