1

I have a problem running the following code:

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);
}

The problem is when the program executes to estimatePoseSingleMarkers(corners, 20, cameraMatrix, distCoeffs, rvecs, tvecs);

I got a error message likes this: 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

Is it caused by wrong variables format ? (cameraMartix & distCoeffs)

I need some help to figure out what is going wrong. Thank you.

Woody1084
  • 11
  • 1
  • 3

2 Answers2

0

Please try distCoeffs = (Mat1f(5, 1) << 0.133013, -0.322199, -0.001524, 0.004866, 0.0);

0

This was posted a long time ago so I'm hoping you found a workaround.

I believe that if you're trying to follow the tutorial then your issue is this:

vector<Mat>rvecs, tvecs;

It instead needs to be:

vector<Vec3d>rvecs, tvecs;

That's what did it for me. I hope this helps.