我用一组20张棋盘图像校准了一个鱼眼镜头。这些点都被正确地标记了,我得到了本质和镜头畸变系数。
将"正方形尺寸"变量定义为15,为15mm,我得到0失真系数和~600焦距。将其设置为0.015会给我失真系数和焦距~1200。在这两种情况下,我的投影中心大致是图像的中点,这是合理的。
当我尝试将我的不失真应用到我的图像中时,我得到了一个非常奇怪的结果。
无畸变的图像我不明白为什么。当失真系数为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;
}
我也有同样的问题。我的代码正常工作了。这里可能的解决方案:
OpenCV鱼眼不扭曲问题