You need to enable JavaScript to run this app. 如何使用cv.recoverPose()计算相机自运动并修正旋转估计偏差
优惠活动
大模型
产品
解决方案
定价
更多

如何使用cv.recoverPose()计算相机自运动并修正旋转估计偏差

OpenCV位姿求解异常现象记录

问题背景

  • 在相邻两帧图像的相机位姿求解任务中,使用cv.findEssentialMat与cv.recoverPose接口计算相机pitch、yaw、roll旋转角时,发现接口输出结果不符合直觉
  • 对照OpenCV社区的公开说明确认:该接口求解得到的是场景点的运动方向,而非相机自身的运动方向;理论上对接口输出的旋转矩阵R求逆(即计算R⁻¹)即可得到符合预期的相机运动结果

异常复现

  • 测试场景设置:仅控制相机绕X轴向上做单自由度旋转,无其他方向的平移或旋转运动
  • 按照理论方法验证时发现:无论使用接口原始输出的R矩阵,还是经过逆变换处理的R矩阵,计算得到的欧拉角均与实际运动情况不匹配
  • 两组输出的欧拉角计算结果分别为:
    • 逆变换R矩阵计算结果:[ 1.19186314e+02 -3.94661600e-02 -1.79903575e+02]
    • 原始R矩阵计算结果:[ 1.19186327e+02 -6.49371021e-02 -1.79918523e+02]
  • 测试采用两组连续拍摄的图像作为输入

完整测试代码

import cv2 as cv
import numpy as np
from scipy.spatial.transform import Rotation as R
import matplotlib.pyplot as plt

# invert the original R from direct output of Essential matrix 
def invert_R(R_mat):
    R_mat_inv = R.from_matrix(R_mat).inv()
    return R_mat_inv.as_euler('zyx', degrees=True)


# testing code
img1 = cv.imread('img/5.jpg') #self-defined
img2 = cv.imread('img/6.jpg')

# use ORB detector to do feature matching
orb = cv.ORB_create()
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)

bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1, des2)
matches = sorted(matches, key = lambda x:x.distance)

# extract coordinates of matched keypoints
kpts1 = np.array([kp1[m.trainIdx].pt for m in matches], dtype=np.int)
kpts2 = np.array([kp2[m.queryIdx].pt for m in matches], dtype=np.int)
img3 = cv.drawMatches(img1,kp1,img2,kp2,matches[:10],None,flags=cv.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)

# calculate Essential, get Roation matrix
E, mask = cv.findEssentialMat(kpts1, kpts2, prob=0.9999, threshold=0.1)
_, R_est, t_est, mask_pose = cv.recoverPose(E, kpts1, kpts2)


# calculate inverted R and origianl R matrix, both displayed in euler angles.
R1_ang = invert_R(R_est)
R2_ang = R.from_matrix(R_est).as_euler('zyx', degrees=True)
print(R1_ang)
print(R2_ang)
plt.imshow(img3), plt.show()

内容的提问来源于stack exchange,提问作者dexter2406

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.09 11:06:08