Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Line endpoint detection

Hi, I would like to find enpoints of lines in my image and then connect them to fix line breaks. The blue part in the image are the line breaks I would like to fix. The green part is the houghline detected.

I have tried probabilistic hough transform but it is detecting only one line instead of all the lines. What other methods can be used for this purpose? Please guide or provide me with relevant literature. Thank you.

image description image description

import numpy as np
import cv2
import matplotlib.pyplot as plt

img = cv2.imread(r"C:\Users\Sachet\Desktop\7c563eea-8b71-4cb9-8136-ce445ce10fde.jpg")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
#cv2.imshow('lol',edges)
minLineLength = 40
maxLineGap = 5
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
    cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imwrite(r"C:\Users\Sachet\Desktop\houghlines5.jpg",img)