1

I've been working off a variant of the opencv squares sample to detect rectangles. It's working fine for closed rectangles, but I was wondering what approaches I could take to detect rectangles that have openings ie missing corners, lines that are too short.

I perform some dilation, which closes small gaps but not these larger ones.

I considered using a convex hull or bounding rect to generate a contour for comparison but since the edges of the rectangle are disconnected, each would read as a separate contour.

I think the first step is to detect which lines are candidates for forming a complete rectangle, and then perform some sort of line extrapolation. This seems promising, but my rectangle edges won't lie perfectly horizontally or vertically.

I'm trying to detect the three leftmost rectangles in this image:

image

Community
  • 1
  • 1
muscovy
  • 43
  • 5
  • those are 2 problems: 1. detect line segments that are no perfect lines. 2. group line segments maybe ending up with a rectangle. – Micka Nov 06 '15 at 08:26
  • Do you have suggestions for tackling detection of imperfect line segments? I've tried HoughLines/HoughLinesP which don't seem to work, I think they are targeted at more perfect lines. My current line of thinking is to analyze the contours for # of points and some sort of area to arcLength ratio to guess at which "part" of the rectangle it is – muscovy Nov 06 '15 at 18:05
  • for contours you could try PCA. but it will fail for connected rectangle corner parts... I like RANSAC methods but you would have to implement it yourself. – Micka Nov 06 '15 at 18:27
  • Thank you, I'll look into those as starting points (: – muscovy Nov 06 '15 at 18:55

1 Answers1

0

Perhaps this paper is of interest? Rectangle Detection based on a Windowed Hough Transform

Basically, take the hough line transform of the image. You will get maximums at the locations in (theta, rho) space which relate to the places where there are lines. The larger the value, the longer/straighter the line. Maybe do a threshold to only get the best lines. Then, we are trying to look for pairs of lines which are

1) parallel: the maximums occur at similar theta values

2) similar length: the values of the maximums are similar

3) orthogonal to another pair of lines: theta values are 90 degrees away from other pairs' theta values

There are some more details in the paper, such as doing the transform in a sliding window, and then using an error metric to consolidate multiple matches.

Nick Crews
  • 837
  • 10
  • 13