2
votes

After some color detection, binary thresholding, and using cvFindContours() and drawing the contours and detected blue rectangle on the image I have:

enter image description here

My problem is to some simple collision avoidance (the blue rectangle in the center cannot hit the red "walls"). It would be helpful for my purposes to have the red wall contours be approximated as with rectangles. However, using a simple cvBoundingRect and drawing red rectangles around the white contours I get:

enter image description here

The edges are a little cropped off, but you may get the idea of what we would expect using a bounding rectangle for the contours, as the entire contour is used for the approximation of the bounding rectangle and hence the large overlapping rectangles. What I would like to have is the wall contours be divided into multiple bounding rectangles, such as the the left wall be approximated as one rectangle, the right wall, the forward wall, etc...as in my illustrative rendition below:

enter image description here

Any help in doing so would be greatly appreciated.

1

1 Answers

1
votes

Detecting lines (typically Hough, RANSAC) together with some other information you have about the problem should be enough, maybe even overkill. For instance, starting with the below image at left, we get the below image at right.

enter image description hereenter image description here

But if you have the above image at left (which you should have already), the problem is already solved. Just draw both internal and external contours of the walls and you are set.