概述
我正在尝试纠正RGB-D Dataset 7-Scenes中的成对图像。由于数据集提供了地面真实姿态数据,所以我没有试图提取匹配点和计算F,而是使用看起来正确的https://math.stackexchange.com/a/709658计算相对平移和旋转,并将这两个帧视为校准场景。在
然而,整改结果却是垃圾。我尝试了使用几个alpha值(-1,0,1,以及[0,1]范围内的许多值),但是没有得到好的结果。在
相对的R和t看起来很好(近帧具有小的旋转和平移)。在
对于相机矩阵,我使用the dataset(主点(320240),焦距(585585))中给出的值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()
你知道我错过了什么吗?我应该不相信地面真实姿态数据还是我的管道有缺陷?在
谢谢。在
最后
以上就是沉默冰棍为你收集整理的python快速实现图像矫正_图像矫正OpenCV Python的全部内容,希望文章能够帮你解决python快速实现图像矫正_图像矫正OpenCV Python所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复