我正在使用OpenCV来校准和纠正立体声系统。我有一个会聚眼的立体相机,实际上我按照这个顺序运行这些功能:
for(int j=0; j < ChessBoard.numSquares; j++)
obj.push_back(Point3f((j/ChessBoard.numCornersHor)*ChessBoard.squareDim, (j%ChessBoard.numCornersHor)*ChessBoard.squareDim, 0.0f));
[...]
然后我循环显示我想要获取的图像数量
found_L = findChessboardCorners(image_L, ChessBoard.board_sz, corners_L, CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + CV_CALIB_CB_FILTER_QUADS + CALIB_CB_FAST_CHECK);
found_R= findChessboardCorners(image_R, ChessBoard.board_sz, corners_R, CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + CV_CALIB_CB_FILTER_QUADS + CALIB_CB_FAST_CHECK);
found = found_L && found_R;
if(found)
{
cornerSubPix(image_L, corners_L, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
cornerSubPix(image_R, corners_R, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
drawChessboardCorners(image_L, ChessBoard.board_sz, corners_L, found);
drawChessboardCorners(image_R, ChessBoard.board_sz, corners_R, found);
image_points[0].push_back(corners_L);
image_points[1].push_back(corners_R);
object_points.push_back(obj);
printf("Right: coordinates stored\n");
printf("Left: coordinates stored\n");
}
在这个块之后我称之为:
cameraMatrix[0] = Mat::eye(3, 3, CV_64F);
cameraMatrix[1] = Mat::eye(3, 3, CV_64F);
calibrateCamera(object_points, image_points[0], imageSize, cameraMatrix[0], distCoeffs[0], rvecs_L, tvecs_L);
calibrateCamera(object_points, image_points[1], imageSize, cameraMatrix[1], distCoeffs[1], rvecs_R, tvecs_R);
然后:
rms = stereoCalibrate(object_points, image_points[0], image_points[1],
cameraMatrix[0], distCoeffs[0],
cameraMatrix[1], distCoeffs[1],
imageSize, R, T, E, F,
TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5),
CV_CALIB_FIX_ASPECT_RATIO+CV_CALIB_FIX_INTRINSIC);
最后:
stereoRectify(cameraMatrix[0], distCoeffs[0],
cameraMatrix[1], distCoeffs[1],
imageSize, R, T, R1, R2, P1, P2, Q,
CALIB_ZERO_DISPARITY, -1, imageSize, &roi1, &roi2 );
initUndistortRectifyMap(cameraMatrix[0], distCoeffs[0], R1, P1, imageSize, CV_16SC2, map11, map12);
initUndistortRectifyMap(cameraMatrix[1], distCoeffs[1], R2, P2, imageSize, CV_16SC2, map21, map22);
remap(imgL, imgL, map11, map12, INTER_LINEAR,BORDER_CONSTANT, Scalar());
remap(imgR, imgR, map21, map22, INTER_LINEAR,BORDER_CONSTANT, Scalar());
这基本上就是我正在做的,但结果非常糟糕,因为图像的黑色区域非常大。这是一个例子:
这是我必须获得的整流图像,直接从相机中纠正:
正如你所看到的那样,图像似乎是在右侧翻译并剪切,右边的图像是相同的,但在左侧翻译,结果几乎相同。
那么如何才能获得与上一个类似的更好的结果呢?问题出在哪儿? 作为一个额外的数据,我注意到rms不是那么好,大约0.4,重新投影误差大约是0.2,我知道它们必须我低一点,但我已经尝试了很多次不同的模式,照明和所以,在校准中,但我总是采取相同的结果,甚至最差。
答案 0 :(得分:1)
尝试像这样呼叫stereoRectify
:
stereoRectify(cameraMatrix[0], distCoeffs[0],
cameraMatrix[1], distCoeffs[1],
imageSize, R, T, R1, R2, P1, P2, Q,
0, -1, imageSize, &roi1, &roi2 );
即。使用0
代替国旗CALIB_ZERO_DISPARITY
。
另外,为了提高stereoCalibrate
获得的RMS,请尝试使用标记CV_CALIB_USE_INTRINSIC_GUESS
(请参阅this related answer):
rms = stereoCalibrate(object_points, image_points[0], image_points[1],
cameraMatrix[0], distCoeffs[0],
cameraMatrix[1], distCoeffs[1],
imageSize, R, T, E, F,
TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5),
CV_CALIB_USE_INTRINSIC_GUESS+
CV_CALIB_FIX_ASPECT_RATIO+CV_CALIB_FIX_INTRINSIC);