Processor

【OpenCV】 트랙 바(Track Bar)

작성자 임베디드코리아 작성일26-04-16 22:11 조회122회 댓글0건
< *  트랙 바(Track Bar)  * >

◆ 트랙 바란 스크롤 바의 하나로, 슬라이더 바의 형태를 갖고 있다.
◆ 트랙 바는 일정 범위 내의 값을 변경할 때 사용하며, 적절한 임곗값을 찾거나 변경하기 위해 사용한다.
◆ OpenCV의 트랙 바는 생성된 윈도우 창에 트랙바를 부착해 사용할 수 있다.


----< 예제 : Track_Bar.py  >-------------------------------------------------------------------
import cv2

def onChange(pos):
    pass

src = cv2.imread("cherryblossom.jpg", cv2.IMREAD_GRAYSCALE)

cv2.namedWindow("Trackbar Windows")

cv2.createTrackbar("threshold", "Trackbar Windows", 0, 255, onChange)
cv2.createTrackbar("maxValue", "Trackbar Windows", 0, 255, lambda x : x)

cv2.setTrackbarPos("threshold", "Trackbar Windows", 127)
cv2.setTrackbarPos("maxValue", "Trackbar Windows", 255)

while cv2.waitKey(1) != ord('q'):

    thresh = cv2.getTrackbarPos("threshold", "Trackbar Windows")
    maxval = cv2.getTrackbarPos("maxValue", "Trackbar Windows")

    _, binary = cv2.threshold(src, thresh, maxval, cv2.THRESH_BINARY)

    cv2.imshow("Trackbar Windows", binary)

cv2.destroyAllWindows()
--------------------------------------------------------------------------------------------------------