使用openCV的“ calibrationCamera”方法时遇到一些问题。我正在Windows 64,Visual Studio 2013中运行OpenCV。
当我从OpenCV调用以下函数时出现问题:“ cv :: calibrateCamera”,它将引发异常“断言失败(nimages> 0)”。
下面是开发的代码示例:
vector< vector< Vec3f > > _object_points;
vector< vector< Vec2f > > _image_points;
_hor_corners = 9;
_ver_corners = 6;
_squareSize = 20; // Let's say 20 mm
_patternsize = Size(_hor_corners, _ver_corners);
Mat corners;
vector<Vec2f> imgP;
vector< Vec3f > obj;
for (int i = 0; i < _ver_corners; i++) //Create the 3d vector
for (int j = 0; j < _hor_corners; j++)
obj.push_back(Point3f((float)j * _squareSize, (float)i * _squareSize, 0));
for (int i = 0; i < numImages; i++)
{
image = calibImages[i];
// ... code for detecting corners
if (corners.rows == _hor_corners*_ver_corners)
{
_image_points.push_back(imgP); //fill arrays
_object_points.push_back(obj);
cout << imgP.size() << "___" << _image_points.size() << "___" << obj.size() << "___" << _object_points.size() << endl; //here's everything is okay
imgP.clear();
}
}
cv::calibrateCamera(_object_points, _image_points, image.size(), intrinsic, distCoeffs, rvecs, tvecs, 0); //Throw the exception here
在这里抛出断言的地方:
double cv::calibrateCamera( InputArrayOfArrays _objectPoints,
InputArrayOfArrays _imagePoints,
Size imageSize, InputOutputArray _cameraMatrix, InputOutputArray _distCoeffs,
OutputArrayOfArrays _rvecs, OutputArrayOfArrays _tvecs, int flags, TermCriteria criteria ){
int rtype = CV_64F;
Mat cameraMatrix = _cameraMatrix.getMat();
cameraMatrix = prepareCameraMatrix(cameraMatrix, rtype);
Mat distCoeffs = _distCoeffs.getMat();
distCoeffs = prepareDistCoeffs(distCoeffs, rtype);
if( !(flags & CALIB_RATIONAL_MODEL) &&
(!(flags & CALIB_THIN_PRISM_MODEL)) &&
(!(flags & CALIB_TILTED_MODEL)))
distCoeffs = distCoeffs.rows == 1 ? distCoeffs.colRange(0, 5) : distCoeffs.rowRange(0, 5);
int nimages = int(_objectPoints.total());
CV_Assert( nimages > 0 );
Mat objPt, imgPt, npoints, rvecM, tvecM;
我在互联网上进行了一些搜索,但找不到该问题的任何可能的逻辑答案。向量正确填充且具有相同的长度。对这里可能发生的事情有任何想法吗?
非常感谢您,