0

I want to know the real position and orientation of my marker. If I understood well, tvecs gives me the real position of my marker, I measure the distance with a ruler and it seems be correct even I had sometimes weird values.

If someone has an idea of why ?

Unfortunately, rvecs gives me strange value too and it's hard to measure. I hold my marker in front of the camera so the angle is approximately at 0° so rvecs needs to return [0, 0, 0] and if i turn my marker of 45° in y, i need to have [0, 45, 0] etc.

Rvecs doesn't return the orientation of the marker ?

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

        //Detection of markers
        cv::aruco::detectMarkers(image, dictionary, corners, ids);
        char key = (char) cv::waitKey(waitTime);
        // if at least one marker detected
        if (ids.size() > 0)
        {
            //std::cout << "FOUND " << std::endl;
            cv::aruco::drawDetectedMarkers(imageCopy, corners, ids);

            std::vector<cv::Vec3d> rvecs, tvecs;
            cv::aruco::estimatePoseSingleMarkers(corners, 0.01, cameraMatrix, distCoeffs, rvecs, tvecs);

            // draw axis for each marker
            for(size_t i=0; i<ids.size(); i++)
            {
                cv::aruco::drawAxis(imageCopy, cameraMatrix, distCoeffs, rvecs[i], tvecs[i], 0.1);
                if(key == 65)
                {
                    std::cout << i << std::endl;
                    std::cout << rvecs[i] << std::endl;
                    std::cout << tvecs[i] << std::endl;
                    std::cout << tvecs[i]*rvecs[i] << std::endl;
                    double distance = sqrt( (tvecs[i][0] * tvecs[i][0]) + (tvecs[i][1] * tvecs[i][1]) + (tvecs[i][2] * tvecs[i][2]) );
                    std::cout << distance << std::endl;
                    std::cout << rvecs[i][0] * 100 << " /// " << rvecs[i][1] * 100 << " /// " << rvecs[i][2] << std::endl;
                    fileOut << rvecs[i][0] << "," << rvecs[i][1] << "," << rvecs[i][2] << std::endl;
                }

            }

        }

Here my code, but I don't think I have done something wrong. Maybe I should multiply the Rvecs with something ? But for tvecs I don't need to multiply, I get directly the values

Newbi
  • 31
  • 6
  • `rvec` is a rotation vector, see: https://www2.cs.duke.edu/courses/fall13/compsci527/notes/rodrigues.pdf You can use `cv::Rodrigues` to convert from a rotation vector to a `3x3` rotation matrix. And from your rotation matrix you can convert the rotation to the representation you want (e.g. XYZ Euler angles, ...). – Catree Apr 30 '21 at 16:08
  • @Catree It's doesn't work, after I use cv::Rodrigues on my vector what can I do ? I find this tutorial : https://learnopencv.com/rotation-matrix-to-euler-angles/ but I havn't angles, I need to divide the result by (180* PI) and after that I have values who correspond with angles but not the expected angles – Newbi May 03 '21 at 07:13

0 Answers0