Ask Your Question
0

Camera Calibration using ChArUco and Python

asked 2016-07-15 17:21:21 -0500

jads_96 gravatar image

Hi everyone,

I've being looking for Python samples on how to calibrate a camera using the ChArUco methods, which are in the ArUco library inside the opencv_contrib, and have failed to find one. If someone can provide simple python script it will be of great benefit to me and the opencv-python community.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-07-16 01:31:49 -0500

I had the same question. Here's what seems to work for me. It's ugly but might help...

import time
import cv2.aruco as A
import numpy as np

dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
board = cv2.aruco.CharucoBoard_create(3,3,.025,.0125,dictionary)
img = board.draw((200*3,200*3))

#Dump the calibration board to a file
cv2.imwrite('charuco.png',img)


#Start capturing images for calibration
cap = cv2.VideoCapture(0)

allCorners = []
allIds = []
decimator = 0
for i in range(300):

    ret,frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    res = cv2.aruco.detectMarkers(gray,dictionary)

    if len(res[0])>0:
        res2 = cv2.aruco.interpolateCornersCharuco(res[0],res[1],gray,board)
        if res2[1] is not None and res2[2] is not None and len(res2[1])>3 and decimator%3==0:
            allCorners.append(res2[1])
            allIds.append(res2[2])

        cv2.aruco.drawDetectedMarkers(gray,res[0],res[1])

    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    decimator+=1

imsize = gray.shape

#Calibration fails for lots of reasons. Release the video if we do
try:
    cal = cv2.aruco.calibrateCameraCharuco(allCorners,allIds,board,imsize,None,None)
except:
    cap.release()

cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

Thanks so much. I'll test it soon...

jads_96 gravatar imagejads_96 ( 2016-07-17 17:15:50 -0500 )edit

Thanks it worked

jads_96 gravatar imagejads_96 ( 2016-08-20 13:28:58 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-07-15 17:21:21 -0500

Seen: 3,105 times

Last updated: Jul 15 '16