-
Line detection, findContours(), drawContours()AI\ML\DL/Computer Vision 2023. 8. 8. 20:31λ°μν
β£
Background
μμ ν¬μ€νΈμμ κ²μΆν μμ§ λ§΅μμ μμ§ νμλ 1, μμ§κ° μλ νμλ 0μΌλ‘ νμλμλ€. μ¬λ λμλ μμ§κ° μ°κ²°λ μ λΆμΌλ‘ 보μ΄λλ°, μμ§ λ§΅μλ μ°κ²° κ΄κ³κ° μμμ μΌλ‘ λνλ μμ λΏ λͺ μμ μΌλ‘ ννλμ΄ μμ§ μλ€.
μ΄λ€μ μ°κ²°νμ¬ κ²½κ³μ μΌλ‘ λ³ννκ³ κ²½κ³μ μ μ§μ μΌλ‘ λ³ννλ©΄ μ΄ν λ¨κ³μΈ 물체 ννμ΄λ μΈμμ λ¬΄μ² μ 리νλ€.
κ²½κ³μ μ°ΎκΈ°
OpenCVμ findContours ν¨μλ₯Ό νμ©νλ©΄ μμ§ λ§΅μμ κ²½κ³μ μ μ°Ύμ μ°μλ μ λ€μ μ§ν©μ 리μ€νΈλ‘ ννν μ μλ€.
findCountours ν¨μμ κ²½κ³μ μ μ°Ύμ μμ§ μμμ 첫λ²μ§Έ μΈμμ μ λ ₯νλ©΄, κ²½κ³μ μ μ°Ύμμ κ°μ²΄μ μ μ₯μ ν΄μ€λ€.
λ OpenCVμ drawContours ν¨μλ μμμ κ²½κ³μ μ κ·Έλ¦°λ€. 첫 λ²μ§Έ μΈμλ κ²½κ³μ μ κ·Έλ € λ£μ μμμ΄κ³ , λ λ²μ§Έ μΈμλ κ²½κ³μ μ μ μ₯ν κ°μ²΄μ΄λ€. μΈ λ²μ§Έ μΈμλ₯Ό -1λ‘ μ€μ νλ©΄ λͺ¨λ κ²½κ³μ μ κ·Έλ €μ£Όλ©° μμλ‘ μ€μ νλ©΄ ν΄λΉ λ²νΈμ ν΄λΉνλ κ²½κ³μ νλλ§ κ·Έλ €μ€λ€. λ€ λ²μ§Έ μΈμλ μκ³Ό λκ»λ₯Ό μ§μ νλ€.
import cv2 as cv import numpy as np img = cv.imread('light.jpg') gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) canny = cv.Canny(gray, 30,100) contour, hierarchy = cv.findContours(canny, cv.RETR_LIST, cv.CHAIN_APPROX_NONE) lcontour = [] for i in range(len(contour)): if contour[i].shape[0] > 100: lcontour.append(contour[i]) cv.drawContours(img, lcontour, -1, (0, 255, 0), 3) cv.imshow('Original with contours', img) cv.imshow('Canny', canny) cv.waitKey() cv.destroyAllWindows()
'AI\ML\DL > Computer Vision' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
SLIC μκ³ λ¦¬μ¦, Superpixel segmentation (0) 2023.08.11 νν λ³ν (Hough Transformation) (1) 2023.08.09 μμ§ κ²μΆ(2) - Canny edge detection (0) 2023.08.08 μμ§ κ²μΆ(1) - 1μ°¨Β·2μ°¨ λ―ΈλΆ, Prewitt, Sobel (0) 2023.08.06