[openCV] Track Bar를 생성해 사용하는 법사용하지않는공간/openCV2021. 5. 5. 18:24
Table of Contents
트랙바를 사용하기 위해선 빈 함수라도 정의가 필요하다.
import cv2
# 트랙바를 사용하려면 비어 있는 함수라도 필요함.
def nothing(x):
pass
cv2.namedWindow("Binary")
cv2.createTrackbar("threshold", "Binary", 0, 255, nothing)
cv2.setTrackbarPos("threshold", "Binary", 177)
img_color = cv2.imread('./binarization/dog3.jpg', cv2.IMREAD_COLOR)
#cv2.imshow('Color',img_color)
#cv2.waitKey(0)
img_gray = cv2.cvtColor(img_color, cv2.COLOR_BGR2GRAY)
#cv2.imshow('Gray', img_gray)
#cv2.waitKey(0)
while True:
low = cv2.getTrackbarPos("threshold","Binary")
# 사진 이진화
# threshold(그레이이미지,threshold(임계값),)
ret,img_binary = cv2.threshold(img_gray, low, 255, cv2.THRESH_BINARY_INV)
cv2.imshow("Binary", img_binary)
img_result = cv2.bitwise_and(img_color,img_color,mask=img_binary)
cv2.imshow("And", img_result)
# esc 눌럿을때 종료
if cv2.waitKey(1)&0xff == 27:
break
cv2.destroyAllWindows()
반응형
'사용하지않는공간 > openCV' 카테고리의 다른 글
[openCV] 컨투어 contours (0) | 2021.05.05 |
---|---|
[openCV] BGR2HVS : bgr을 hvs로 변환하는 프로그램 (0) | 2021.05.05 |
[openCV] 이진화 작업 (0) | 2021.05.05 |
[openCV] 동영상(캠) 다루기 (0) | 2021.05.05 |
[openCV] openCV 기본과 이미지 다루기 (0) | 2021.05.05 |
@반나무 :: 반나무_뿌리
3년차 WPF 개발자입니다.
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!