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;
}
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.

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