不失真的鱼眼图像错误

Posted

技术标签:

【中文标题】不失真的鱼眼图像错误【英文标题】:Undistorting fisheye image error 【发布时间】:2016-08-12 11:42:31 【问题描述】:

我使用一组 20 张棋盘格图像校准了鱼眼镜头。这些点都被正确标记了,我得到了内在函数和镜头畸变系数。

将 15mm 的“正方形大小”变量定义为 15 可以得到 0 失真系数和约 600 的焦距。将其设置为 0.015 可以得到失真系数和约 1200 的焦距。在这两种情况下,我的投影中心大致是图像的中点,这是合理的。

当我尝试对图像应用不失真时,我得到了一个非常奇怪的结果。

Undistorted image

我不明白为什么。失真系数为 0 时,我仍然可以得到这张图像。如果有人可以提供帮助,将不胜感激!

 void undistortFisheye()

    std::vector <cv::Mat> inputImages;
    std::vector<std::vector<cv::Point3f> > objectPoints(1);
    std::vector<std::vector<cv::Point2f>> image_points;

//Load images
for (int i = 0; i < 13; i++)

    std::cout << "Loading: " << "C:/Data/CheckerboardCalib/" << std::to_string(i + 1) << ".png" << std::endl;

    inputImages.push_back(cv::imread("C:/Data/CheckerboardCalib/" + std::to_string(i + 1) + ".png"));


int chessBoardFlags = cv::CALIB_CB_ADAPTIVE_THRESH | cv::CALIB_CB_NORMALIZE_IMAGE;

for (int i = 0; i < inputImages.size(); i++)

    std::vector<cv::Point2f> pointBuf;
    cv::Mat view;

    std::cout << i << std::endl;
    bool found = cv::findChessboardCorners(inputImages[i], cv::Size(21, 14), pointBuf, chessBoardFlags);

    if (found) // If done with success,
    
        std::cout << "Corners found!" << std::endl;

        // improve the found corners' coordinate accuracy for chessboard
        cv::Mat viewGray;
        cvtColor(inputImages[i], viewGray, cv::COLOR_BGR2GRAY);
        cornerSubPix(viewGray, pointBuf, cv::Size(11, 11), cv::Size(-1, -1), cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::COUNT, 30, 0.1));

        image_points.push_back(pointBuf);

        // Draw the corners.
    //  inputImages[i].copyTo(view);
        //cv::drawChessboardCorners(view, cv::Size(21, 14), cv::Mat(pointBuf), found);
        //cv::imshow("Window", view);
        //cv::waitKey(0);
       


float squareSize = 15.0f;
calcBoardCornerPositions(cv::Size(21,14), squareSize, objectPoints[0]);
objectPoints.resize(image_points.size(), objectPoints[0]);

cv::Matx33f K;
cv::Vec4f D;

std::vector<cv::Vec3f> rvec;
std::vector<cv::Vec3f> tvec;

//int flag = cv::fisheye::CALIB_CHECK_COND | cv::fisheye::CALIB_FIX_SKEW; 
int flag = cv::fisheye::CALIB_FIX_SKEW | cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC;
//| cv::fisheye::CALIB_FIX_K1 | cv::fisheye::CALIB_FIX_K2 | cv::fisheye::CALIB_FIX_K3;// | cv::fisheye::CALIB_FIX_K4;// | cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC;// | cv::fisheye::CALIB_FIX_K1;// | cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC;

cv::fisheye::calibrate(objectPoints, image_points, cv::Size(1920, 1080), K, D, rvec, tvec, flag, cv::TermCriteria(3, 20, 1e-6));

std::cout << "Points detected" << std::endl;
//double rms = calibrateCamera(objectPoints, image_points, cv::Size(1920, 1080), K, D, rvec, tvec, flag, cv::TermCriteria(3, 20, 1e-6));
std::cout << "Calibrated." << std::endl;

std::cout << K << std::endl;
std::cout << D << std::endl;

for (int i = 0; i < inputImages.size(); i++)

    cv::Mat src = cv::imread("C:/Data/CheckerboardCalib/" + std::to_string(i + 1) + ".png");
    cv::Mat temp;

    cv::fisheye::undistortImage(src, temp, K, D, cv::Mat::eye(3,3, CV_64F));
    cv::imwrite("C:/Data/CheckerboardCalib/undistorted/" + std::to_string(i+1) + ".png", temp);

std::string inputLine;
std::cin >> inputLine;

【问题讨论】:

【参考方案1】:

我遇到了同样的问题。我让我的代码工作了。 这里的潜在解决方案:

OpenCV fisheye undistort issues

【讨论】:

以上是关于不失真的鱼眼图像错误的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV:鱼眼相机去畸变=图像去畸变+点去畸变

鱼眼图像的经纬度展开

图像视觉 --鱼眼摄像头标定和图像畸变矫正

校正鱼眼图像的整个视野​​范围

图像提取基于matlab鱼眼图像有效区域提取含Matlab源码 2186期

如何使用opencv将鱼眼相机拍摄的图像转换为平面(矩形)图像?