bhomaidan90
bhomaidan90

Reputation: 304

Camera calibration using OpenCV 4.10

I have a ChArUco board and I do like to do intrinsic camera calibration using OpenCV 4.10, what I have tried is to mimic this answer:

import os
import cv2
import glob

img_folder_path = f"{os.getenv('HOME')}/rgb/"

aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_5X5_250)
board = cv2.aruco.CharucoBoard(
    size=(14, 9), 
    squareLength=0.04, 
    markerLength=0.03, 
    dictionary=aruco_dict)

ch_params = cv2.aruco.CharucoParameters()
detector_params = cv2.aruco.DetectorParameters()
refine_params = cv2.aruco.RefineParameters(minRepDistance=0.05, errorCorrectionRate=0.1, checkAllOrders=True)

ch_detector = cv2.aruco.CharucoDetector(
    board=board,charucoParams=ch_params, 
    detectorParams=detector_params, 
    # refineParams=refine_params
)

all_ch_corners = []
all_ch_ids = []
image_size = None

images = glob.glob(img_folder_path + '/*.png')

for image_file in images:
    image = cv2.imread(image_file)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    
    charucoCorners, charucoIds, markerCorners, markerIds = ch_detector.detectBoard(gray)
    
    if charucoIds is not None and len(charucoCorners) > 3:
        all_ch_corners.append(charucoCorners)
        all_ch_ids.append(charucoIds)

result, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.aruco.calibrateCameraCharuco(
    all_ch_corners, 
    all_ch_ids, 
    board, 
    image.shape[:2], 
    None, 
    None
)
print("camera_matrix: \n", camera_matrix, "dist_coeffs: \n", dist_coeffs)

but I get an error:

AttributeError: module 'cv2.aruco' has no attribute 'calibrateCameraCharuco

Also in the documentation I see a note: Aruco markers, module functionality was moved to objdetect module

Can you please tell me how can I fix that Error?

Upvotes: 2

Views: 300

Answers (1)

BЈовић
BЈовић

Reputation: 64283

The aruco module is not part of the opencv core. It is still part of the opencv_contrib. So, in order to use cv2.aruco.calibrateCameraCharucoyou have to install opencv_contrib.

This still holds for opencv 4.12.

Upvotes: 0

Related Questions