Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- edges = cv2.Canny(img, 100, 100, apertureSize=3)
- h_lines = cv2.HoughLines(edges, 1, np.pi / 180, 90)
- horizontal_lines = []
- vertical_lines = []
- if h_lines is not None:
- for line in h_lines:
- rho, theta = line[0]
- a = np.cos(theta)
- b = np.sin(theta)
- x0 = a * rho
- y0 = b * rho
- x1 = int(x0 + 1000 * (-b))
- y1 = int(y0 + 1000 * (a))
- x2 = int(x0 - 1000 * (-b))
- y2 = int(y0 - 1000 * (a))
- if abs(theta - np.pi) < 0.1 or abs(theta - np.pi / 2) < 0.1 or abs(theta) < 0.1:
- if abs(y2 - y1) < abs(x2 - x1):
- horizontal_lines.append([x1, x2, y1, y2, rho, theta])
- elif abs(x2 - x1) < abs(y2 - y1):
- vertical_lines.append([x1, x2, y1, y2, rho, theta])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement