opencv 2-如何仅计算两个图像之间的平移和缩放? [英] opencv 2 - How can I calculate ONLY the translation and scale between two images?

查看:753
本文介绍了opencv 2-如何仅计算两个图像之间的平移和缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用opencv仅计算两个图像之间的平移和缩放的方法.我只遇到了一个刚性变换实现,该实现将比例尺信息与旋转绑定在一起,而我对此并不感兴趣.

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.

您如何建议我这样做?

注意,在下面的代码中,两个非常相等的角度不是,实际上是angle2 = 2 * angle.我不知道为什么:

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

推荐答案

您可以使用此处(sx,sy,xc,yc),并且无需旋转.

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.

这篇关于opencv 2-如何仅计算两个图像之间的平移和缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆