hough transform opencv

Solutions on MaxInterview for hough transform opencv by the best coders in the world

showing results for - "hough transform opencv"
Francesca
30 Nov 2018
1import cv2
2import numpy as np
3
4img = cv2.imread('dave.jpg')
5gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
6edges = cv2.Canny(gray,50,150,apertureSize = 3)
7
8lines = cv2.HoughLines(edges,1,np.pi/180,200)
9for rho,theta in lines[0]:
10    a = np.cos(theta)
11    b = np.sin(theta)
12    x0 = a*rho
13    y0 = b*rho
14    x1 = int(x0 + 1000*(-b))
15    y1 = int(y0 + 1000*(a))
16    x2 = int(x0 - 1000*(-b))
17    y2 = int(y0 - 1000*(a))
18
19    cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
20
21cv2.imwrite('houghlines3.jpg',img)
22