立体校准和 3D 重建问题

问题描述

我正在尝试对计算出的视差图像执行立体相机校准和 3D 重投影。
为了简单起见,我在 Matlab 中做了这个例子,但在 Python 和 OpenCV 中得到了相同的结果。

我使用这段代码进行校准:

% Detect checkerboards in images
[imagePoints,boardSize,imagesUsed] = detectCheckerboardPoints(imageFileNames_left,imageFileNames_right);

% Generate world coordinates of the checkerboard keypoints
squareSize = 108;  % in units of 'millimeters'
worldPoints = generateCheckerboardPoints(boardSize,squareSize);

% Read one of the images from the first stereo pair
I1 = imread(imageFileNames_left{1});
[mrows,ncols,~] = size(I1);

% Calibrate the camera
[stereoParams,pairsUsed,estimationErrors] = estimateCameraParameters(imagePoints,worldPoints,...
    'EstimateSkew',false,'EstimateTangentialDistortion',true,...
    'NumRadialDistortionCoefficients',3,'WorldUnits','millimeters',...
    'InitialIntrinsicMatrix',[],'InitialRadialDistortion',...
    'ImageSize',[mrows,ncols]);

image_FileNames 包含指向相应校准图像的路径。我使用印在 A0 尺寸的刚性面板上的棋盘校准图案。

校准结果看起来很有希望:

然而,计算视差并将其重新投影到 3D 会产生奇怪的结果:

Link to reprojected point cloud image

我使用以下代码片段进行 3D 投影:

I1 = imread(strcat(dirs_left{i},'/',names_left{i}));
I2 = imread(strcat(dirs_right{i},names_right{i}));

% Rectify using calibration data
[J1,J2] = rectifyStereoImages(I1,I2,stereoParams);

% Calculate Disparity
disparityRange = [0 128];
disparityMap = disparitySGM(rgb2gray(J1),rgb2gray(J2),'DisparityRange',disparityRange);

% Project to 3D
point3D = reconstructScene(disparityMap,stereoParams);

% Convert from millimeters to meters.
point3D = point3D ./ 1000;

% Visualize the 3-D Scene
ptCloud = pointCloud(point3D,'Color',J1);
h1 = figure; pcshow(ptCloud);

相应的视差图像(使用 SGBM 计算)看起来很棒:

Link to disparity image

这是校准数据:(注意:OpenCV 表示法,我转置了所有矩阵以与 OpenCV 兼容):

camera matrix 0:
 - 2362.9276056,0.0000006,1034.4700766,- 0.0000006,2366.4078916,728.4543626,1.0000006,camera matrix 1:
 - 2366.2683866,1030.6057166,2366.4804296,740.0748076,lens dist 0: ()
-0.201011,0.094025,-0.000569,0.000521,0.252866

lens dist 1:
-0.191647,0.046607,0.205665

rotation matrix camera 1:
 - 0.9994606,-0.0068816,0.0321416,- 0.0055786,0.9991666,0.0404456,- -0.0323936,-0.0402446,0.9986656,translation vector camera 1:
 - -485.0037626,-48.0975216,48.2236646,

我使用 OpenCV 而不是 Matlab 得到了一个类似的点云进行重新投影,上面的校准信息。

我还发现了 this question, 他们似乎在投影后得到了类似的输出。 但在我的例子中,所有的重投影误差都相当小(平均为 0.26 像素),视差范围默认设置为 0-128,这是最大值,视差图看起来很棒。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)