将四元数转换为相机旋转矩阵 - OpenCV
Transforming Quaternion to Camera rotation matrix - OpenCV
几周来,我一直在尝试使用精确的四元数来扭曲几张照片,但没有成功。下面的方程式似乎没有像我期望的那样旋转相机位置。我做对了吗?有什么我想念的吗?
我明白仅仅传递四元数不足以拼接照片,但应该足以对齐照片?
公式如下:
double divmult = 2.0 / lsq;
double xx = divmult * x * x;
double yy = divmult * y * y;
double zz = divmult * z * z;
double wx = divmult * w * x;
double wy = divmult * w * y;
double wz = divmult * w * z;
double xy = divmult * x * y;
double xz = divmult * x * z;
double yz = divmult * y * z;
cameras_global[imageCounter].R = (Mat_<float>(3, 3) << ( 1 - yy - zz ), -( xy - wz ), -( xz + wy ),
( xy + wz ), -( 1 -xx -zz ), -( yz - wx ),
( xz - wy ), -( yz + wx ), -( 1 -xx -yy ) );
OpenCV 不直接支持四元数。我不会修复您的计算,而是进行更简单的转换。最接近它的是表示 3D 旋转的轴角向量(也称为罗德里格斯角)。我会 convert to axis-angle, then multiply the axis by the angle to obtain Rodrigues angles. After that, you can use OpenCV's built-in functions, for instance cv::Rodrigues 转换为 3x3 旋转矩阵。
几周来,我一直在尝试使用精确的四元数来扭曲几张照片,但没有成功。下面的方程式似乎没有像我期望的那样旋转相机位置。我做对了吗?有什么我想念的吗?
我明白仅仅传递四元数不足以拼接照片,但应该足以对齐照片?
公式如下:
double divmult = 2.0 / lsq;
double xx = divmult * x * x;
double yy = divmult * y * y;
double zz = divmult * z * z;
double wx = divmult * w * x;
double wy = divmult * w * y;
double wz = divmult * w * z;
double xy = divmult * x * y;
double xz = divmult * x * z;
double yz = divmult * y * z;
cameras_global[imageCounter].R = (Mat_<float>(3, 3) << ( 1 - yy - zz ), -( xy - wz ), -( xz + wy ),
( xy + wz ), -( 1 -xx -zz ), -( yz - wx ),
( xz - wy ), -( yz + wx ), -( 1 -xx -yy ) );
OpenCV 不直接支持四元数。我不会修复您的计算,而是进行更简单的转换。最接近它的是表示 3D 旋转的轴角向量(也称为罗德里格斯角)。我会 convert to axis-angle, then multiply the axis by the angle to obtain Rodrigues angles. After that, you can use OpenCV's built-in functions, for instance cv::Rodrigues 转换为 3x3 旋转矩阵。