Skip to content
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

ChArUco pattern has broken backward compatibility #23152

Closed
4 tasks done
stefan523 opened this issue Jan 19, 2023 · 6 comments
Closed
4 tasks done

ChArUco pattern has broken backward compatibility #23152

stefan523 opened this issue Jan 19, 2023 · 6 comments

Comments

@stefan523
Copy link
Contributor

System Information

OpenCV version: 4.7.0

Detailed description

ChArUco patterns have been moved recently from OpenCV contrib to the main branch in OpenCV 4.7.0, but such patterns have been used for a longer time across the world. Backwards compatiblity with pre-existing targets and data needs to be ensured to avoid waste of resources and material.

OpenCV (contrib) 4.6.0 introduced a backwards incompatible change in ChArUco pattern generation for even row count. The impact is quite big.

  • Existing calibration targets that have been self-manufactured or procured expensively are incompatible with the latest OpenCV versions.
  • On stock targets from e.g. https://calib.io/ do not work with OpenCV anymore.
  • Acquired calibration data images cannot be processed anymore.

Related issues in OpenCV contrib:

A fix is available that enables support for pre and post 4.6.0 patterns.

Steps to reproduce

import cv2
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_5X5_1000)
charuco_board = cv2.aruco.CharucoBoard_create(
    squaresX = 5,
    squaresY = 4,
    squareLength = 4,
    markerLength = 3,
    dictionary = aruco_dict
)
img_board = charuco_board.draw((250,200), marginSize=0, borderBits=1)
cv2.imwrite('charuco_OpenCV-' + cv2.__version__ + '.png', img_board)

OpenCV 4.5.5:
OpenCV 4 5 5

OpenCV 4.6.0:
OpenCV 4 6 0

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)
@stefan523
Copy link
Contributor Author

A pull request with a fix has been raised: #23153

@stefan523
Copy link
Contributor Author

Code to reproduce with OpenCV 4.7.0 (slightly changed interface):

import cv2
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_5X5_1000)
charuco_board = cv2.aruco.CharucoBoard(
    size = [5, 4],
    squareLength = 4,
    markerLength = 3,
    dictionary = aruco_dict
)
img_board = charuco_board.generateImage((250,200), marginSize=0, borderBits=1)
cv2.imwrite('charuco_OpenCV-' + cv2.__version__ + '.png', img_board)

charuco_OpenCV-4 7 0

@stefan523
Copy link
Contributor Author

Fix in #23153 was merged (thanks @asmorkalov!). Will be resolved in next OpenCV release 4.8.0.

@M-A-Robson
Copy link

M-A-Robson commented Jul 12, 2023

This is still an issue in 4.8.0.74

calib.io target:
image

python generated target:

aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_250)
board = aruco.CharucoBoard((5, 4), 0.015, 0.012, aruco_dict)
imboard = board.generateImage((10000, 10000))

image

@gmedan
Copy link

gmedan commented Jul 12, 2023

You need to add board.setLegacyPattern(True)

@M-A-Robson
Copy link

Thank you @gmedan I had missed that. Here is a code snippet for those coming across this at a later date:

aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_250)
board = aruco.CharucoBoard((5, 4), 0.015, 0.012, aruco_dict)
board.setLegacyPattern(True)
imboard = board.generateImage((10000, 10000))

result:
image

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

4 participants