Ask Your Question

warpPerspective of deformed rectangle

asked 2014-09-24 08:50:26 -0500

thdrksdfthmn gravatar image

updated 2015-08-22 19:44:55 -0500

I have a rectangle that is possible rotated and curved like here (the game card) and I have some points on its contour (4 corners and 2 points on the curvature, not always the same), is it possible by using warpPerspective to warp it to normal rectangle (Size(100, 100))?

Until now I have done it using the minAreaRect, but the curvature remains; and is not very nice.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-09-24 15:19:39 -0500

rwong gravatar image

updated 2014-09-25 05:21:49 -0500

It will require a cylindrical surface model transform. See this paper for details.

Fortunately, in most cases, you can get by with an approximation by decomposing the transform into two:

  • First, perform a flat-surface perspective transform, using the four corners of the card. When rendering the surface, you must render with a generous amount of margin (up to 50% of the image size beyond the boundaries of the original quadrilateral).
  • Then, perform a 1D flattening of the dewarped image from the first step. The result from the first step should have straight left and right borders, but curved top and bottom borders. The top and bottom curves may be different. Usually, they are represented as polynomials.

This is just an approximation. If you need a mathematically correct result, you will need another paper.

Keep in mind that for perspective transform, the "center" of the quadrilateral (generally speaking) should be taken to mean the "centroid" of the quadrilateral in mathematical terms. It is the intersection point of the lines AC, BD, which are the two diagonals of the quadrilateral.

Added information:

Here is an illustration of the dewarping model:

image description

The bounded area is divided into strips. The vertical boundaries of these strips would have been parallel lines in the word coordinate system (i.e. when measured on the physical object). On the image, these vertical boundaries form a family of lines, which, together with the left and right boundaries of the object, are either coincident at a vanishing point, or are perfectly parallel with each other.

Each strip provides four coordinates (corners) for the dewarping process. In order to generate perspectively correct dewarped result, four correspondence points must be specified. If only two points were given (one from the top curve, another one from the bottom curve), the dewarped pixels will appear distorted and perspectively wrong.

edit flag offensive delete link more

answered 2014-09-24 09:55:24 -0500

No, this not possible. The transformation between your curved card and your flat goal image is much complexer than just a perspective transformation and therefore cannot be expressed as a perspective trafo.

edit flag offensive delete link more

Question Tools


Asked: 2014-09-24 08:50:26 -0500

Seen: 3,623 times

Last updated: Sep 25 '14