-
Notifications
You must be signed in to change notification settings - Fork 0
5940 Camera Lens Calibration Guide
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.
- 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)
If using the existing 10x10 DRG checkerboard (from calib.io):
- Inspect the board for damage or warping
- Ensure all squares are clearly visible and undamaged
- Verify the board is completely flat
If you need to create a new calibration board:
-
Printing the calibration target
- Use the high-quality Canon color printer
- Select "fit to paper" in printer settings
- Print the 10x10 checkerboard pattern
-
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
-
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
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:
- Position the checkerboard so it's fully visible to the camera
- 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
- 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
-
Clone the calibration repository:
git clone https://github.com/BREAD5940/camera-calibration
-
Install Docker Desktop if not already installed
-
Verify Docker installation:
docker --version
-
Build the Docker image:
./build_docker_image.sh
This process typically takes a few minutes to complete.
- 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:
-
Execute the calibration script:
./run-cal-with-docker.sh <video_file>
Note: The process takes approximately 7 minutes. Do not interrupt it.
-
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:
-
Locate the generated calibration file:
- Find the
.json
file named after your camera - Save this file in a secure location
- Find the
-
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
After completing the calibration:
- Test the camera using AprilTags
- Verify 3D tracking accuracy
- 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
- 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.