projectPoints shows wierd results

asked 2019-12-20 12:56:37 -0500

Jo144 gravatar image

updated 2019-12-20 14:42:35 -0500

supra56 gravatar image

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);
}
edit retag flag offensive close merge delete

Comments

and the problem is ? example image ?

berak gravatar imageberak ( 2019-12-20 14:10:07 -0500 )edit