gpt4 book ai didi

c++ - 如何使用 findChessboardCorners 和 calibrateCamera?

转载 作者:太空宇宙 更新时间:2023-11-03 22:52:33 25 4
gpt4 key购买 nike

我想将 findChessboardCornerscalibrateCamera 一起使用,但在使用 calibrateCamera 时遇到错误。输出不是很有帮助。

OpenCV Error: Assertion failed (i < 0) in 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);

最佳答案

rvecs, tvecs 的减速应该是 vector<Mat>而不是 Mat ,然后一切都会好起来的。如需更多信息,请访问 3calibration.cpp .

关于c++ - 如何使用 findChessboardCorners 和 calibrateCamera?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36223057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com