Hi,
I am trying to count lines shown in this image.
After dilations I get this.
import cv2
import math
img = cv2.imread('D:/Books/lines1.jpg', cv2.IMREAD_GRAYSCALE)
edges = cv2.Canny(img,50,150,apertureSize = 3)
cv2.imwrite('D:/Books/edges.jpg',edges)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
dilated_Edges = cv2.dilate(edges, kernel, iterations=1)
cv2.imwrite("D:/Books/dilated_Edges.jpg", dilated_Edges)
lines = cv2.HoughLinesP(dilated_Edges,1,math.pi/180,15,minLineLength=100,maxLineGap=10)
for line in lines:
x1,y1,x2,y2 = line[0]
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imwrite('D:/Books/correcthoughlines.jpg',img)
print( len(lines))
The image with lines detected is this.
Even though it prints '6' I don't I understood how this works. I mean the parameters and how they have to be tweaked. So, for example, increasing maxLineGap prints 7 as the algorithm includes the last vertical line.
Can anyone guide ?
Thanks,
Mohan