aboutsummaryrefslogtreecommitdiff
path: root/docs/user_guide/aruco_markers/camera_calibration.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/user_guide/aruco_markers/camera_calibration.md')
-rw-r--r--docs/user_guide/aruco_markers/camera_calibration.md42
1 files changed, 25 insertions, 17 deletions
diff --git a/docs/user_guide/aruco_markers/camera_calibration.md b/docs/user_guide/aruco_markers/camera_calibration.md
index c8a0be9..ea2c51a 100644
--- a/docs/user_guide/aruco_markers/camera_calibration.md
+++ b/docs/user_guide/aruco_markers/camera_calibration.md
@@ -5,7 +5,7 @@ Any camera device have to be calibrated to compensate its optical distorsion.
![Camera calibration](../../img/camera_calibration.png)
-The first step to calibrate a [ArUcoCamera](/argaze/#argaze.ArUcoMarkers.ArUcoCamera) is to create an [ArUcoBoard](/argaze/#argaze.ArUcoMarkers.ArUcoBoard) like in the code below:
+The first step to calibrate a camera is to create an [ArUcoBoard](/argaze/#argaze.ArUcoMarkers.ArUcoBoard) like in the code below:
``` python
from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoBoard
@@ -20,20 +20,20 @@ aruco_board = ArUcoBoard.ArUcoBoard(7, 5, 5, 3, aruco_dictionary)
aruco_board.save('./calibration_board.png', 300)
```
-Then, the calibration process needs to make many different captures of an [ArUcoBoard](/argaze/#argaze.ArUcoMarkers.ArUcoBoard) through the camera and then, pass them to an [ArUcoDetector](/argaze/#argaze.ArUcoMarkers.ArUcoDetector.ArUcoDetector) instance.
+Then, the calibration process needs to make many different captures of an [ArUcoBoard](/argaze/#argaze.ArUcoMarkers.ArUcoBoard) through the camera and then, pass them to an [ArUcoDetector](/argaze/#argaze.ArUcoMarkers.ArUcoDetector.ArUcoDetector) instance to detect board corners and store them as calibration data to an [ArUcoOpticCalibrator](/argaze/#argaze.ArUcoMarkers.ArUcoOpticCalibrator) for final calibration process.
![Calibration step](../../img/camera_calibration_step.png)
The sample of code below shows how to detect board corners into camera frames, store detected corners then process them to build calibration data and, finally, save it into a JSON file:
``` python
-from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoCamera, ArUcoBoard, ArUcoDetector
+from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoOpticCalibrator, ArUcoBoard, ArUcoDetector
# Create ArUco dictionary
aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_APRILTAG_16h5')
-# Create ArUco camera
-aruco_camera = ArUcoCamera.ArUcoCamera(dimensions=(1920, 1080))
+# Create ArUco optic calibrator
+aruco_optic_calibrator = ArUcoOpticCalibrator.ArUcoOpticCalibrator()
# Create ArUco board of 7 columns and 5 rows with 5 cm squares with 3cm aruco markers inside
# Note: This board is the one expected during further board tracking
@@ -57,27 +57,35 @@ while video_stream.is_alive():
aruco_detector.draw_board(frame)
# Append tracked board data for further calibration processing
- aruco_camera.store_calibration_data(aruco_detector.board_corners, aruco_detector.board_corners_identifier)
+ aruco_optic_calibrator.store_calibration_data(aruco_detector.board_corners, aruco_detector.board_corners_identifier)
# Start camera calibration processing for Full HD image resolution
print('Calibrating camera...')
-aruco_camera.calibrate(expected_aruco_board)
+optic_parameters = aruco_optic_calibrator.calibrate(aruco_board, dimensions=(1920, 1080))
-# Print camera calibration data
-print('Calibration succeeded!')
-print(f'RMS:{aruco_camera.rms}')
-print(f'Camera matrix:{aruco_camera.K}')
-print(f'Distortion coefficients:{aruco_camera.D}')
+if optic_parameters:
-# Save camera calibration data
-aruco_camera.to_json('calibration.json')
+ print('\nCalibration succeeded!')
+
+ print(f'\nRMS:\n{optic_parameters.rms}')
+ print(f'\nDimensions:\n{optic_parameters.dimensions[0]}x{optic_parameters.dimensions[1]}')
+ print(f'\nCamera matrix:\n{optic_parameters.K}')
+ print(f'\nDistortion coefficients:\n{optic_parameters.D}')
+
+ optic_parameters.to_json(f'{args.output}/calibration.json')
+
+ print(f'\ncalibration.json file exported into {args.output} folder')
+
+else:
+
+ print('\nCalibration error.')
```
Then, the camera calibration data are loaded to compensate optical distorsion during [ArUcoMarkers](/argaze/#argaze.ArUcoMarkers.ArUcoMarker) detection:
``` python
-from argaze.ArUcoMarkers import ArUcoCamera
+from argaze.ArUcoMarkers import ArUcoOpticCalibrator
-# Load camera calibration data
-aruco_camera = ArUcoCamera.ArUcoCamera.from_json('./calibration.json')
+# Load camera optic parameters
+optic_parameters = ArUcoOpticCalibrator.OpticParameters.from_json('./calibration.json')
```