gpt4 book ai didi

c++ - stereoCalibrate() 改变焦距,即使它不应该改变

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:10:15 27 4
gpt4 key购买 nike

我注意到 opencv stereoCalibrate() 改变了相机矩阵中的焦距,即使我已经设置了适当的标志(即 CV_CALIB_FIX_FOCAL_LENGTH)。我在镜头上使用两个具有相同焦距的相同相机,而且我知道传感器尺寸,因此我可以手动计算内在相机矩阵,我实际上在做什么。

这里是立体校准程序的一些输出 - stereoCalibrate() 之前和之后的相机矩阵。

    std::cout << "Before calibration: " << std::endl;
std::cout << "C1: " << _cameraMatrixA << std::endl;
std::cout << "C2: " << _cameraMatrixB << std::endl;

double error = cv::stereoCalibrate(objectPoints, imagePointsA, imagePointsB, _cameraMatrixA, _distCoeffsA, _cameraMatrixB, _distCoeffsB, _imageSize,
R, T, E, F,
cv::TermCriteria((cv::TermCriteria::COUNT + cv::TermCriteria::EPS), 30, 9.999999999999e-7), CV_CALIB_FIX_FOCAL_LENGTH | CV_CALIB_FIX_PRINCIPAL_POINT);

std::cout << "After calibration: " << std::endl;
std::cout << "C1: " << _cameraMatrixA << std::endl;
std::cout << "C2: " << _cameraMatrixB << std::endl;

Before calibration:

C1: [6203.076923076923, 0, 1280; 0, 6203.076923076923, 960; 0, 0, 1]

C2: [6203.076923076923, 0, 1280; 0, 6203.076923076923, 960; 0, 0, 1]

After calibration:

C1: [6311.77650416514, 0, 1279.5; 0, 6331.34531760757, 959.5; 0, 0, 1]

C2: [6152.655897294907, 0, 1279.5; 0, 6206.591406832492, 959.5; 0, 0, 1]

我认为这是奇怪的 opencv 行为。有人遇到过类似的问题吗?我知道这很容易解决,我可以在立体校准后为相机矩阵设置焦距。

最佳答案

为了做你想做的事,你必须调用带有标志的stereoCalibrate:

CV_CALIB_USE_INTRINSIC_GUESS | CV_CALIB_FIX_FOCAL_LENGTH | CV_CALIB_FIX_PRINCIPAL_POINT

如果不使用CV_CALIB_USE_INTRINSIC_GUESS标志,stereoCalibrate会先初始化相机矩阵和畸变系数本身,然后在后续优化中修复其中的一部分。这在 documentation 中说明,虽然相当不清楚并且没有提到那个关键标志:

Besides the stereo-related information, the function can also perform a full calibration of each of two cameras. However, due to the high dimensionality of the parameter space and noise in the input data, the function can diverge from the correct solution. If the intrinsic parameters can be estimated with high accuracy for each of the cameras individually (for example, using calibrateCamera() ), you are recommended to do so [...].

使用 CV_CALIB_USE_INTRINSIC_GUESS 和任何 CV_CALIB_FIX_* 标志告诉函数使用您传递的内容作为输入,否则,此输入将被简单地忽略和覆盖。

关于c++ - stereoCalibrate() 改变焦距,即使它不应该改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23059076/

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