OpenCV OpenGL AR. tvec x y position incorrect.

asked 2020-04-13 18:35:59 -0600

Noamco3 gravatar image

I have an odd problem with the ArUco marker detection. for some reason the x and y axisez in the tvec dont match.

the error only increses the furthur i get from the upper left corner of the screan and the furthur i am from the camera. the axis seem to becorrect when i draw the axis.

im not sure what is the problem and i hope one of you can assist me, im new to both opencv and opengl.

drawing the axis:

image description image description

drawing a cube:

image description image description image description image description

code:

`std::vector<cv::vec3d> rvec; std::vector<cv::vec3d> tvec;

            cv::aruco::estimatePoseSingleMarkers(poi, 0.1f, this->_cam->cameraM, this->_cam->dco, rvec, tvec);

            cv::Rodrigues(rvec[0], rot_mat);

            trans = {
                rot_mat.at<double>(0,0),
                -rot_mat.at<double>(1,0),
                -rot_mat.at<double>(2,0),
                0.0,
                rot_mat.at<double>(0,1),
                -rot_mat.at<double>(1,1),
                -rot_mat.at<double>(2,1),
                0.0,
                rot_mat.at<double>(0,2),
                -rot_mat.at<double>(1,2),
                -rot_mat.at<double>(2,2),
                0.0,
                tvec[0][0],
                -tvec[0][1],
                -tvec[0][2],
                1.0
            };

finding the marker corners:

std::vector<std::vector<cv::Point2f> > corners;

cv::aruco::detectMarkers(pic, this->dictionary, corners, ids);

for (int i = 0; i < ids.size(); i++)
{
    ans[ids[i]] = Marker(corners[i]);
}

calculating the perspective projection:

this->projection_perspective = { fx / cx, 0, 0, 0,
    0, fy / cy, 0, 0,
    0, 0, -(Ifar + Inear) / (Ifar - Inear), -(2 * Ifar*Inear) / (Ifar - Inear),
    0, 0, -1, 0 };

this->projection_perspective = glm::transpose(projection_perspective);

camera matrix: 488.1376376745014f, 0, 253.0715989656472f, 0, 498.9594153933512f, 140.5037242647958f, 0, 0, 1

distance co: -0.1222389325494649, 0.2889414791568923, -0.04209010131697889, -0.01354673693111083, -0.2503457825759766

edit retag flag offensive close merge delete

Comments

seems like i wont get any anwer soon.

Noamco3 gravatar imageNoamco3 ( 2020-04-16 20:00:19 -0600 )edit