와챠의 우당탕탕 코딩 일기장
[openCV-Python] 7장 연습문제 14번(Canny) 본문
반응형
14번
다음의 그림과 같이 캐니에지 알고리즘에서 이중 임계값을 트랙바로 만들어서 두 개의 임계값을 조절하여 에지를 검출하도록 프로그램을 작성하시오.

This file contains 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
import cv2 | |
def bar(value) : | |
global title, image | |
# 낮은 임계값 th1과 높은 임계값 th2 구하기 | |
th1 = cv2.getTrackbarPos('th1', title) | |
th2 = cv2.getTrackbarPos('th2', title) | |
# 구한 임계값으로 캐네 에지 검출하기 | |
result = cv2.Canny(image, th1, th2) | |
cv2.imshow(title, result) | |
# 영상 읽기 | |
image = cv2.imread("images/cannay_test.jpg", cv2.IMREAD_GRAYSCALE) | |
if image is None: raise Exception("영상 파일 읽기 오류 발생") | |
title = 'cannay edge' | |
# 캐니 에지 검출하기 (낮은 임계값은 50, 높은 임계값은 150을 디폴트로 검출) | |
result = cv2.Canny(image, 100, 150) | |
cv2.imshow(title, result) | |
cv2.createTrackbar('th1', title, 50, 255, bar) | |
cv2.createTrackbar('th2', title, 150, 255, bar) | |
cv2.waitKey(0) |
이제 트랙바 문제는... 익숙해졌다.
반응형
'이런 저런 공부' 카테고리의 다른 글
[알고리즘] 스파르타 코딩 : 알고리즘 - 2주차 (0) | 2021.07.08 |
---|---|
[알고리즘] 스파르타 코딩 : 알고리즘 - 1주차 (0) | 2021.07.08 |
[opevCV-Python] 6장 연습문제 9번(영상 합성) (1) | 2021.04.09 |
[Open CV-Python] 5장 연습문제 7 , 8, 9번 (3) | 2021.03.29 |
[OpenCV-Python] 4장 연습문제 8 ~ 18번 (0) | 2021.03.28 |
Comments