From 4a5c7ad8bf29afc5af893c524e5753de302873b7 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 14 Jun 2023 11:36:40 +0200 Subject: Renaming ArUcoCamera into ArUcoOpticCalibrator. Using OpticParameters class to handle K and D parameters. --- .../user_guide/ar_environment/environment_setup.md | 2 +- .../areas_of_interest/aoi_scene_projection.md | 4 +-- .../user_guide/aruco_markers/camera_calibration.md | 42 +++++++++++++--------- docs/user_guide/aruco_markers/introduction.md | 2 +- docs/user_guide/aruco_markers/markers_detection.md | 4 +-- docs/user_guide/utils/demonstrations_scripts.md | 2 +- docs/user_guide/utils/ready-made_scripts.md | 2 +- 7 files changed, 33 insertions(+), 25 deletions(-) (limited to 'docs') diff --git a/docs/user_guide/ar_environment/environment_setup.md b/docs/user_guide/ar_environment/environment_setup.md index 367030c..bbfdbd6 100644 --- a/docs/user_guide/ar_environment/environment_setup.md +++ b/docs/user_guide/ar_environment/environment_setup.md @@ -15,7 +15,7 @@ Here is JSON environment file example where it is assumed that mentioned .obj fi "name": "DICT_APRILTAG_16h5" } "marker_size": 5, - "camera": { + "optic_parameters": { "rms": 0.6, "dimensions": [ 1920, diff --git a/docs/user_guide/areas_of_interest/aoi_scene_projection.md b/docs/user_guide/areas_of_interest/aoi_scene_projection.md index a23d069..4d06e87 100644 --- a/docs/user_guide/areas_of_interest/aoi_scene_projection.md +++ b/docs/user_guide/areas_of_interest/aoi_scene_projection.md @@ -14,8 +14,8 @@ An [AOI3DScene](/argaze/#argaze.AreaOfInterest.AOI3DScene) can be rotated and tr # Assuming pose estimation is done (tvec and rmat) -# Project AOI 3D scene according pose estimation and camera intrinsic parameters -aoi2D_scene = aoi3D_scene.project(tvec, rmat, aruco_camera.K) +# Project AOI 3D scene according pose estimation and optic parameters +aoi2D_scene = aoi3D_scene.project(tvec, rmat, optic_parameters.K) # Draw AOI 2D scene aoi2D_scene.draw(frame) 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') ``` diff --git a/docs/user_guide/aruco_markers/introduction.md b/docs/user_guide/aruco_markers/introduction.md index fbf01cf..7da045c 100644 --- a/docs/user_guide/aruco_markers/introduction.md +++ b/docs/user_guide/aruco_markers/introduction.md @@ -10,6 +10,6 @@ The ArGaze [ArUcoMarkers submodule](/argaze/#argaze.ArUcoMarkers) eases markers * [ArUcoMarkersDictionary](/argaze/#argaze.ArUcoMarkers.ArUcoMarkersDictionary) * [ArUcoMarkers](/argaze/#argaze.ArUcoMarkers.ArUcoMarker) * [ArUcoBoard](/argaze/#argaze.ArUcoMarkers.ArUcoBoard) -* [ArUcoCamera](/argaze/#argaze.ArUcoMarkers.ArUcoCamera) +* [ArUcoOpticCalibrator](/argaze/#argaze.ArUcoMarkers.ArUcoOpticCalibrator) * [ArUcoDetector](/argaze/#argaze.ArUcoMarkers.ArUcoDetector) * [ArUcoScene](/argaze/#argaze.ArUcoMarkers.ArUcoScene) \ No newline at end of file diff --git a/docs/user_guide/aruco_markers/markers_detection.md b/docs/user_guide/aruco_markers/markers_detection.md index d962b7b..f8a23f9 100644 --- a/docs/user_guide/aruco_markers/markers_detection.md +++ b/docs/user_guide/aruco_markers/markers_detection.md @@ -8,7 +8,7 @@ Firstly, the [ArUcoDetector](/argaze/#argaze.ArUcoMarkers.ArUcoDetector.ArUcoDet Notice that extra parameters are passed to detector: see [OpenCV ArUco markers detection parameters documentation](https://docs.opencv.org/4.x/d1/dcd/structcv_1_1aruco_1_1DetectorParameters.html) to know more. ``` python -from argaze.ArUcoMarkers import ArUcoDetector, ArUcoCamera +from argaze.ArUcoMarkers import ArUcoDetector, ArUcoOpticCalibrator # Assuming camera calibration data are loaded @@ -16,7 +16,7 @@ from argaze.ArUcoMarkers import ArUcoDetector, ArUcoCamera extra_parameters = ArUcoDetector.DetectorParameters.from_json('./detector_parameters.json') # Create ArUco detector to track DICT_APRILTAG_16h5 5cm length markers -aruco_detector = ArUcoDetector.ArUcoDetector(camera=aruco_camera, dictionary='DICT_APRILTAG_16h5', marker_size=5, parameters=extra_parameters) +aruco_detector = ArUcoDetector.ArUcoDetector(optic_parameters=optic_parameters, dictionary='DICT_APRILTAG_16h5', marker_size=5, parameters=extra_parameters) ``` Here is [DetectorParameters](/argaze/#argaze.ArUcoMarkers.ArUcoDetector.DetectorParameters) JSON file example: diff --git a/docs/user_guide/utils/demonstrations_scripts.md b/docs/user_guide/utils/demonstrations_scripts.md index 5c4ef2b..adcc8b3 100644 --- a/docs/user_guide/utils/demonstrations_scripts.md +++ b/docs/user_guide/utils/demonstrations_scripts.md @@ -18,7 +18,7 @@ python ./src/argaze/utils/demo_ar_features_run.py -d DEVICE ``` !!! warning - This demonstration assumes that camera calibration step is done and a **calibration.json** has been exported into *./src/argaze/utils/demo_environment/* folder. + This demonstration assumes that camera calibration step is done and a **optic_parameters.json** has been exported into *./src/argaze/utils/demo_environment/* folder. !!! note Use **A3_demo.pdf** file located in *./src/argaze/utils/demo_environment/* folder ready to be printed on A3 paper sheet. diff --git a/docs/user_guide/utils/ready-made_scripts.md b/docs/user_guide/utils/ready-made_scripts.md index 82039c5..4ab8b52 100644 --- a/docs/user_guide/utils/ready-made_scripts.md +++ b/docs/user_guide/utils/ready-made_scripts.md @@ -25,7 +25,7 @@ python ./src/argaze/utils/aruco_calibration_board_export.py 7 5 5 3 DICT_APRILTA ## Camera calibration -Calibrate a camera device (-d DEVICE) using a 7 columns and 5 rows calibration board made of 5cm squares with 3cm markers from *DICT_APRILTAG_16h5* dictionary. Then, export its optical parameters into an *calibration.json* file into *./src/argaze/utils/demo_environment/* folder: +Calibrate a camera device (-d DEVICE) using a 7 columns and 5 rows calibration board made of 5cm squares with 3cm markers from *DICT_APRILTAG_16h5* dictionary. Then, export its optical parameters into an *optic_parameters.json* file into *./src/argaze/utils/demo_environment/* folder: ```shell python ./src/argaze/utils/camera_calibrate.py 7 5 5 3 DICT_APRILTAG_16h5 -d DEVICE -o ./src/argaze/utils/demo_environment -- cgit v1.1