Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detection of hand-drawn hough lines

Hi,

I am trying to count lines shown in this image.

image description

After dilations I get this.

image description

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.

image description

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

Detection of hand-drawn hough lines

Hi,

I am trying to count lines shown in this image.

image description

After dilations I get this.

image description

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.

image description

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

Detection of hand-drawn hough lines

Hi,

I am trying to count lines shown in this image.

image description

After dilations I get this.

image description

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.

image description

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 seems to include the last vertical line.

image description

Can anyone guide ?

Thanks,

Mohan

Detection of hand-drawn lines

Hi,

I am trying to count lines shown in this image.

image description

After dilations I get this.

image description

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.

image description

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 seems to include the last vertical line.

image description

The code I have fails for similar images like these.

image description image description

Can anyone guide ?

Thanks,

Mohan