Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. edges = cv2.Canny(img, 100, 100, apertureSize=3)
  2.     h_lines = cv2.HoughLines(edges, 1, np.pi / 180, 90)
  3.  
  4.     horizontal_lines = []
  5.     vertical_lines = []
  6.     if h_lines is not None:
  7.         for line in h_lines:
  8.             rho, theta = line[0]
  9.             a = np.cos(theta)
  10.             b = np.sin(theta)
  11.             x0 = a * rho
  12.             y0 = b * rho
  13.             x1 = int(x0 + 1000 * (-b))
  14.             y1 = int(y0 + 1000 * (a))
  15.             x2 = int(x0 - 1000 * (-b))
  16.             y2 = int(y0 - 1000 * (a))
  17.  
  18.             if abs(theta - np.pi) < 0.1 or abs(theta - np.pi / 2) < 0.1 or abs(theta) < 0.1:
  19.                 if abs(y2 - y1) < abs(x2 - x1):
  20.                     horizontal_lines.append([x1, x2, y1, y2, rho, theta])
  21.                 elif abs(x2 - x1) < abs(y2 - y1):
  22.                     vertical_lines.append([x1, x2, y1, y2, rho, theta])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement