use*_*515 5 matlab opencv triangulation stereo-3d matlab-cvst
我目前有一个立体相机设置.我已经校准了两个摄像头并且具有用于摄像头K1和摄像头的内在矩阵K2.
K1 = [2297.311, 0, 319.498;
0, 2297.313, 239.499;
0, 0, 1];
K2 = [2297.304, 0, 319.508;
0, 2297.301, 239.514;
0, 0, 1];
Run Code Online (Sandbox Code Playgroud)
我还确定了F使用findFundamentalMat()OpenCV 的两台摄像机之间的基本矩阵.我已经使用一对相应的点x1和x2(在像素坐标中)测试了Epipolar约束,并且它非常接近0.
F = [5.672563368940768e-10, 6.265600996978877e-06, -0.00150188302445251;
6.766518121363063e-06, 4.758206104804563e-08, 0.05516598334827842;
-0.001627120880791009, -0.05934224611334332, 1];
x1 = 133,75
x2 = 124.661,67.6607
transpose(x2)*F*x1 = -0.0020
Run Code Online (Sandbox Code Playgroud)
从F我能够得到本质矩阵E为E = K2'*F*K1.我E使用MATLAB SVD函数进行分解,以获得K2相对于旋转和平移的4种可能性K1.
E = transpose(K2)*F*K1;
svd(E);
[U,S,V] = svd(E);
diag_110 = [1 0 0; 0 1 0; 0 0 0];
newE = U*diag_110*transpose(V);
[U,S,V] = svd(newE); //Perform second decompose to get S=diag(1,1,0)
W = [0 -1 0; 1 0 0; 0 0 1];
R1 = U*W*transpose(V);
R2 = U*transpose(W)*transpose(V);
t1 = U(:,3); //norm = 1
t2 = -U(:,3); //norm = 1
Run Code Online (Sandbox Code Playgroud)
假设它K1被用作我们进行所有测量的坐标系.因此,中心K1是在C1 = (0,0,0).有了它,应该可以应用正确的旋转R和平移t,使得C2 = R*(0,0,0)+t(即K2相对于中心测量的中心K1)
现在让我们说使用我相应的对x1和x2.如果我知道两个相机中每个像素的长度,并且因为我知道内部矩阵的焦距,我应该能够确定两个矢量,v1并且v2两个相机在相同的点处相交,如下所示.
pixel_length = 7.4e-6; //in meters
focal_length = 17e-3; //in meters
dx1 = (133-319.5)*pixel_length; //x-distance from principal point of 640*480 image
dy1 = (75-239.5) *pixel_length; //y-distance from principal point of 640*480 image
v1 = [dx1 dy1 focal_length] - (0,0,0); //vector found using camera center and corresponding image point on the image plane
dx2 = (124.661-319.5)*pixel_length; //same idea
dy2 = (67.6607-239.5)*pixel_length; //same idea
v2 = R * ( [dx2 dy2 focal_length] - (0,0,0) ) + t; //apply R and t to measure v2 with respect to K1 frame
Run Code Online (Sandbox Code Playgroud)
利用这个向量并以参数形式知道线方程,我们可以将这两条线等同为三角形并求解两个标量s并t通过MATLAB中的左手除法函数来求解方程组.
C1 + s*v1 = C2 + t*v2
C1-C2 = tranpose([v2 v1])*transpose([s t]) //solve Ax = B form system to find s and t
Run Code Online (Sandbox Code Playgroud)
随着s和t决心,我们可以通过插入回线方程找到三角点.然而,我的过程中一直没有成功,因为我无法找到一个单一R和t解决方案,其中重点是在两个相机的前面,其中两个相机指向前方.
我的管道或思维过程有问题吗?是否可以获得每个像素光线?
当你将基本矩阵分解为4 种不同的解决方案R时t。其中三个将点投影在一台或两台摄像机后面,其中之一是正确的。您必须通过对一些样本点进行三角测量来测试哪一个是正确的。
MATLAB 的计算机视觉系统工具箱中有一个名为 的函数cameraPose,它可以为您完成此操作。