1

I have to detect appropriate rectangles (which satisfy the area and aspect ratio condition of doors) from an image to find Doors in it. So I used canny edge detection to find the edges and then I used hough Transform to extract lines for the edges. And I got the result something like in the image below: enter image description here

Now I somehow extracted lines that forms the rectangle which satisfy the 'Door Conditions'. but as you can see in the image the lines are so close that it forms many rectangles which satisfies my door condition. So I thought I would reduce the lines by replacing the close lines with their average line but I am unable to do it as it is becoming much more complex. I tried something like this.

def segregateLines(tobesegLines):
    while True:
        noLinesLeft = True
        for i in range(0 , len(tobesegLines)):
            closeLineFound = False
            for j in range(0, len(tobesegLines)):
                if abs(tobesegLines[i][0][0] - tobesegLines[j][0][0]) < 50:
                    closeLineFound = True
                    noLinesLeft = False
                    newLines.append([[(abs(tobesegLines[i][0][0] +tobesegLines[j][0][0])) /2, tobesegLines[i][0][1]]])

            if not closeLineFound:
                newLines.append(tobesegLines[i])

        if noLinesLeft:
            break
        segregateLines(newLines)
    return newLines

But i am getting 'memory error'.Does anyone have an idea about averaging the close lines in python. Or any other ideas about extracting correct rectangle from the lines to find my door?

P.S : I have Distance of every line from th origin i.e rho. and I have lines segregated as almost horizontal and almost vertical lines.

  • You need to change how you detect local maxima in the Hough transform. Lines that are close together and nearly parallel are local maxima that are close together. Typically one detects a local maximum, then suppresses the other ones nearby, before detecting the next local maximum. – Cris Luengo Jun 04 '21 at 12:24
  • Can you suggest how can I do it in python? I have an array of lines where each element have [rho, theta]. Is there any direct function to achieve it? – SameeranZingre Jun 04 '21 at 14:16
  • You need to do this before you get that array of lines. This happens in the algorithm that generates that list. Can’t tell you how to adjust it without knowing what Hough implementation you are using. – Cris Luengo Jun 04 '21 at 14:23
  • `edges = cv2.Canny(gray,100,200,True) lines = cv2.HoughLines(edges,1,np.pi/180,150)` I am using this simple HoughLines function to get [rho,theta] – SameeranZingre Jun 04 '21 at 14:31
  • Sorry, I don’t know how to get that function to do better. The OpenCV implementation doesn’t give access to the intermediate parameter space. You could try to reduce the angular resolution. Otherwise, pick a different implementation. There are so many... – Cris Luengo Jun 04 '21 at 16:23
  • Okay. Thanks, Chris! – SameeranZingre Jun 04 '21 at 16:51

0 Answers0