vondip
vondip

Reputation: 14039

opencv 2 - How can I calculate ONLY the translation and scale between two images?

I'm looking for a way to calculate only the translation and scale between two images using opencv. I've only encountered a rigid transform implementation which bundles the scale information with the rotation, which I'm not interested in.

How would you advise I do it?

Notice, in the following code the two surpassingly equal angles are not, actually angle2 = 2 * angle. which I'm not sure why:

    cv::Mat rigid_mat = cv::estimateRigidTransform(prevMatGray, thisMatGray, false);
    float tx = rigid_mat.at<float>(0,2);
    float ty = rigid_mat.at<float>(1,2);

    float a = rigid_mat.at<float>(0,0);
    float b = rigid_mat.at<float>(0,1);

    float c = rigid_mat.at<float>(1,0);
    float d = rigid_mat.at<float>(1,1);

    float sX = [BTImageProcessing sign:a] * sqrtf(powf(a,2) + powf(b,2));
    float sY = [BTImageProcessing sign:d] * sqrt(powf(c,2) + powf(d,2));
    float alpha = atan2f(c, d);
    float alpha2 = atan2f(-b, a);


+ (int)sign:(float)num{
    return num > 0 ? 1 : -1;
}

Upvotes: 4

Views: 7821

Answers (1)

Kornel
Kornel

Reputation: 5354

You can use estimateRigidTransform() to compute an optimal affine transformation [A|b] (a 2x3 floating-point matrix) between two 2D point sets. Next, you should decompose the transformation matrix into scaling and translation, like here (sx, sy, xc, yc) and don't care with rotation.

https://i.sstatic.net/rhsh8.png

Upvotes: 5

Related Questions