Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7963939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:44:45+00:00 2026-06-04T05:44:45+00:00

I am playing with the affine transform in OpenCV and I am having trouble

  • 0

I am playing with the affine transform in OpenCV and I am having trouble getting an intuitive understanding of it workings, and more specifically, just how do I specify the parameters of the map matrix so I can get a specific desired result.

To setup the question, the procedure I am using is 1st to define a warp matrix, then do the transform.

In OpenCV the 2 routines are (I am using an example in the excellent book OpenCV by Bradski & Kaehler):

cvGetAffineTransorm(srcTri, dstTri, warp_matrix);
cvWarpAffine(src, dst, warp_mat);

To define the warp matrix, srcTri and dstTri are defined as:

CvPoint2D32f srcTri[3], dstTri[3];

srcTri[3] is populated as follows:

srcTri[0].x = 0;
srcTri[0].y = 0;
srcTri[1].x = src->width - 1;
srcTri[1].y = 0;
srcTri[2].x = 0;
srcTri[2].y = src->height -1;

This is essentially the top left point, top right point, and bottom left point of the image for starting point of the matrix. This part makes sense to me.

But the values for dstTri[3] just are confusing, at least, when I vary a single point, I do not get the result I expect.

For example, if I then use the following for the dstTri[3]:

dstTri[0].x = 0;
dstTri[0].y = 0;
dstTri[1].x = src->width - 1;
dstTri[1].y = 0;
dstTri[2].x = 0;
dstTri[2].y = 100;

It seems that the only difference between the src and the dst point is that the bottom left point is moved to the right by 100 pixels. Intuitively, I feel that the bottom part of the image should be shifted to the right by 100 pixels, but this is not so.

Also, if I use the exact same values for dstTri[3] that I use for srcTri[3], I would think that the transform would produce the exact same image–but it does not.

Clearly, I do not understand what is going on here. So, what does the mapping from the srcTri[] to the dstTri[] represent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:44:46+00:00Added an answer on June 4, 2026 at 5:44 am

    Here is a mathematical explanation of an affine transform:
    this is a matrix of size 3×3 that applies the following transformations on a 2D vector: Scale in X axis, scale Y, rotation, skew, and translation on the X and Y axes.
    These are 6 transformations and thus you have six elements in your 3×3 matrix. The bottom row is always [0 0 1].
    Why? because the bottom row represents the perspective transformation in axis x and y, and affine transformation does not include perspective transform.
    (If you want to apply perspective warping use homography: also 3×3 matrix )

    What is the relation between 6 values you insert into affine matrix and the 6 transformations it does? Let us look at this 3×3 matrix like

    e*Zx*cos(a), -q1*sin(a)  ,  dx,
    e*q2*sin(a),     Z y*cos(a),  dy,
    0       ,            0  ,   1
    
    1. The dx and
    2. dy elements are translation in x and y axis (just move the picture left-right, up down).
    3. Zx is the relative scale(zoom) you apply to the image in X axis.
    4. Zy is the same as above for y axis
    5. a is the angle of rotation of the image. This is tricky since when you want to rotate by ‘a’ you have to insert sin(), cos() in 4 different places in the matrix.
    6. ‘q’ is the skew parameter. It is rarely used. It will cause your image to skew on the side (q1 causes y axis affects x axis and q2 causes x axis affect y axis)
    7. Bonus: ‘e’ parameter is actually not a transformation. It can have values 1,-1. If it is 1 then nothing happens, but if it is -1 than the image is flipped horizontally. You can use it also to flip the image vertically but, this type of transformation is rarely used.

    Very important Note!!!!!

    The above explanation is mathematical. It assumes you multiply the matrix by the column vector from the right. As far as I remember, Matlab uses reverse multiplication (row vector from the left) so you will need to transpose this matrix. I am pretty sure that OpenCV uses regular multiplication but you need to check it.
    Just enter only translation matrix (x shifted by 10 pixels, y by 1).

    1,0,10
    0,1,1
    0,0,1
    

    If you see a normal shift than everything is OK, but If shit appears than transpose the matrix to:

    1,0,0
    0,1,0
    10,1,1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Playing with URLs, more specifically building them incrementally from other, discovered URLs. In doing
Just playing around with different types of bindings and having a property binding a
Just playing around with Wordpress / Contact Form 7 . Is it possible to
Playing with Erlang, I've got a process-looping function like: process_loop(...A long list of parameters
Playing around with Flask and just wanted to print out some data as JSON
Currently playing about with KnockoutJS. Just trying to update an observable array from a
Playing around a bit more with jqTouch and am running into a problem with
Just playing around with the now released Silverlight 2.0. I'm trying to put a
Just playing about with some vb.net and i dont understand why when i enter
while playing this wav file in windows phone 7 its getting error. var stream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.