0

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.

hough template

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)
  • If the lines you want to connect are horiontal, you can write your own horizontal line detector and find the start/end point accordingly. (i.e. more than 20 pixels are black in a row) – Burak Nov 12 '20 at 12:01
  • The line can be vertical or diagonal too. – sachet sourav Nov 12 '20 at 12:29
  • So you mean it can have various angle. Did you try `HoughLines` instead of `HoughLinesP`? Changing the threshold values may help. Make sure that the result of `Canny` function returns a binary mask *with* lines, otherwise HoughLines cannot find them obviously. – Burak Nov 12 '20 at 14:35

0 Answers0