我有一个应用程序,可以在两个不同的图像中找到相同的基准标记。我正在尝试使用cvsba(围绕SBA的opencv包装器)对结果进行包调整。 根据{{3}}中的代码 我经过两个帧,找到基准标记,然后按以下方式存储数据:
std::vector< cv::Point3f > points3D;
std::vector< std::vector< cv::Point2f > > pointsImg;
std::vector< std::vector< int > > visibility;
std::vector< cv::Mat > cameraMatrices, distCoeffsss, RotsMatrices, TransMatrices;
for (int f = 0; f < frames.size(); f++)
{
// read the input image
cv::Mat InImage = frames[f].clone();
cv::cvtColor(InImage, InImage, cv::COLOR_BGR2GRAY);
// detect markers and estimate pose
aruco::detectMarkers(InImage, dictionary, corners, ids, detectorParams, rejected);
if (estimatePose && ids.size() > 0)
aruco::estimatePoseSingleMarkers(corners, markerLength, camMatrix, distCoeffs, rvecs,
tvecs);
std::vector<cv::Point2f> cnrs2d;
std::vector<int> vis; //set visibility
for (int i = 0; i < ids.size(); i++)
{
/*Let N and M denote the number of object points and the number of cameras.
*
* @param points N x 3 object points
* @param imagePoints M x N x 2 image points for each camera and each points.The outer vector has M elements and each element has N elements of Point2d .
* @param visibility M x N x 1 visibility matrix, the element[i][j] = 1 when object point i is visible from camera j and 0 if not.
* @param cameraMatrix M x 3 x 3 camera matrix(intrinsic parameters) 3 x 3 camera matrix for each image
* @param distCoeffs M x 5 x1 distortion coefficient for each image
* @param R M x 3 x 3 rotation matrix for each image
* @param T M x 3 x 1 translation matrix for each image
*/
std::vector<cv::Point3f> cnrs3d = getCornersInCameraWorld(markerLength, rvecs[i], tvecs[i]);
std::vector<cv::Point2f> cnrs2d2 = corners[i];
for (int v = 0; v < cnrs3d.size(); v++) //add the 3d points
{
points3D.push_back(cnrs3d[v]);
cnrs2d.push_back(cnrs2d2[v]);
vis.push_back(1);
}
}
//add cam pose
cv::Mat cmat = cv::Mat(3, 1, CV_64FC1, cv::Scalar::all(0));
cv::Mat tmat = cv::Mat(3, 1, CV_64FC1, cv::Scalar::all(0));
RotsMatrices.push_back(cmat);
TransMatrices.push_back(tmat);
pointsImg.push_back(cnrs2d);
cameraMatrices.push_back(camMatrix); //add intrinsics
distCoeffsss.push_back(distCoeffs);
visibility.push_back(vis);
}
然后:
cvsba::Sba sba;
sba.run(points3D, pointsImg, visibility, cameraMatrices, distCoeffsss, RotsMatrices, TransMatrices);
运行此命令时,它似乎已根据需要添加了所有必需的变量,但是当它尝试运行实际的sba函数时,代码崩溃。我想念什么吗?该代码在哪里出错了?