Ask Your Question
0

How to detect multiple rectangles and rotate to vertical position

asked 2014-05-20 07:45:15 -0600

reebston gravatar image

Hi, Here is the picture of what I want to analyse: http://i58.tinypic.com/102qyoh.png

I'm going to try to save each of these paper piece to a file, and before I do it, rotate them to vertical position. Is it possible and what should be steps, functions to use it? As you can see in the picture, the pieces are lying on background with other color, that should make it easier to detect them right? Please let me know if my goal is possible. Thanks in advance!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-05-20 23:21:07 -0600

This is what I would roughly do:

I would first use findCountours using the parameter CV_RETR_EXTERNAL to detect only the external contours.

Then I would make sure that each contour contains 4 and only 4 corners (it is a square).

I would calculate the angle of each box respect to a vertical line(using for example the top-left and bottom-left corners of each detected contour) and use that angle to create a transformation matrix using getRotationMatrix2D

And finally use warpAffine and the transformation matrix that you just got to get each detected box aligned

Here are a couple of tutorials that might be useful to you:

finding contours in images

affine transformations

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-05-20 07:45:15 -0600

Seen: 2,929 times

Last updated: May 20 '14