立体校准和三维重建问题



我正在尝试执行立体相机校准和计算视差图像的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号刚性面板上的棋盘校准图案。

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

  • 链接到示例校正立体图像

  • 链接到重投影错误图

  • 平均重投影误差<0.3

  • 校正后的图像具有平行线

  • 我使用了100多张图像进行校准

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

链接到重新投影的点云图像

我使用了以下代码片段进行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计算(看起来很棒:

视差图像链接

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

camera matrix 0:
- 2362.9276056, 0.0000006, 1034.4700766,
- 0.0000006, 2366.4078916, 728.4543626,
- 0.0000006, 0.0000006, 1.0000006,
camera matrix 1:
- 2366.2683866, 0.0000006, 1030.6057166,
- 0.0000006, 2366.4804296, 740.0748076,
- 0.0000006, 0.0000006, 1.0000006,
lens dist 0: ()
-0.201011, 0.094025, -0.000569, 0.000521, 0.252866
lens dist 1:
-0.191647, 0.046607, -0.000569, 0.000521, 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获得了一个类似的点云用于重新投影,上面的校准信息。

我也发现了这个问题,在那里他们在投影之后似乎得到了类似的输出。但在我的情况下,所有的重投影误差都很小(平均0.26像素(,视差范围默认设置为0-128,这是最大值,视差图看起来很棒。

有什么想法吗?

预测的相机参数与所用相机镜头的物理特性相匹配。这导致我限制了投影空间,基本上就像fdermishin建议的那样。删除45m距离以外的所有点可以得到合理的结果!

我使用以下代码来过滤点:

roi = [-50 50 -10 40 0 45]; % filter x, y, and z
indices = findPointsInROI(ptCloud,roi);
ptCloud_clean = select(ptCloud,indices);

最新更新