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)
- Print out a Charucho board
- Save the configuration file: defaultConfig.xml
-
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"?> <opencv_storage> <charuco_dict>10</charuco_dict> <charuco_square_lenght>200</charuco_square_lenght> <charuco_marker_size>100</charuco_marker_size> <calibration_step>1</calibration_step> <max_frames_num>30</max_frames_num> <min_frames_num>10</min_frames_num> <solver_eps>1e-7</solver_eps> <solver_max_iters>30</solver_max_iters> <fast_solver>0</fast_solver> <frame_filter_conv_param>0.1</frame_filter_conv_param> <camera_resolution>1280 720</camera_resolution> </opencv_storage>
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!
Resources:
- https://docs.opencv.org/trunk/d7/d21/tutorial_interactive_calibration.html
- https://docs.opencv.org/3.2.0/dc/dbb/tutorial_py_calibration.html
- https://docs.opencv.org/3.1.0/df/d4a/tutorial_charuco_detection.html
One Response to OpenCV Charuco Camera-Calibration