UVDAR Camera Calibration
This page describes, step by step, the procedure for calibrating a camera used with the UVDAR system. This process needs to be repeated for each camera on the drone that uses the UVDAR system and must be performed again if the camera is moved on the drone.
-
Clone this repository using
git clone
and read the README file. -
Download Pylon viewer software.
-
Connect the camera to your computer.
-
Ensuring cameras are properly focused:
-
Set up a UV-active target (panel with UV LEDs) a few meters away from the cameras.
-
Launch the Pylon Viewer software to observe the camera image.
-
Activate the camera viewpoint.
-
Locate the target in the camera feed. It should appear as a set of small, bright spots. Focus the camera by rotating the lens until the spots in the viewer are as small and sharp as possible.
-
Once the correct focus is obtained, secure the lens’s focal distance with a glue gun.
-
Verify in Pylon Viewer that the focus has not shifted.
-
-
Taking camera images of the target to be processed:
-
Navigate to the UVDAR utilities directory:
cd uvdar_core/scripts/utilities
. -
Run the script to verify that the Basler camera is properly connected:
./basler_get_cam.sh
. The camera serial number should appear. -
Start the calibration recording:
./record_calibration_basler.sh
. -
Position the UV target (panel with UV LEDs) close to the camera and verify visibility in the termviz window.
-
Alternatively, but also recommended, you can use rqt_image_view to visualize the camera feed by opening a new terminal and running:
rosrun rqt_image_view rqt_image_view
. The script will automatically record a rosbag for calibration. -
Move the target to specific positions within the camera’s field of view:
-
Place the target at the center of the image.
-
Shift it to one side, ensuring all points remain visible along the edge of the image.
-
Repeat on the opposite side.
-
Move the target to the top edge of the image.
-
Then, position it along the bottom edge.
-
-
Stop the recording when all target positions have been captured.
-
-
Extracting images to be processed:
-
Navigate to the directory where the recorded data are stored:
cd ~/bag_files/uvdar_calib
. -
You should see a folder named after the camera’s serial number. Enter the folder corresponding to the camera you are calibrating.
-
In a new terminal, in the camera folder, restart rqt_image_view to examine the recorded images:
rosrun rqt_image_view rqt_image_view
. -
Open the bag file you just recorded.
-
Start roscore in a separate terminal:
roscore
. -
In another terminal, play the bag file:
rosbag play the_name_of_the_bag_file
. -
Refresh rqt_image_view if the recorded images do not appear automatically.
-
Now, select the key images from the recording to save. These images should capture the UV target in different positions within the frame:
-
Centered in the image.
-
On the left and right edges.
-
At the top and bottom edges.
-
-
Aim to save 9–10 images in total. Pause the playback in rqt_image_view on frames where the LEDs are fully visible (avoid any images where LEDs are obscured), then save the displayed image.
-
Save each image in JPEG format with filenames such as i_1, i_2, i_3, and so on.
-
-
Image processing:
-
Open MATLAB and run the ocam_calib.m file of this repository. This will open the calibration interface for processing the saved images.
-
Click on "Read names" and follow the instructions:
-
Base name: i_ .
-
Extension: j (for jpeg).
-
-
All the images should now be extracted.
-
Important: Remember to remove any extracted images from previous calibrations.
-
Click on "Extract UV markers" and follow the instructions:
-
All images: press Enter.
-
Along the x direction: 6 squares.
-
Along the y direction: 4 squares.
-
Spacing: 50 millimeters apart.
-
Press Enter for the remaining instructions.
-
-
You should see that all images are processed without issues.
-
Click on "Calibration".
- For the degree of polynomial, 4 is sufficient, so simply press Enter.
-
Two graphs should appear, and you can read the average pixel error in the reprojection. If it's less than 1 pixel, everything is fine.
-
Click on "Find center" — this may take some time.
-
Once the procedure is finished, you should notice that the average pixel error has decreased.
-
The final step: Click on "Calibration refinement" and press Enter for the query.
-
-
Checking the calibration results:
-
Now you can check how well everything is going by clicking on "Reproject on images."
-
Open a window and observe the circle (representing the new projections) and the crosses (representing the original projections). Verify if they match well. One circle should be at the center (it represents the projection of the center), so check if it is well centered.
-
You can also click on "Show Extrinsic" and verify if all the projections make sense relative to the camera's position.
-
Alternatively, click on "Analyze error" to ensure there is not too much bias from the center.
-
Click on "Show calib results." The bottom curve should be nearly linear if the calibration is performed correctly.
-
-
Saving the calibration file:
-
Finally, click on "Save" to save the calibration as an m80 Matlab file, and then click on "Export Data." A file named calib_results.txt should appear in your working directory.
-
Move this file to the mrs_uav_deployment package for later use.
-
The calibration procedure is now complete. Close everything, and your camera is calibrated. Repeat this process for each camera that you are using.