1

我想用以下代码校准鱼眼镜头:

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 中的断言失败 ((flags & FIXED_TYPE) != 0),文件 ......\sources\modules\core\src\matrix.cpp,第 1792 行

所以我尝试这样初始化rvecs

for(int i = 0 ; i < imagePoints.size() ; ++i)
{
    rvecs.push_back(Mat::zeros(3, 3, CV_64FC3));
}

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

OpenCV 错误: cv::_InputArray::getMat 中的断言失败 (0 <= i && i < (int)v.size()),文件 ......\sources\modules\core\src\matrix.cpp ,第 1170 行

如何rvecs并且tvecs必须声明和初始化?

4

1 回答 1

0

您应该尝试以下方法:

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

于 2015-02-12T19:37:22.870 回答