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?
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.
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°.
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.
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.
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.
You didn't mention the language you use.
OpenCV documentation has got diagramatic explanation of these functions and that is really good.
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)
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With