Skip to content

5940 Camera Lens Calibration Guide

Gautam edited this page Jan 22, 2025 · 3 revisions

Intro

Camera lens calibration is a crucial process that corrects for lens distortion and ensures accurate spatial measurements in computer vision. When a camera lens captures an image, it can introduce various types of distortion that affect the accuracy of measurements and 3D tracking. Through calibration, we create a mathematical model of these distortions, allowing PhotonVision (our vision software) to compensate for them and provide precise spatial measurements, particularly when working with AprilTag localization.

Prerequisites

  • A computer running macOS
  • Docker Desktop installed
  • High-quality printer
  • Calipers or a precise ruler
  • Rigid polycarbonate or acrylic sheet
  • Gaff tape
  • Business card (for smoothing)

Step 1: Creating the calibration checkerboard

Using existing checkerboard

If using the existing 10x10 DRG checkerboard (from calib.io):

  1. Inspect the board for damage or warping
  2. Ensure all squares are clearly visible and undamaged
  3. Verify the board is completely flat

Creating a new checkerboard

If you need to create a new calibration board:

  1. Printing the calibration target

    • Use the high-quality Canon color printer
    • Select "fit to paper" in printer settings
    • Print the 10x10 checkerboard pattern
  2. Mounting the calibration target

    • Handle the printed paper with clean hands to avoid smudges
    • Obtain a rigid polycarbonate or acrylic sheet that's larger than the pattern
    • Clean the sheet material thoroughly
    • Carefully tape the pattern to the sheet material
    • Use a business card to smooth out any air bubbles between the paper and sheet
    • Ensure the entire setup remains perfectly flat
  3. Measurement

    • Using calipers or a precise ruler, measure the width of several squares
    • Record the measurements in meters (you'll need this for the calibration software routine)
    • Take multiple measurements from different areas to ensure it's consistent

Calibration Process

Step 2: Video recording

Before starting:

  • Ensure the camera lens is properly focused
  • Do not adjust focus after starting calibration - any focus changes will require recalibration
  • Disconnect the camera's USB from the co-processor
  • Connect the camera directly to your computer while keeping it in its mount

Recording procedure:

  1. Position the checkerboard so it's fully visible to the camera
  2. Move the checkerboard through different positions and orientations:
    • Start at the center of the frame
    • Slowly tilt the board in different orientations
    • Move the board to different areas of the frame, ensure you record multiple distances
    • Ensure the entire checkerboard pattern remains visible
    • Record for approximately 2 minues
  3. Save the video file with a name that clearly identifies the specific camera

Attached below is a good example of what the video should look like:

https://drive.google.com/file/d/1aLhK3cXPQUxe845DFZqB3GR2U8DDXj4a/edit

Step 3: Software setup

  1. Clone the calibration repository:

    git clone https://github.com/BREAD5940/camera-calibration
  2. Install Docker Desktop if not already installed

  3. Verify Docker installation:

    docker --version
  4. Build the Docker image:

    ./build_docker_image.sh

    This process typically takes a few minutes to complete.

Step 4: Running calibration

  1. If using a new checkerboard, update the "object spacing" property in the 'run-cal-with-docker' script with your measured square width (in meters)

Where to edit the property in the script:

Object Spacing

  1. Execute the calibration script:

    ./run-cal-with-docker.sh <video_file>

    Note: The process takes approximately 7 minutes. Do not interrupt it.

  2. Verify calibration quality:

    • Check the generated calibration uncertainty image
    • The image should be predominantly purple
    • Purple coloring means low uncertainty in the calibration
    • Areas of other colors suggest potential calibration issues in those regions
    • If significant non-purple areas exist, consider recalibrating.

Example of an high quality calibration:

Calibration Uncertainty Graph

Step 5: Uploading to PhotonVision

  1. Locate the generated calibration file:

    • Find the .json file named after your camera
    • Save this file in a secure location
  2. Upload to PhotonVision:

    • Navigate to the Cameras tab in PhotonVision
    • Select the appropriate resolution (typically 720p)
    • Click "Import" under the calibrations section
    • Upload your calibration file
    • Verify successful upload

Verification

After completing the calibration:

  • Test the camera using AprilTags
  • Verify 3D tracking accuracy

Common issues and solutions:

  • If calibration uncertainty shows non-purple regions:
    • Ensure checkerboard is completely flat
    • Record new video with smoother movements
    • Verify checkerboard measurements
  • If PhotonVision import fails:
    • Check camera resolution matches calibration
    • Ensure the connection exists

Important notes

  • Recalibrate when:
    • Changing lens focus
    • Modifying camera mount
    • Noticing tracking accuracy issues
  • Store calibration files with clear naming conventions
  • Document calibration dates and results

Remember: Accurate calibration is very crucial for reliable 3d AprilTag tracking. Take time to follow each step carefully, and don't hesitate to recalibrate if results aren't good.