calibrateCamera fails even using vector<Mat> for rvecs, tvecs
I am getting an error when I try to run calibrateCamera.
The error is this:
C:\builds\2_4_PackSlave-win32-vc11-shared\opencv\modules\core\src\matrix.cpp:963: error: (-215) i < 0 in function cv::_InputArray::getMat
I have read elsewhere that this can happen when passing Mat's instead of std::vectors of Mat's as the rvecs and tvecs, but that is what I am doing! So why do I still get this error? The error only occurs when I try to run calibrateCamera, all the other code executes without errors.
Here is my code:
cv::Size patternSize(9,6);
vector<cv::Point2f> imagePoints;
bool found = cv::findChessboardCorners(mat, patternSize, imagePoints, CV_CALIB_CB_ADAPTIVE_THRESH + CV_CALIB_CB_FAST_CHECK);
if ( found )
{
if ( pMainWinDlg->getCamImage() )
{
drawChessboardCorners(cv::Mat(pMainWinDlg->getCamImage()), patternSize, cv::Mat(imagePoints), found);
}
float squareSize = 1.f;
vector<cv::Point3f> objectPoints;
objectPoints = Create3DChessboardCorners(patternSize, squareSize);
vector<cv::Mat> rotationVectors;
vector<cv::Mat> translationVectors;
cv::Mat distortionCoefficients = cv::Mat::zeros(8, 1, CV_64F); // There are 8 distortion coefficients
cv::Mat cameraMatrix = cv::Mat::eye(3, 3, CV_64F);
cv::Size imageSize = mat.size();
int flags = 0;
try
{
double rms = cv::calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distortionCoefficients, rotationVectors, translationVectors, flags|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5 );
}