OpenCV Charuco Camera-Calibration

OpenCV is an amazing tool that can provide accurate pose information in real-time, but first you have to provide it with a model of your camera. The opencv_interactive-calibraiton tool nominally provides that capability.

Follows is a record of how I obtained calibration settings for my laptop camera. I hope others find it useful, but I’m no expert and provide no warranty or guarantee. Please comment if you have feedback and let me used if this was helpful to you.

Install opencv and verify that opencv_interactive-calibration:

opencv_interactive-calibration --help

If you’re having trouble installing opencv, you might try Anaconda. After installing Anaconda, then installed opencv using the following command:

conda install -c conda-forge opencv

Once you have that opencv installed and working, complete the following tasks to get a camera matrix and distance coefficients for your specific camera.

Overview (details follow)

  1. Print out a Charucho board
  2. Save the configuration file: defaultConfig.xml
  3. opencv_interactive-calibration -h=7 -w=5 --sz=.032 --t=charuco

Step 1: Print out a board

Print out the (5,11,aruco.DICT_6X6_250) Charucho board:

If you want dimensionally accurate pose estimates, you will need to measure the length of a side of one of the bigger black squares. Mine was 3.2 centimeters.

Step 2: Save the interactive calibration file

Save the following opencv_interactive-calibration into a file named defaultConfig.xml into a folder:

<?xml version="1.0"?>
 <camera_resolution>1280 720</camera_resolution>

Step 3: Interactive calibration

Run the opencv_interactive-calibration app from the directory that you stored the configuration xml file. Set the –sz according to the size of the board you printed and measured in step 1. For mine, the black square was 3.2 centimeters.

opencv_interactive-calibration -h=7 -w=5 --sz=.032 --t=charuco

Move the calibration target around the cameras field of view until you collect enough frames to cover the field. The app will display the word OK on the overlay to indicate that a good fit has been acquired. See the image at the top.

When a good fit is acquired, press the s key while in the frame window to save an XML file with the opencv camera configuration parameters.

If things aren’t working:

When I first started trying to calibrate my camera, the interactive tool wouldn’t do anything and just showed me the video feed and no overlay.

For me, I had to basically hand-write a calibration tool before I could figure out which configurations were incorrectly set. Try following the instructions above faithfully and hopefully you’ll have better luck!


This entry was posted in MOBOT, Projects, Toys. Bookmark the permalink.

One Response to OpenCV Charuco Camera-Calibration

Leave a Reply