1

我在运行以下代码时遇到问题:

Mat cameraMatrix, distCoeffs;
cameraMatrix = (Mat1f(3, 3) << 462.71, 0, 338.630, 0, 465.97, 177.780, 0, 0, 1);
distCoeffs = (Mat1f(4, 1) << 0.133013, -0.322199, -0.001524, 0.004866);
//skip
Mat color(Size(color_information.width, color_information.height), CV_8UC3, (void*)color_data.planes[0], color_data.pitches[0] / sizeof(uchar));
Mat imageCopy;
double tick = (double)getTickCount();
vector<int>ids;
vector<vector<Point2f>>corners, rejected;
vector<Mat>rvecs, tvecs;
aruco::detectMarkers(color, dictionary, corners, ids, detectorParams, rejected);
double currentTime = ((double)getTickCount() - tick) / getTickFrequency();

// draw results
color.copyTo(imageCopy);
if (ids.size() > 0)
{
    aruco::drawDetectedMarkers(imageCopy, corners, ids);
    vector<Mat>rvecs, tvecs;
    estimatePoseSingleMarkers(corners, 20, cameraMatrix, distCoeffs, rvecs, tvecs);
    for (int i = 0; i<ids.size(); i++)
        drawAxis(imageCopy, cameraMatrix, distCoeffs, rvecs[i], tvecs[i],0.1);
}

问题是当程序执行到estimatePoseSingleMarkers(corners, 20, cameraMatrix, distCoeffs, rvecs, tvecs);

我收到这样的错误消息: OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in cv::_InputArray::getMat_, file C:\opencv-3.0\source\opencv\modules\core\src\matrix.cpp, line 1253

它是由错误的变量格式引起的吗?(cameraMartix & distCoeffs)

我需要一些帮助来弄清楚出了什么问题。谢谢你。

4

2 回答 2

0

请尝试 distCoeffs = (Mat1f(5, 1) << 0.133013, -0.322199, -0.001524, 0.004866, 0.0);

于 2017-02-28T01:48:32.483 回答
0

这是很久以前发布的,所以我希望您找到解决方法。

我相信,如果您尝试遵循本教程,那么您的问题是:

vector<Mat>rvecs, tvecs;

相反,它需要是:

vector<Vec3d>rvecs, tvecs;

这就是为我做的。我希望这有帮助。

于 2017-07-18T21:42:08.290 回答