Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way of understanding opencv's warpperspective and warpaffine?

I'm trying to transform a static image to give the illusion of it being taken from different angles. It seems like warpPerspective and warpAffine are the functions I should understand to make this work. However, even after read the OpenCV docs, I'm having difficulty understanding them.

What tutorials/docs should I read that explain them very well?

like image 311
John Bartost Avatar asked Jun 09 '12 15:06

John Bartost


People also ask

What is warpAffine function?

warpAffine() function that applies an affine transformation to an image. The syntax of this function is given below. dst = cv.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]] ) # src: input image # M: Transformation matrix # dsize: size of the output image # flags: interpolation method to be used.

What is the difference between perspective and affine transformation?

The perspective-based model predicts that the angles within each square on the side nearest to the participant should seem smaller than those on the far side. The simple affine model under our conditions predicts that the perceived size of the angles of each square should remain 90°.

What is geometric transformation in OpenCV?

Rotation of an image for an angle \theta is achieved by the transformation matrix of the form. M = \begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{bmatrix} But OpenCV provides scaled rotation with adjustable center of rotation so that you can rotate at any location you prefer.

What is transformation matrix in OpenCV?

Translating an image is shifting it along the x and y axes. A affine transformation can be obtained by using a transformation matrix M . It is a translation matrix which shifts the image by the vector (x, y). The first row of the matrix is [1, 0, x], the second is [0, 1, y] M = np.


2 Answers

warpPerspective does a projective transformation or homography:

http://en.wikipedia.org/wiki/Homography

warpAffine does an affine transformation:

http://en.wikipedia.org/wiki/Affine_transformation

Abid Rahman, already mentioned a good book. If you want a more theoretical one, Multiple View Geometry is considered the bible of these topics.

like image 97
Rui Marques Avatar answered Oct 21 '22 05:10

Rui Marques


You didn't mention the language you use.

  1. OpenCV documentation has got diagramatic explanation of these functions and that is really good.

  2. Apart from that, OpenCV also got a tutorial on this with working C++ code. : Affine Transformations

    ( If you use Python, find it here : Affine Transform)

  3. And Gary Bradsky's book "Learning OpenCV" has got a good explanation of this, if you like, on page 163. You can read it from "Google Books"

like image 25
Abid Rahman K Avatar answered Oct 21 '22 05:10

Abid Rahman K