使用 opencv 3.0 beta 校准鱼眼镜头
Fisheye lens calibration with opencv 3.0 beta
我想用这个代码校准鱼眼镜头:
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);
我没问题找到棋盘,但我在校准过程中出现断言错误:
Assertion failed ((flags & FIXED_TYPE) != 0) in cv::_InputArray::type, file ......\sources\modules\core\src\matrix.cpp, line 1792
所以我尝试像这样初始化rvecs
:
for(int i = 0 ; i < imagePoints.size() ; ++i)
{
rvecs.push_back(Mat::zeros(3, 3, CV_64FC3));
}
但是有了这个我得到了另一个断言:
OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in cv::_InputArray::getMat, file ......\sources\modules\core\src\matrix.cpp, line 1170
如何声明和初始化rvecs
和tvecs
?
您应该尝试以下操作:
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)
);
我想用这个代码校准鱼眼镜头:
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);
我没问题找到棋盘,但我在校准过程中出现断言错误:
Assertion failed ((flags & FIXED_TYPE) != 0) in cv::_InputArray::type, file ......\sources\modules\core\src\matrix.cpp, line 1792
所以我尝试像这样初始化rvecs
:
for(int i = 0 ; i < imagePoints.size() ; ++i)
{
rvecs.push_back(Mat::zeros(3, 3, CV_64FC3));
}
但是有了这个我得到了另一个断言:
OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in cv::_InputArray::getMat, file ......\sources\modules\core\src\matrix.cpp, line 1170
如何声明和初始化rvecs
和tvecs
?
您应该尝试以下操作:
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)
);