Ask Your Question

Revision history [back]

projectPoints shows wierd results

I'm trying to project a square on an aruco marker, but all I get are some random lines. I think that my rotation and translation matrix because when using aruco::drawAxis, the axis are projected ok. Here is my code for drawing a square.

void drawCube(InputOutputArray image, InputArray cameraMatrix, InputArray distortionCoeff, InputArray transl, InputArray rot, float dim){

float half_l = 0.089/2; //dim of the aruco marker /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);

}

projectPoints shows wierd results

I'm trying to project a square on an aruco marker, but all I get are some random lines. I think that my rotation and translation matrix because when using aruco::drawAxis, the axis are projected ok. Here is my code for drawing a square. square.

void drawCube(InputOutputArray image, InputArray cameraMatrix, InputArray distortionCoeff,  InputArray transl,  InputArray rot, float dim){

dim){


    float half_l = 0.089/2; //dim of the aruco marker /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);
}

}