我想将findChessboardCorners
与calibrateCamera
一起使用,但在使用calibrateCamera
时遇到错误。输出不是很有帮助。
OpenCV错误:断言失败(i< 0)在cv :: _ OutputArray :: create
中
static const Size patterSize(8, 6);
auto image = imread("x.jpg", IMREAD_GRAYSCALE);
Mat corners;
auto found = findChessboardCorners(image, patterSize, corners);
//constructing objectPoints
vector<vector<Vec3f>> objectPoints;
objectPoints.push_back(vector<Vec3f>());
for (int row = 0; row < patterSize.height; row++) {
for (int col = 0; col < patterSize.width; col++) {
objectPoints.at(0).push_back(Vec3f(row, col, 0));
}
}
vector<vector<Vec2f>> imagePoints;
imagePoints.push_back(vector<Vec2f>());
for (int row = 0; row < patterSize.height; row++) {
for (int col = 0; col < patterSize.width; col++) {
int num = row*patterSize.width + col;
imagePoints.at(0).push_back(corners.at<Vec2f>(num, 0));
}
}
Mat cameraMatrix, distMatrix, rvecs, tvecs;
calibrateCamera(objectPoints, imagePoints, Size(image.size().width, image.size().height), cameraMatrix, distMatrix, rvecs, tvecs);