Skip to content

Aruco pose estimation in Python differs from C++ #3263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
matialmar opened this issue May 24, 2022 · 3 comments
Closed
4 tasks done

Aruco pose estimation in Python differs from C++ #3263

matialmar opened this issue May 24, 2022 · 3 comments

Comments

@matialmar
Copy link

System information (version)
  • OpenCV => 4.5.5
  • Operating System / Platform => Ubuntu 20.02
  • Compiler => G++
Detailed description

I performed pose estimation with Arucos in Python3 with OpenCV 4.5.5 (installed via pip) and works as expected.
Rewriting the code in C++ with OpenCV 4.5.5 (built from source) the axes are flipped and translated from the center.
The corners are detected as expected in both Python and C++

I cant provide the full image (IP reasons) but i can provide a sample showcasing the error.

The camera matrix and distortion coefficients are the same in both.
Camera matrix:
[1256.90057913919, 0, 879.4298086122573;
0, 1254.48702971061, 504.1243816908799;
0, 0, 1]

Dist coeffs:
[-0.0552371547544854, -0.09931921582386366, 0.0007686659523849842, -0.002406439165687887, 0.02099621803945325]

Expected output (from Python):
correct

Resulting output (C++)
wrong

Steps to reproduce

Python code:

# Ommiting the code for reading the image and camera calibration

dictionary = cv2.aruco.Dictionary_get(ARUCO_DICT["DICT_6X6_250"])

parameters = cv2.aruco.DetectorParameters_create()
parameters.cornerRefinementMethod = cv2.aruco.CORNER_REFINE_SUBPIX

(corners, ids, _) = cv2.aruco.detectMarkers(image, dictionary, parameters)
rvec, tvec, _ = cv2.aruco.estimatePoseSingleMarkers(corners, 0.1, mtx, dist)

cv2.aruco.drawDetectedMarkers(image,corners,ids)
for i in range(0, len(ids)):
    cv2.aruco.drawAxis(image, mtx, dist, rvec[i], tvec[i], 0.05) 

# Ommiting the code for displaying the image

C++ Code

C++ code

std::vector< int > ids;
std::vector< std::vector<cv::Point2f> > corners;
std::vector< cv::Vec3d > tvecs;
std::vector< cv::Vec3d > rvecs;

cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);

cv::Ptr<cv::aruco::DetectorParameters> parameters  = cv::aruco::DetectorParameters::create();
parameters->cornerRefinementMethod = cv::aruco::CORNER_REFINE_SUBPIX;

// Ommiting the code for reading images and camera calibration

cv::aruco::detectMarkers(image, dictionary, corners, ids, parameters);
cv::aruco::estimatePoseSingleMarkers(corners, 0.1, cameraMatrix, distCoeffs, rvecs, tvecs);
    
cv::aruco::drawDetectedMarkers(image, corners, ids);
for(int i=0; i< ids.size(); i++)
    cv::drawFrameAxes(image, cameraMatrix, distCoeffs, rvecs[i], detection.tvec[i], 0.05);

// Ommiting the code for displaying the image
Issue submission checklist
  • I report the issue, it's not a question

  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution

  • I updated to the latest OpenCV version and the issue is still there

  • There is reproducer code and related data files: videos, images, onnx, etc

@matialmar matialmar changed the title Aruco pose estimation in python differs in c++ Aruco pose estimation in Python differs from C++ May 24, 2022
@alalek
Copy link
Member

alalek commented May 24, 2022

Original unmodified image is necessary for reproducer.

@matialmar
Copy link
Author

Original unmodified image is necessary for reproducer.

Sorry for the delay. Here is the unmodified image.
original

@asmorkalov
Copy link
Contributor

Most probably it's duplicate for #3252. Alexander Panov already prepared fix for that in #3256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants