250x250
Link
๋‚˜์˜ GitHub Contribution ๊ทธ๋ž˜ํ”„
Loading data ...
Notice
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Data Science LAB

[Python] OpenCV ๊ธฐ์ดˆ 13 - ์ด๋ฏธ์ง€ ๊ฒ€์ถœ ๋ณธ๋ฌธ

๐Ÿ–ฅ๏ธ Computer Vision/Opencv

[Python] OpenCV ๊ธฐ์ดˆ 13 - ์ด๋ฏธ์ง€ ๊ฒ€์ถœ

ใ…… ใ…œ ใ…” ใ…‡ 2022. 8. 14. 21:34
728x90

1. Canny Edge Detection

cv2.Canny([์ด๋ฏธ์ง€], ํ•˜์œ„ ์ž„๊ณ„๊ฐ’, ์ƒ์œ„์ž„๊ณ„๊ฐ’)
import cv2
img = cv2.imread('img.jpg')

canny = cv2.Canny(img, 170,200)
# 170๋ณด๋‹ค ์ž‘์œผ๋ฉด ์ž„๊ณ„๊ฐ’ x, 200๋ณด๋‹ค ํฌ๋ฉด ์ž„๊ณ„๊ฐ’(๊ฒฝ๊ณ„์„ )


cv2.imshow('img',img)
cv2.imshow('canny',canny)
cv2.waitKey(0)
cv2.destroyAllWindows()

- ์›๋ณธ ์ด๋ฏธ์ง€

- ์ด๋ฏธ์ง€ ๊ฒ€์ถœ

 

 

import cv2
img = cv2.imread('img.jpg')

def empty(pos):
    pass

name = 'Trackbar'
cv2.namedWindow(name)
cv2.createTrackbar('threshold1', name, 0, 255, empty) # minvalue
cv2.createTrackbar('threshold2', name, 0, 255, empty) #maxvalue

while True:
    threshold1 = cv2.getTrackbarPos('threshold1',name)
    threshold2 = cv2.getTrackbarPos('threshold2',name)

    canny = cv2.Canny(img, threshold1,threshold2)
# ๋Œ€์ƒ ์ด๋ฏธ์ง€, minvalue(ํ•˜์œ„ ์ž„๊ณ„๊ฐ’), maxvalue(์ƒ์œ„์ž„๊ณ„๊ฐ’)



    cv2.imshow('img',img)
    cv2.imshow(name,canny)
    
    if cv2.waitKey(0) == ord('q'):
        break
cv2.waitKey(0)
cv2.destroyAllWindows()

 

trackbar๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๊ฒฝ๊ณ„๊ฐ’์„ ์กฐ์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. 

728x90
Comments