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

时间:2015-02-12 16:58:08

标签: c++ opencv fisheye opencv3.0

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

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);

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

  

断言失败((flags&amp; FIXED_TYPE)!= 0)在cv :: _ InputArray :: type,文件...... \ 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错误:断言失败(0&lt; = i&amp;&amp; i&lt;(int)v.size())在cv :: _ InputArray :: getMat,文件...... \ sources \ modules中\ core \ src \ matrix.cpp,第1170行

必须如何声明和初始化rvecstvecs

1 个答案:

答案 0 :(得分: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