import cv2 as cv
import numpy as np
import math
cap = cv.imread("image.png")
dst = cv.Canny(cap, 50, 200, None, 3)
lines = cv.HoughLines(dst, 1, np.pi / 180, 150, None, 0, 0)
# Draw the lines
if lines is not None:
for i in range(0, len(lines)):
rho, theta = lines[i][0][0], lines[i][0][1]
a, b = math.cos(theta), math.sin(theta)
x0, y0 = a * rho, b * rho
pt1 = (int(x0 + 1000*(-b)), int(y0 + 1000*(a)))
pt2 = (int(x0 - 1000*(-b)), int(y0 - 1000*(a)))
if math.isclose(pt1[1], pt2[1], rel_tol = .1): # if they have "same" y
cv.line(cap, pt1, pt2, (0,0,255), 3, cv.LINE_AA)