如何使用findChessboardCorners和calibrateCamera?

时间:2016-03-25 15:40:17

标签: c++ opencv

我想将findChessboardCornerscalibrateCamera一起使用,但在使用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);

1 个答案:

答案 0 :(得分:1)

rvecs, tvecs的取消应该是vector<Mat>而不是Mat,然后一切都会好起来的。有关详细信息,请访问3calibration.cpp