Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recognize rectangles in this image?

I have a image with horizontal and vertical lines. In fact, this image is the BBC website converted to horizontal and vertical lines. My problem is that I want to be able to find all the rectangles in the image. I want to write a computer program to find all the rectangles. Does anyone know how to do this or suggest ideas on how to get started? This task is easy for me as a person to find the visual rectangles, but I am not sure how to describe it as a program.

Image is the BBC website here http://www.bbc.co.uk/


Update to this, I wrote the code which converts the BBC website image to the horizontal and vertical line, the problem is these lines do not completely meet at the corners and sometimes they do not completely form a rectangle. Thanks!

like image 345
Phil Avatar asked Nov 30 '09 01:11

Phil


People also ask

How do I find a rectangle in a picture?

Use the findContours() and contourArea() Function of OpenCV to Detect Rectangles in Images in Python. We can detect a rectangle present in an image using the findContours() function of OpenCV, and we can use the contourArea() function to sort different rectangles according to their area.

How do you find the rectangle in OpenCV?

Compute the aspect ratio of the contour cnt. Set a range of aspect ratios to detect the square. We set it [0.9, 1.1]. If the ratio is between 0.9 and 1.1, the detected contour is a square else it is a rectangle.

What is shape detection?

Shape detection is an important part of Image Processing referring to modules that deal with identifying and detecting shapes of parts of image which differ in brightness,color or texture.


2 Answers

Opencv (image processing and computer vision library written in c) has implementation for hough transform (the simple hough transform find lines in an image, while the generalized one finds more complex objects) so that could be a good start. For the rectangles which do have closed corners there are also corner detectors such as cornerHarris which can help.

I ran the houghlines demo provided with opencv and here's the result on the image you gave (detected lines marked in red): alt text
(source: splintec.com)

like image 124
elijah Avatar answered Sep 20 '22 15:09

elijah


I believe you are looking for the generalized Hough transform.

like image 38
rlbond Avatar answered Sep 16 '22 15:09

rlbond