Python和OpenCV-有关findFundamentalMat';行为
抱歉,如果标题有点含糊不清。很难用简单易懂的方式表达我的问题 所以,我正处于一个3D重建项目的中间。管道与标准管道大致相同,其中Python和OpenCV-有关findFundamentalMat';行为,python,opencv,3d-reconstruction,Python,Opencv,3d Reconstruction,抱歉,如果标题有点含糊不清。很难用简单易懂的方式表达我的问题 所以,我正处于一个3D重建项目的中间。管道与标准管道大致相同,其中 不失真图像 使用关键点检测器检测点 跨帧跟踪点(光流) 计算基本矩阵 等等。唯一不同的部分是在第2步,我使用一个线段检测器,并跨帧跟踪它 因此,如果我使用关键点检测器,给出两帧图像,我将得到两组关键点(每组对应于每帧)。但对于我的情况,我有四组关键点(每两组对应于每一帧,因为一条线有一个起点和一个终点) 为了计算基本矩阵,我需要连接每帧的两组点 一种方法是垂直连接它:
np.vstack([start\u point,end\u point])
另一种方法是:np.hstack([start\u point,end\u point])。重塑(-1,2)
。也就是说,它是“交替”连接的,即
[[start_point[0],
end_point[0],
start_point[1],
end_point[1],
...]]
两者最终将以相同的形状结束。但公平地说,它们产生了完全不同的结果。根据我的观察,vstack
产生的重建结果更像“3D”,而hstack
产生的重建结果更像“平面”
问题是为什么会这样?哪一个应该更好
下面是关于此问题的示例代码:
import numpy as np
import cv2
np.random.seed(0)
def prepare_points(pts_frame1, pts_frame2):
# Prepare the four sets of points
(p1_f1, p2_f1) = pts_frame1
(p1_f2, p2_f2) = pts_frame2
v_stacked_f1f2 = (np.vstack([p1_f1, p2_f1]), np.vstack([p1_f2, p2_f2]))
h_stacked_f1f2 = (np.hstack([p1_f1, p2_f1]).reshape(-1, 2),
np.hstack([p1_f2, p2_f2]).reshape(-1, 2))
return (v_stacked_f1f2, h_stacked_f1f2)
pts_frame1 = np.random.random_sample((60, 2)).astype("float32")
pts_frame2 = np.random.random_sample((60, 2)).astype("float32")
# Emulate the two sets of points for each frame where
# the first set is the start point, while
# the second set is the end point of a line
pts_frame1 = (pts_frame1[::2], pts_frame1[1::2])
pts_frame2 = (pts_frame2[::2], pts_frame2[1::2])
(v_stacked_f1f2, h_stacked_f1f2) = prepare_points(pts_frame1, pts_frame2)
F_vstacked = cv2.findFundamentalMat(v_stacked_f1f2[0], v_stacked_f1f2[1],
cv2.FM_RANSAC, 3, 0.99)[0]
F_hstacked = cv2.findFundamentalMat(h_stacked_f1f2[0], h_stacked_f1f2[1],
cv2.FM_RANSAC, 3, 0.99)[0]
print("F_vstacked:\n", F_vstacked, "\n")
print("F_hstacked:\n", F_hstacked, "\n")
# F_vstacked:
# [[ 3.31788127 -2.24336615 -0.77866782]
# [ 0.83418839 -1.4066019 -0.92088302]
# [-2.75413748 2.27311637 1. ]]
# F_hstacked:
# [[ 7.70558741 25.29966782 -16.20835082]
# [-12.95357284 -0.54474384 14.95490469]
# [ 1.79050172 -10.40077071 1. ]]
findFundamentalMat函数处理如下点格式:2*N,其中N是点的数量。所以我认为“Fhstacked”是正确的。
还有一件事我不清楚,为什么你只想用直线的端点来估计运动?那么特征点是否准确?因为您无法准确地计算出(像素)是每行的终点。findFundamentalMat函数处理点的格式如下:2*N,其中N是点的数量。所以我认为“Fhstacked”是正确的。 还有一件事我不清楚,为什么你只想用直线的端点来估计运动?那么特征点是否准确?因为你不能准确地找出每一行的终点(像素)