使用 opencv 3.0 beta 进行鱼眼镜头校准

Posted

技术标签:

【中文标题】使用 opencv 3.0 beta 进行鱼眼镜头校准【英文标题】:Fisheye lens calibration with opencv 3.0 beta 【发布时间】:2015-04-13 12:49:20 【问题描述】:

我想用这个代码校准鱼眼镜头:

bool found = findChessboardCorners( view, s.boardSize, pointBuf, CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE);
vector<vector<Point2f> > imagePoints;
imagePoints.push_back(pointBuf);
Mat cameraMatrix, distCoeffs;
vector<Mat> rvecs, tvecs;
vector<float> reprojErrs;
vector<vector<Point3f> > objectPoints(1);
s.flag = fisheye::CALIB_RECOMPUTE_EXTRINSIC|fisheye::CALIB_FIX_SKEW|fisheye::CALIB_FIX_K1;
calcBoardCornerPositions(s.boardSize, s.squareSize, objectPoints[0], s.calibrationPattern);
double rms = fisheye::calibrate(objectPoints, imagePoints, view.size(), cameraMatrix, distCoeffs, rvecs, tvecs, s.flag);

我没有问题找到棋盘,但在校准过程中出现断言错误:

在 cv::_InputArray::type,文件 ......\sources\modules\core\src\matrix.cpp,第 1792 行中断言失败 ((flags & FIXED_TYPE) != 0)

所以我尝试像这样初始化rvecs

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

    rvecs.push_back(Mat::zeros(3, 3, CV_64FC3));

但是有了这个我得到另一个断言:

OpenCV 错误:断言失败 (0

rvecstvecs 必须如何声明和初始化?

【问题讨论】:

【参考方案1】:

您应该尝试以下方法:

std::vector<std::vector<cv::Point2d> > imagePoints(n_images);
std::vector<std::vector<cv::Point3d> > objectPoints(n_images);

//...

cv::Matx33d K;
cv::Vec4d D;
std::vector<cv::Vec3d> rvec;
std::vector<cv::Vec3d> tvec;

cv::fisheye::calibrate(
     objectPoints, imagePoints, imageSize, 
     K, D, rvec, tvec, flag, 
     cv::TermCriteria(3, 20, 1e-6)
);

在此处查看示例:https://github.com/Itseez/opencv/blob/6df1198e8b1ea4925cbce943a1dc6549f27d8be2/modules/calib3d/test/test_fisheye.cpp

【讨论】:

以上是关于使用 opencv 3.0 beta 进行鱼眼镜头校准的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV - 校准鱼眼镜头误差(病态矩阵)

VS2019+OpenCV4.5 鱼眼相机图像畸变矫正

如何通过openGL创建鱼眼镜头效果? [复制]

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

DxO Analyzer 光学模块鱼眼镜头MTF测试

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