Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rectangle detection in image

I'd like to program a detection of a rectangular sheet of paper which doesn't absolutely need to be perfectly straight on each side as I may take a picture of it "in the air" which means the single sides of the paper might get distorted a bit.

The app (iOs and android) CamScanner does this very very good and Im wondering how this might be implemented. First of all I thought of doing:

  • smoothing / noise reduction
  • Edge detection (canny etc) OR thresholding (global / adaptive)
  • Hough Transformation
  • Detecting lines (only vertically / horizontally allowed)
  • Calculate the intercept point of 4 found lines

But this gives me much problems with different types of images. And I'm wondering if there's maybe a better approach in directly detecting a rectangular-like shape in an image and if so, if maybe camscanner does implement it like this as well!?

Here are some images taken in CamScanner. These ones are detected quite nicely even though in a) the side is distorted (but the corner still gets shown in the overlay but doesnt really fit the corner of the white paper) and in b) the background is pretty close to the actual paper but it still gets recognized correctly:

a)b)

It even gets the rotated pictures correctly:

enter image description here

And when Im inserting some testing errors, it fails but at least detects some of the contour, but always try to detect it as a rectangle:

enter image description hereenter image description here

And here it fails completely:

enter image description here

I suppose in the last three examples, if it would do hough transformation, it could have detected at least two of the four sides of the rectangle.

Any ideas and tips? Thanks a lot in advance

like image 814
tim Avatar asked Mar 22 '14 20:03

tim


People also ask

What is contour detection in image processing?

Contours detection is a process can be explained simply as a curve joining all the continuous points (along with the boundary), having same colour or intensity. The contours are a useful tool for shape analysis and object detection and recognition.

How do we find faces on an image?

You can detect the faces in the image using method detectMultiScale() of the class named CascadeClassifier. This method accepts an object of the class Mat holding the input image and an object of the class MatOfRect to store the detected faces.

How do we detect edges of items in a drawing?

How are Edges Detected? Edges are characterized by sudden changes in pixel intensity. To detect edges, we need to go looking for such changes in the neighboring pixels. Come, let's explore the use of two important edge-detection algorithms available in OpenCV: Sobel Edge Detection and Canny Edge Detection.


1 Answers

OpenCV framework may help your problem. Also, you can look to this document for the Android platform.

Detecting simple shapes in an image

The full source code is available on Github.

like image 187
Abdullah Elen Avatar answered Oct 02 '22 00:10

Abdullah Elen