gpt4 book ai didi

c++ - 图像 C++ 上有太多黑色区域的 OpenCV 校正

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:48 26 4
gpt4 key购买 nike

我正在使用 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");
}

在这个 block 之后我称之为两个:

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());

这基本上就是我正在做的,但结果真的很糟糕,因为图像有很大的黑色区域。这是一个例子:

Left From OpenCV

这是我必须获得的校正图像,它是直接从相机拍摄的:

Left From Camera

正如你所看到的,图像似乎是在右侧平移并剪切的,与右侧相同,但在左侧平移,结果几乎相同。

那么我怎样才能获得与上一个相似的更好的结果呢?哪里有问题?作为附加数据,我注意到 rms 不是很好,大约 0.4,重新投影误差大约是 0.2,我知道它们必须低一点,但我已经尝试了很多次不同的模式、照明和等等,在校准中,但我总是得到相同的结果甚至最差。

最佳答案

尝试像这样调用 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);

关于c++ - 图像 C++ 上有太多黑色区域的 OpenCV 校正,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23244380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com