我试图在aruco标记上画一个正方形,但我得到的只是一些随机线。但是,当我尝试使用aruco :: drawAxis仅在标记上绘制轴时,这些投影就很好了。
这是我投影正方形的代码:
void drawCube(InputOutputArray image, InputArray cameraMatrix, InputArray distortionCoeff, InputArray transl, InputArray rot, float dim){
float half_l = 0.089/2;
CV_Assert(
image.getMat().total() != 0 &&
(image.getMat().channels() == 1 || image.getMat().channels() == 3)
);
CV_Assert(dim > 0);
// project square points
std::vector<cv::Point3f> squarePoints;
squarePoints.push_back(cv::Point3f(half_l, half_l, 0));
squarePoints.push_back(cv::Point3f(half_l, -half_l, 0));
squarePoints.push_back(cv::Point3f(-half_l, -half_l, 0));
squarePoints.push_back(cv::Point3f(-half_l, half_l, 0));
std::vector<cv::Point2f> imagePoints;
projectPoints(
squarePoints, rot, transl, cameraMatrix, distortionCoeff, imagePoints
);
cv::line(image, imagePoints[0], imagePoints[1], cv::Scalar(255, 0, 0), 3);
cv::line(image, imagePoints[1], imagePoints[2], cv::Scalar(255, 0, 0), 3);
cv::line(image, imagePoints[2], imagePoints[3], cv::Scalar(255, 0, 0), 3);
cv::line(image, imagePoints[3], imagePoints[0], cv::Scalar(255, 0, 0), 3);
}