Home > Enterprise >  How to detect lines - OpenCV
How to detect lines - OpenCV

Time:10-05

I'm new to OpenCV and trying to do detect lines in a drawing in a format the same as contours are detected. For example, the following image needs to be processed: Original Image

So far I have been able to detect the contours as follows: Detected contours

What I'd like to do is detect the actual line and not the inner and outer contour but still have the result in the form of a list. Is this possible? If so, I'd like to apply this to pictures with more than one line such as: multiline drawing

All drawings will only consist of lines and no solid 'blocks'

Thanks very much!

CodePudding user response:

img = cv2.imread('image.png', cv2.IMREAD_COLOR) 

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 50, 200)
lines = cv2.HoughLinesP(edges, 1, np.pi/180, threshold=0)
for line in lines:
    x1, y1, x2, y2 = line[0]
    cv2.line(img, (x1, y1), (x2, y2), (51, 250, 250), 2)
cv2.imshow(img)
  • Related