Hi
I’m working on this project where I’ve to separate some lines segments from others. I used Hough transform to detect these lines, however, I’m stuck on how I can extract only the lines I want. As you can see, in the image, I would like to extract the lines marked in red.
If someone has a idea of where I can find a documentation which can help or provide some code help, I’ll be gratefull.
I’ve provided my Hough transform code in case it can help for something.
img = cv2.imread('input.png')
lines_list = list()
if len(img.shape) == 3:
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
image_all = img.copy()
else:
gray = img.copy()
image_all = cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
edges = cv2.Canny(gray,50,150,apertureSize=3)
lines = cv2.HoughLinesP(
edges, # Input edge image
5, # Distance resolution in pixels
np.pi / 180, # Angle resolution in radians
150, # Min number of votes for valid line
np.array([]),
minLineLength = 90, # Min allowed length of line
maxLineGap = 40 # Max allowed gap between line for joining them
)
for points in lines:
# Extracted points nested in the list
x1,y1,x2,y2=points[0]
# Draw the lines joing the points On the original image
cv2.line(image_all,(x1,y1),(x2,y2),(0,100,255),4)