我正在尝试纠正 RGB-D 数据集 7 场景中的成对图像 .由于数据集提供了地面实况姿势数据,我并没有尝试提取匹配点并计算 F。相反,我正在使用 https://math.stackexchange.com/a/709658 计算相对平移和旋转,这似乎是正确,并将两帧视为校准场景。
但是,整改结果是垃圾。我尝试使用多个 alpha 值(-1、0、1 和 [0,1] 范围内的许多值)但没有任何效果。
相对的 R 和 t 看起来很好(近帧有小的旋转和平移)。
对于相机矩阵,我使用数据集中给出的值(主点(320,240),焦距(585,585))
import cv2
import numpy as np
from matplotlib import pyplot as plt
frame1 = 100
frame2 = 160
img_1_path = './chess/seq-01/frame-000{}.color.png'.format(frame1)
img_2_path = './chess/seq-01/frame-000{}.color.png'.format(frame2)
pose_1_path = './chess/seq-01/frame-000{}.pose.txt'.format(frame1)
pose_2_path = './chess/seq-01/frame-000{}.pose.txt'.format(frame2)
img_1 = cv2.imread(img_1_path)
img_2 = cv2.imread(img_2_path)
pose1 = np.loadtxt(pose_1_path)
pose2 = np.loadtxt(pose_2_path)
R1 = pose1[0:3, 0:3]
t1 = pose1[0:3, 3]
R2 = pose2[0:3, 0:3]
t2 = pose2[0:3, 3]
# https://math.stackexchange.com/questions/709622/relative-camera-matrix-pose-from-global-camera-matrixes
R = np.matmul(np.linalg.inv(R2), R1)
T = np.matmul(np.linalg.inv(R2), (t1 - t2))
# https://www.microsoft.com/en-us/research/project/rgb-d-dataset-7-scenes/
px = 320.0
py = 240.0
fx = 585.0
fy = 585.0
cameraMatrix1 = np.array(
[
[fx, 0, px],
[0, fy, py],
[0, 0, 1.0]
]
)
cameraMatrix2 = cameraMatrix1
distCoeff = np.zeros(4)
R1, R2, P1, P2, Q, roi1, roi2 = cv2.stereoRectify(
cameraMatrix1=cameraMatrix1,
distCoeffs1=distCoeff,
cameraMatrix2=cameraMatrix2,
distCoeffs2=distCoeff,
imageSize=(640, 480),
R=R,
T=T,
flags=cv2.CALIB_ZERO_DISPARITY,
alpha=1)
map1x, map1y = cv2.initUndistortRectifyMap(
cameraMatrix=cameraMatrix1,
distCoeffs=distCoeff,
R=R1,
newCameraMatrix=P1,
size=(640, 480),
m1type=cv2.CV_32FC1)
map2x, map2y = cv2.initUndistortRectifyMap(
cameraMatrix=cameraMatrix2,
distCoeffs=distCoeff,
R=R2,
newCameraMatrix=P2,
size=(640, 480),
m1type=cv2.CV_32FC1)
img1_rect = cv2.remap(img_1, map1x, map1y, cv2.INTER_LINEAR)
img2_rect = cv2.remap(img_2, map2x, map2y, cv2.INTER_LINEAR)
fig, ax = plt.subplots(nrows=2, ncols=2)
plt.subplot(2, 2, 1)
plt.imshow(img_1)
plt.subplot(2, 2, 2)
plt.imshow(img_2)
plt.subplot(2, 2, 3)
plt.imshow(img1_rect)
plt.subplot(2, 2, 4)
plt.imshow(img2_rect)
plt.show(block=False)
plt.pause(10)
plt.close()
知道我错过了什么吗?我不应该相信真实姿势数据还是我管道中的缺陷?
谢谢。
当极点在图像中时,您可以使用 Mark Pollefeys 的极地校正方法:http://homes.esat.kuleuven.be/~konijn/publications/1999/MPOL-simple.pdf