줘이리의 인생적기

CV - opencv(Python) Hough Transform(설명필요) 본문

공부/Computer Vision(py)

CV - opencv(Python) Hough Transform(설명필요)

줘이리 2020. 7. 24. 08:00
728x90

Hough Transform에 대해 알아보겠습니다.

 

hough transform은 영상에서 직선을 검출하는 방법 중 하나입니다.

(설명필요)

 

 

Hough Transform

 

코드 원형 설명

def houghLinesP(image, rho=1.0, theta=np.pi/180, threshold=100, minLineLength=10, maxLineGap=100):
    return cv2.HoughLinesP(image, rho, theta, threshold, minLineLength=minLineLength, maxLineGap=maxLineGap)
def drawHoughLinesP(image, lines):
    result = imageCopy(image)
    if len(image.shape) == 2:
        result = convertColor(image, cv2.COLOR_GRAY2BGR)
    for i in range(len(lines)):
        for x1, y1, x2, y2 in lines[i]:
            cv2.line(result, (x1, y1), (x2, y2), (0, 0, 255), 3)

 

코드 설명

더보기
from OpenCV_Functions import *

#이미지 설정
imagePath = "<이미지 경로>"
image = imageRead(imagePath) 
imageShow("image", image)

#hough 변환
image_edge = cannyEdge(image, 100, 200)
lines = houghLinesP(image_edge, 1, np.pi/180, 100, 10, 50)
image_lines = drawHoughLinesP(image, lines)
imageShow("image_edge", image_edge)
imageShow("image_lines", image_lines)

cv2.destroyAllWindows()