Python - Camera Calibration Charuco Diamond Intrinsic parameters help

Hi everyone, I’m fairly new to using OpenCV and working on a project that looks into different implementations of camera calibration using Python. I’m making use of Charuco Diamond as one of my implementations. I’ve tried to consult various resources online for help and so far not much help fixing this bug which prevents the program from running. Is there anyone that could help with finding the fix behind this bug?

Traceback (most recent call last):
File “C:\Users\asus\PycharmProjects\Calibr8\src\charuco_diamond\int_charuco_diamond.py”, line 49, in
ret, K, d, rvec, tvec = cv2.aruco.calibrateCameraCharuco(all_corners, all_ids, board, imsize, None, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv_contrib\modules\aruco\src\aruco_calib.cpp:69: error: (-215:Assertion failed) _charucoIds.total() > 0 && (_charucoIds.total() == _charucoCorners.total()) in function ‘cv::aruco::calibrateCameraCharuco’

I can provide the code below here

import cv2
import os
import sys
from glob import glob

import matplotlib.pyplot as plt

module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
    sys.path.append(module_path)

# Chessboard configuration
square_length = 200
marker_length = 120
diamond_marker_ids = (45, 68, 28, 74)  # any 4 markers can define a diamond
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
# Draw Charuco board
board = cv2.aruco.CharucoBoard((3, 3), square_length, marker_length, aruco_dict)

# Input images capturing the chessboard above
input_files = 'data/*.jpg'

parameters = cv2.aruco.DetectorParameters()
parameters.cornerRefinementMethod = cv2.aruco.CORNER_REFINE_CONTOUR

all_corners = []
all_ids = []

for i in sorted(glob(input_files)):
    frame = cv2.imread(i)

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    corners, ids, rejected_points = cv2.aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
    if len(corners) > 0:
        ret, c_corners, c_ids = cv2.aruco.interpolateCornersCharuco(corners, ids, gray, board)
        print(f'{i}  found {ret} corners')
        if ret > 0:
            all_corners.append(c_corners)
            all_ids.append(c_ids)

    imsize = (gray.shape[1], gray.shape[0])

    # show sample image
    plt.figure()
    plt.imshow(frame)
    plt.title('Input Image')
    plt.show()

ret, K, d, rvec, tvec = cv2.aruco.calibrateCameraCharuco(all_corners, all_ids, board, imsize, None, None,
                                                         flags=cv2.CALIB_FIX_ASPECT_RATIO + cv2.CALIB_RATIONAL_MODEL)

print("Re-projection error = ", ret)
print("Intrinsic parameter K = ", K)
print("Distortion parameters d = (k1, k2, p1, p2, k3, k4, k5, k6) = ", d)

assert ret < 1.0

If it would also be of any help I can provide the entire repository (this class being located in src < charuco_diamond < int_charuco_diamond.py)

Any help is greatly appreciated and if there are any questions that you have I’m happy to answer them thanks!!

May be it’s time to wait …

[* Prepared PR Move Charuco/Calib tutorials and samples to main repo #25378

  • update/fix charuco_detection.markdown, images and samples
  • update/fix charuco_diamond_detection.markdown, images and samples
  • update/fix aruco_calibration.markdown, images and samples
  • update/fix aruco_faq.markdown and images
  • moving tutorials, samples and tests to main repo
  • Prepared and merged PR add detectDiamonds to diamond test #3713](2024 · opencv/opencv Wiki · GitHub)

when in doubt, look for the “deprecated” aruco api in opencv. it still works. the “new” one is, IMHO, unusable. partly at least. issues relating to aruco keep being reported.

It seems like that best option is to scrap this and try something else, thanks for your help though!!

Maybe it’s something I might look into later but for now, I’ll just put it on hold I think. Thanks for the help though!!