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!!