@@ -25,19 +25,74 @@ def _user_arguments() -> argparse.Namespace:
2525 parser = argparse .ArgumentParser (
2626 description = "Stitch point clouds from multiple Zivid cameras using transformation matrices."
2727 )
28+
2829 parser .add_argument (
2930 "yaml_files" ,
3031 type = Path ,
3132 nargs = "+" ,
3233 help = "YAML files containing the corresponding transformation matrices (one per camera)." ,
3334 )
35+
36+ parser .add_argument (
37+ "-o" ,
38+ "--output-file" ,
39+ required = False ,
40+ type = Path ,
41+ help = "Save the stitched point cloud to a file with this name (.ply)" ,
42+ )
43+
3444 parser .add_argument (
35- "-o" , "--output-file" , type = Path , help = "Save the stitched point cloud to a file with this name (.ply)"
45+ "--settings-path" ,
46+ required = False ,
47+ type = Path ,
48+ help = "Path to the camera settings YML file" ,
3649 )
50+
3751 return parser .parse_args ()
3852
3953
54+ def sanitized_model_name (camera : zivid .Camera ) -> str :
55+ """Get a string that represents the camera model name.
56+
57+ Args:
58+ camera: Zivid camera
59+
60+ Raises:
61+ RuntimeError: If unsupported camera model for this code sample
62+
63+ Returns:
64+ A string representing the camera model name
65+
66+ """
67+ model = camera .info .model
68+
69+ model_map = {
70+ zivid .CameraInfo .Model .zividTwo : "Zivid_Two_M70" ,
71+ zivid .CameraInfo .Model .zividTwoL100 : "Zivid_Two_L100" ,
72+ zivid .CameraInfo .Model .zivid2PlusM130 : "Zivid_Two_Plus_M130" ,
73+ zivid .CameraInfo .Model .zivid2PlusM60 : "Zivid_Two_Plus_M60" ,
74+ zivid .CameraInfo .Model .zivid2PlusL110 : "Zivid_Two_Plus_L110" ,
75+ zivid .CameraInfo .Model .zivid2PlusMR130 : "Zivid_Two_Plus_MR130" ,
76+ zivid .CameraInfo .Model .zivid2PlusMR60 : "Zivid_Two_Plus_MR60" ,
77+ zivid .CameraInfo .Model .zivid2PlusLR110 : "Zivid_Two_Plus_LR110" ,
78+ zivid .CameraInfo .Model .zivid3XL250 : "Zivid_Three_XL250" ,
79+ }
80+ if model not in model_map :
81+ raise RuntimeError (f"Unhandled camera model: { camera .info ().model ().to_string ()} " )
82+
83+ return model_map [model ]
84+
85+
4086def connect_to_all_available_cameras (cameras : List [zivid .Camera ]) -> List [zivid .Camera ]:
87+ """get a list of available cameras and connect to them.
88+
89+ Args:
90+ cameras: List of Zivid cameras
91+
92+ Returns:
93+ List of connected Zivid cameras
94+
95+ """
4196 connected_cameras = []
4297 for camera in cameras :
4398 if camera .state .status == zivid .CameraState .Status .available :
@@ -60,10 +115,11 @@ def get_transformation_matrices_from_yaml(
60115 cameras: List of connected Zivid cameras
61116
62117 Returns:
63- A dictionary mapping camera serial numbers to their corresponding transformation matrices
118+ transforms_mapped_to_cameras: A dictionary mapping camera serial numbers to their corresponding transformation matrices
64119
65120 Raises:
66121 RuntimeError: If a YAML file for a camera is missing
122+
67123 """
68124 transforms_mapped_to_cameras = {}
69125 for camera in cameras :
@@ -100,11 +156,12 @@ def main() -> None:
100156
101157 # DOCTAG-START-CAPTURE-AND-STITCH-POINT-CLOUDS-PART1
102158 for camera in connected_cameras :
103- settings_path = (
104- get_sample_data_path ()
105- / "Settings"
106- / f"{ camera .info .model_name .replace ('2+' , 'Two_Plus' ).replace ('2' , 'Two' ).replace ('3' , 'Three' ).replace (' ' , '_' )} _ManufacturingSpecular.yml"
107- )
159+ if args .settings_path is not None :
160+ settings_path = args .settings_path
161+ else :
162+ settings_path = (
163+ get_sample_data_path () / "Settings" / f"{ sanitized_model_name (camera )} _ManufacturingSpecular.yml"
164+ )
108165 print (f"Imaging from camera: { camera .info .serial_number } " )
109166 frame = camera .capture (zivid .Settings .load (settings_path ))
110167 unorganized_point_cloud = frame .point_cloud ().to_unorganized_point_cloud ()
@@ -115,13 +172,13 @@ def main() -> None:
115172 print ("Voxel-downsampling the stitched point cloud" )
116173 final_point_cloud = stitched_point_cloud .voxel_downsampled (0.5 , 1 )
117174
118- print (f"Visualizing the stitched point cloud ({ len ( final_point_cloud .size ()) } data points)" )
175+ print (f"Visualizing the stitched point cloud ({ final_point_cloud .size } data points)" )
119176 display_pointcloud (final_point_cloud )
120177
121- if args .output_file :
122- print (f"Saving { len ( final_point_cloud .size ()) } data points to { args .output_file } " )
178+ if args .output_file is not None :
179+ print (f"Saving { final_point_cloud .size } data points to { args .output_file } " )
123180 export_unorganized_point_cloud (
124- final_point_cloud , PLY (args .output_file , layout = PLY .Layout .unordered , color_space = ColorSpace .srgb )
181+ final_point_cloud , PLY (str ( args .output_file ) , layout = PLY .Layout .unordered , color_space = ColorSpace .srgb )
125182 )
126183
127184
0 commit comments