I have a black-white image where I want to fit 2 separate lines to the edges in the image. It is easy to fit a single line with opencv, with the code below. How do I fit two best possible lines to this image. Here is the input image and 1 line result. I need something that is like the last image below.
def fit_line_to_edges(edges):
points = np.where(edges>0)
points = np.array([points[1], points[0]]).T
[vx,vy,x,y] = cv2.fitLine(points, cv2.DIST_L2,0,0.01,0.01)
lefty = int((-x*vy/vx) + y)
righty = int(((edges.shape[1]-x)*vy/vx)+y)
cv2.line(edges, (edges.shape[1]-1,righty), (0,lefty), color = (136,155,112), thickness = 3)
return edges