I have an image that is a simple picture and I want to extract the end points of the lines. However, there are other lines that do overlap, so, my lines have 'gaps' in them.
I am trying to use HoughLinesP to extract the parameterization of these ten lines and though the visual result is reasonable, it still gives me 43 individual lines.
I have tried smoothing the lines, skeleton representation of the lines, redrawing the lines after each of those, I'm working with countours right now. I have adjusted my parameters (line length, max gap, threshold, etc...) and I can not get this to reduce to ten lines. In my current code, I subtract the first image from itself to make a new black space to draw my HoughLines on, maybe not the most efficient, but its effective. Here is my code:
import numpy as np
import cv2
img = cv2.imread('masked.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 100
img2 = cv2.subtract(img, img)
lines = cv2.HoughLinesP(gray,1,np.pi/180,10,minLineLength,maxLineGap=100)
print(len(lines))
for n in range(len(lines)):
for x1,y1,x2,y2 in lines[n]:
cv2.line(img2,(x1,y1),(x2,y2),(0,255,0),1,4)
cv2.imshow('result.png', img2)
cv2.waitKey(0)
cv2.destroyAllWindows()
Is there another approach that would allow me to fill in these gaps and pull out ten equations of lines? I'm using Python, OpenCV and Numpy right now.