diff --git a/README.md b/README.md index a1dfe09b..b347c22f 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,9 @@ This repository contains python code samples for Zivid SDK v2.17.2. For tested compatibility with earlier SDK versions, please check out -[accompanying -releases](https://github.com/zivid/zivid-python-samples/tree/master/../../releases). +[accompanying releases]. -![image](https://www.zivid.com/hubfs/softwarefiles/images/zivid-generic-github-header.png) +![image] @@ -24,9 +23,33 @@ releases](https://github.com/zivid/zivid-python-samples/tree/master/../../releas ## Tutorials list - - [quick\_capture\_tutorial](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/quick_capture_tutorial.md) - - [capture\_tutorial](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_tutorial.md) - - [point\_cloud\_tutorial](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/point_cloud_tutorial.md) +- **Camera** + - **Capture** + - [Quick Capture Tutorial] + - [Capture Tutorial] + - [Point Cloud Capture Process] + - [2D Image Capture Process] + - [2D + 3D Capture Strategy] + - [File Camera] + - [Projector] + - **Maintenance** + - [Infield Correction] + - [Warm-up] + - [Firmware Update] +- **Applications** + - **Point Cloud** + - [Point Cloud Tutorial] + - [Downsample] + - [Transform] + - [Normals] + - [Region of Interest Tutorial] + - [Visualization Tutorial] + - [Stitching] + - **2D Image** + - [Barcode Detection] + - **System** + - [Hand-Eye Calibration] + - [Multi-Camera Calibration] ## Samples list @@ -37,162 +60,193 @@ the output generated by the camera, such as the 3D point cloud, a 2D image or other data from the camera. These samples shows how the data from the camera can be used. - - **camera** - - **basic** - - [capture](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture.py) - Capture colored point cloud, save 2D image, save 3D ZDF, - and export PLY, using the Zivid camera. - - [capture\_from\_file\_camera](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_from_file_camera.py) - Capture point clouds, with color, with the Zivid file - camera. - - [capture\_hdr\_complete\_settings](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_hdr_complete_settings.py) - Capture point clouds, with color, from the Zivid camera - with fully configured settings. - - [capture\_with\_settings\_from\_yml](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_with_settings_from_yml.py) - Capture images and point clouds, with and without color, - from the Zivid camera with settings from YML file. - - **advanced** - - [capture\_2d\_and\_3d](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/advanced/capture_2d_and_3d.py) - Capture 2D and 3D with the Zivid camera. - - [capture\_and\_print\_normals](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/advanced/capture_and_print_normals.py) - Capture Zivid point clouds, compute normals and print a - subset. - - **info\_util\_other** - - [adapt\_settings\_for\_flickering\_ambient\_light](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/adapt_settings_for_flickering_ambient_light.py) - Adapt camera acquisition settings based on known ambient - light conditions. - - [automatic\_network\_configuration\_for\_cameras](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/automatic_network_configuration_for_cameras.py) - Automatically configure the IP addresses of connected - cameras to match the network of the user's PC. - - [camera\_info](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/camera_info.py) - Print version information for Python, zivid-python and - Zivid SDK, then list cameras and print camera info and state - for each connected camera. - - [camera\_user\_data](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/camera_user_data.py) - Store user data on the Zivid camera. - - [capture\_with\_diagnostics](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/capture_with_diagnostics.py) - Capture point clouds, with color, from the Zivid camera, - with default settings and diagnostics enabled. - - [context\_manager\_with\_zivid](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/context_manager_with_zivid.py) - Sample showing how to use a context manager with Zivid - Application and safely return processed data. - - [firmware\_updater](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/firmware_updater.py) - Update firmware on the Zivid camera. - - [frame\_info](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/frame_info.py) - Read frame info from the Zivid camera. - - [get\_camera\_intrinsics](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/get_camera_intrinsics.py) - Read intrinsic parameters from the Zivid camera (OpenCV - model) or estimate them from the point cloud. - - [measure\_scene\_conditions](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/measure_scene_conditions.py) - Measure ambient light conditions in the scene and output - the measured flickering frequency of the ambient light if - flickering is detected. - - [network\_configuration](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/network_configuration.py) - Uses Zivid API to change the IP address of the Zivid - camera. - - [warmup](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/warmup.py) - Short example of a basic way to warm up the camera with - specified time and capture cycle. - - **maintenance** - - [correct\_camera\_in\_field](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/correct_camera_in_field.py) - Correct the dimension trueness of a Zivid camera. - - [reset\_camera\_in\_field](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/reset_camera_in_field.py) - Reset infield correction on a camera. - - [verify\_camera\_in\_field](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/verify_camera_in_field.py) - Check the dimension trueness of a Zivid camera. - - [verify\_camera\_in\_field\_from\_zdf](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/verify_camera_in_field_from_zdf.py) - Check the dimension trueness of a Zivid camera from a ZDF - file. - - **applications** - - **basic** - - **visualization** - - [capture\_and\_visualize\_normals](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/capture_and_visualize_normals.py) - Capture Zivid point clouds, compute normals and - convert to color map and display. - - [capture\_from\_file\_camera\_vis\_3d](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/capture_from_file_camera_vis_3d.py) - Capture point clouds, with color, with the Zivid file - camera. - - [capture\_vis\_3d](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/capture_vis_3d.py) - Capture point clouds, with color, from the Zivid - camera, and visualize it. - - [project\_image\_start\_and\_stop](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/project_image_start_and_stop.py) - Start the Image Projection and Stop it. - - [read\_zdf\_vis\_3d](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/read_zdf_vis_3d.py) - Read point cloud data from a ZDF file and visualize - it. - - **file\_formats** - - [convert\_zdf](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/file_formats/convert_zdf.py) - Convert point cloud data from a ZDF file to your - preferred format - - [read\_iterate\_zdf](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/file_formats/read_iterate_zdf.py) - Read point cloud data from a ZDF file, iterate through - it, and extract individual points. - - **advanced** - - [auto\_2d\_settings](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/auto_2d_settings.py) - Automatically find 2D settings for a 2D capture by using a - Zivid calibration board. - - [barcode\_detector](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/barcode_detector.py) - Detect and decode linear and matrix barcodes from a 2D - capture. - - [color\_balance](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/color_balance.py) - Balance color of a 2D image by using a Zivid calibration - board. - - [create\_depth\_map](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/create_depth_map.py) - Read point cloud data from a ZDF file, convert it to - OpenCV format, then extract and visualize depth map. - - [downsample](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/downsample.py) - Downsample point cloud from a ZDF file. - - [gamma\_correction](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/gamma_correction.py) - Capture 2D image with gamma correction. - - [get\_checkerboard\_pose\_from\_zdf](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/get_checkerboard_pose_from_zdf.py) - Read point cloud data of a Zivid calibration board from a - ZDF file, estimate the - - [hand\_eye\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/hand_eye_calibration.py) - Perform Hand-Eye calibration. - - [project\_and\_find\_marker](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/project_and_find_marker.py) - Show a marker using the projector, capture a set of 2D - images to find the marker coordinates (2D and 3D). - - [read\_project\_and\_capture\_image](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/read_project_and_capture_image.py) - Read a 2D image from file and project it using the camera - projector. - - [reproject\_points](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/reproject_points.py) - Illuminate checkerboard (Zivid Calibration Board) centers - by getting the checkerboard feature points - - [roi\_box\_via\_aruco\_marker](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/roi_box_via_aruco_marker.py) - Filter the point cloud based on a ROI box given relative - to the ArUco marker on a Zivid Calibration Board. - - [roi\_box\_via\_checkerboard](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/roi_box_via_checkerboard.py) - Filter the point cloud based on a ROI box given relative - to the Zivid Calibration Board. - - [stitch\_continuously\_rotating\_object](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/stitch_continuously_rotating_object.py) - Stitch point clouds from a continuously rotating object - without pre-alignment using Local Point Cloud Registration - and apply Voxel Downsample. - - [stitch\_using\_robot\_mounted\_camera](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/stitch_using_robot_mounted_camera.py) - Stitch multiple point clouds captured with a robot mounted - camera. - - [stitch\_via\_local\_point\_cloud\_registration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/stitch_via_local_point_cloud_registration.py) - Stitch two point clouds using a transformation estimated - by Local Point Cloud Registration and apply Voxel - Downsample. - - [transform\_point\_cloud\_from\_millimeters\_to\_meters](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/transform_point_cloud_from_millimeters_to_meters.py) - Transform point cloud data from millimeters to meters. - - [transform\_point\_cloud\_via\_aruco\_marker](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/transform_point_cloud_via_aruco_marker.py) - Transform a point cloud from camera to ArUco marker - coordinate frame by estimating the marker's pose from the - point cloud. - - [transform\_point\_cloud\_via\_checkerboard](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/transform_point_cloud_via_checkerboard.py) - Transform a point cloud from camera to checkerboard (Zivid - Calibration Board) coordinate frame by getting checkerboard - pose from the API. - - **hand\_eye\_calibration** - - [hand\_eye\_gui](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/hand_eye_gui.py) - Hand-Eye Calibration GUI - - [pose\_conversion\_gui](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/pose_conversion_gui.py) - Convert between different rotation formats with a GUI: - - [pose\_conversions](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/pose_conversions.py) - Convert to/from Transformation Matrix (Rotation Matrix - + Translation Vector). - - [robodk\_hand\_eye\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/robodk_hand_eye_calibration/robodk_hand_eye_calibration.py) - Generate a dataset and perform hand-eye calibration - using the Robodk interface. - - [utilize\_hand\_eye\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/utilize_hand_eye_calibration.py) - Transform single data point or entire point cloud from - camera to robot base reference frame using Hand-Eye - calibration - - [verify\_hand\_eye\_with\_visualization](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/verify_hand_eye_with_visualization.py) - Verify hand-eye calibration by transforming all - dataset point clouds and - - **ur\_hand\_eye\_calibration** - - [universal\_robots\_perform\_hand\_eye\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/ur_hand_eye_calibration/universal_robots_perform_hand_eye_calibration.py) - Script to generate a dataset and perform hand-eye - calibration using a Universal Robot UR5e robot. - - **robodk\_hand\_eye\_calibration** - - [robodk\_verify\_hand\_eye\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/robodk_hand_eye_calibration/robodk_verify_hand_eye_calibration.py) - Perform a touch test with a robot to verify - Hand-Eye Calibration using the RoboDK interface. - - **multi\_camera** - - [multi\_camera\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/multi_camera_calibration.py) - Use captures of a calibration object to generate - transformation matrices to a single coordinate frame, - from connected cameras. - - [multi\_camera\_calibration\_from\_zdf](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/multi_camera_calibration_from_zdf.py) - Use captures of a calibration object to generate - transformation matrices to a single coordinate frame, - from ZDF files. - - [stitch\_by\_transformation](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/stitch_by_transformation.py) - Use transformation matrices from Multi-Camera - calibration to transform point clouds into a single - coordinate frame, from connected cameras. - - [stitch\_by\_transformation\_from\_zdf](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/stitch_by_transformation_from_zdf.py) - Use transformation matrices from Multi-Camera - calibration to transform point clouds into single - coordinate frame, from a ZDF files. - - **robot\_guidance** - - [robodk\_robot\_guidance](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/robot_guidance/robodk_robot_guidance.py) - Guide the robot to follow a path on the Zivid - Calibration Board. - - **modules** - - **zividsamples** - - [calibration\_board\_utils](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/calibration_board_utils.py) - Utility functions for the Zivid calibration board. - - [camera\_verification](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/camera_verification.py) - def capture\_and\_measure\_from\_frame(frame: zivid.Frame) - -\> VerificationAndState: - - [color\_to\_grayscale](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/color_to_grayscale.py) - if rgba\_image.ndim \!= 3 or rgba\_image.shape\[2\] \!= 4: - [display](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/display.py) - Display relevant data for Zivid Samples. - - [paths](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/paths.py) - Get relevant paths for Zivid Samples. - - [robodk\_tools](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/robodk_tools.py) - Robot Control Module - - [save\_load\_matrix](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/save_load_matrix.py) - Save and load Zivid 4x4 transformation matrices from and - to YAML files. - - [save\_load\_transformation\_matrix](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/save_load_transformation_matrix.py) - - assert\_affine\_matrix\_and\_save(transformation\_matrix.as\_matrix(), - yaml\_path) - - [save\_residuals](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/save_residuals.py) - per\_pose\_residuals = \[ - [settings\_utils](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/settings_utils.py) - categories = zivid.presets.categories2d(camera.info.model) - - [transformation\_matrix](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/transformation_matrix.py) - Convenience functions and a class for 4x4 transformation - matrices. - - [white\_balance\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/white_balance_calibration.py) - Balance color for 2D capture using white surface as - reference. +- **camera** + - **basic** + - [capture] - Capture colored point cloud, save 2D image, save 3D + ZDF, and export PLY, using the Zivid camera. + - [capture_from_file_camera] - Capture point clouds, with color, + with the Zivid file camera. + - [capture_hdr_complete_settings] - Capture point clouds, with + color, from the Zivid camera with fully configured settings. + - [capture_with_settings_from_yml] - Capture images and point + clouds, with and without color, from the Zivid camera with + settings from YML file. + - **advanced** + - [capture_2d_and_3d] - Capture 2D and 3D with the Zivid camera. + - [capture_and_print_normals] - Capture Zivid point clouds, compute + normals and print a subset. + - **info_util_other** + - [adapt_settings_for_flickering_ambient_light] - Adapt camera + acquisition settings based on known ambient light conditions. + - [camera_info] - Print version information for Python, zivid-python + and Zivid SDK, then list cameras and print camera info and state + for each connected camera. + - [camera_user_data] - Store user data on the Zivid camera. + - [capture_with_diagnostics] - Capture point clouds, with color, + from the Zivid camera, with default settings and diagnostics + enabled. + - [context_manager_with_zivid] - Sample showing how to use a context + manager with Zivid Application and safely return processed data. + - [firmware_updater] - Update firmware on the Zivid camera. + - [frame_info] - Read frame info from the Zivid camera. + - [get_camera_intrinsics] - Read intrinsic parameters from the Zivid + camera (OpenCV model) or estimate them from the point cloud. + - [measure_scene_conditions] - Measure ambient light conditions in + the scene and output the measured flickering frequency of the + ambient light if flickering is detected. + - [warmup] - Short example of a basic way to warm up the camera with + specified time and capture cycle. + - **network** + - [automatic_network_configuration_for_cameras] - Automatically + configure the IP addresses of connected cameras to match the + network of the user's PC. + - [network_configuration] - Uses Zivid API to change the IP + address of the Zivid camera. + - **maintenance** + - [correct_camera_in_field] - Correct the dimension trueness of a + Zivid camera. + - [reset_camera_in_field] - Reset infield correction on a camera. + - [verify_camera_in_field] - Check the dimension trueness of a Zivid + camera. + - [verify_camera_in_field_from_zdf] - Check the dimension trueness + of a Zivid camera from a ZDF file. +- **applications** + - **basic** + - **visualization** + - [capture_and_visualize_normals] - Capture Zivid point clouds, + compute normals and convert to color map and display. + - [capture_from_file_camera_vis_3d] - Capture point clouds, with + color, with the Zivid file camera. + - [capture_vis_3d] - Capture point clouds, with color, from the + Zivid camera, and visualize it. + - [project_image_start_and_stop] - Start the Image Projection and + Stop it. + - [read_zdf_vis_3d] - Read point cloud data from a ZDF file and + visualize it. + - **file_formats** + - [convert_zdf] - Convert point cloud data from a ZDF file to your + preferred format + - [read_iterate_zdf] - Read point cloud data from a ZDF file, + iterate through it, and extract individual points. + - **advanced** + - [auto_2d_settings] - Automatically find 2D settings for a 2D + capture by using a Zivid calibration board. + - [capture_undistort_2d] - Use camera intrinsics to undistort a 2D + image. + - [color_balance] - Balance color of a 2D image by using a Zivid + calibration board. + - [create_depth_map] - Read point cloud data from a ZDF file, + convert it to OpenCV format, then extract and visualize depth map. + - [downsample][1] - Downsample point cloud from a ZDF file. + - [gamma_correction] - Capture 2D image with gamma correction. + - **visualization** + - [capture_vis_3d_in_loop] - Capture point clouds, with color, + from the Zivid camera, and visualize them in a loop. + - [capture_vis_3d_in_loop_with_keypress_exit] - Capture point + clouds, with color, from the Zivid camera, and visualize them in + a loop. Press 'q' to exit. + - **transform** + - [get_checkerboard_pose_from_zdf] - Read point cloud data of a + Zivid calibration board from a ZDF file, estimate the + - [transform_point_cloud_from_millimeters_to_meters] - Transform + point cloud data from millimeters to meters. + - [transform_point_cloud_via_aruco_marker] - Transform a point + cloud from camera to ArUco marker coordinate frame by estimating + the marker's pose from the point cloud. + - [transform_point_cloud_via_checkerboard] - Transform a point + cloud from camera to checkerboard (Zivid Calibration Board) + coordinate frame by getting checkerboard pose from the API. + - **roi** + - [roi_box_via_aruco_marker] - Filter the point cloud based on a + ROI box given relative to the ArUco marker on a Zivid + Calibration Board. + - [roi_box_via_checkerboard] - Filter the point cloud based on a + ROI box given relative to the Zivid Calibration Board. + - **stitching** + - [stitch_continuously_rotating_object] - Stitch point clouds from + a continuously rotating object without pre-alignment using Local + Point Cloud Registration and apply Voxel Downsample. + - [stitch_using_robot_mounted_camera] - Stitch multiple point + clouds captured with a robot mounted camera. + - [stitch_via_local_point_cloud_registration] - Stitch two point + clouds using a transformation estimated by Local Point Cloud + Registration and apply Voxel Downsample. + - **barcode** + - [barcode_detector] - Detect and decode linear and matrix + barcodes from a 2D capture. + - **hand_eye_calibration** + - [hand_eye_calibration] - Perform Hand-Eye calibration. + - [hand_eye_gui] - Hand-Eye Calibration GUI + - [pose_conversion_gui] - Convert between different rotation + formats with a GUI: + - [pose_conversions] - Convert to/from Transformation Matrix + (Rotation Matrix + Translation Vector). + - [utilize_hand_eye_calibration] - Transform single data point or + entire point cloud from camera to robot base reference frame + using Hand-Eye calibration + - [verify_hand_eye_with_visualization] - Verify hand-eye + calibration by transforming all dataset point clouds and + - **ur_hand_eye_calibration** + - [universal_robots_perform_hand_eye_calibration] - Script to + generate a dataset and perform hand-eye calibration using a + Universal Robot UR5e robot. + - **robodk_hand_eye_calibration** + - [robodk_hand_eye_calibration] - Generate a dataset and perform + hand-eye calibration using the Robodk interface. + - [robodk_verify_hand_eye_calibration] - Perform a touch test + with a robot to verify Hand-Eye Calibration using the RoboDK + interface. + - **multi_camera** + - [multi_camera_calibration] - Use captures of a calibration + object to generate transformation matrices to a single + coordinate frame, from connected cameras. + - [multi_camera_calibration_from_zdf] - Use captures of a + calibration object to generate transformation matrices to a + single coordinate frame, from ZDF files. + - [stitch_by_transformation] - Use transformation matrices from + Multi-Camera calibration to transform point clouds into a single + coordinate frame, from connected cameras. + - [stitch_by_transformation_from_zdf] - Use transformation + matrices from Multi-Camera calibration to transform point clouds + into single coordinate frame, from a ZDF files. + - **projector** + - [project_and_find_marker] - Show a marker using the projector, + capture a set of 2D images to find the marker coordinates (2D + and 3D). + - [read_project_and_capture_image] - Read a 2D image from file and + project it using the camera projector. + - [reproject_points] - Illuminate checkerboard (Zivid Calibration + Board) centers by getting the checkerboard feature points + - **robot_guidance** + - [robodk_robot_guidance] - Guide the robot to follow a path on + the Zivid Calibration Board. +- **modules** + - **zividsamples** + - [calibration_board_utils] - Utility functions for the Zivid + calibration board. + - [camera_verification] - def capture_and_measure_from_frame(frame: + zivid.Frame) -\> VerificationAndState: + - [color_to_grayscale] - if rgba_image.ndim != 3 or + rgba_image.shape\[2\] != 4: + - [display] - Display relevant data for Zivid Samples. + - [paths] - Get relevant paths for Zivid Samples. + - [robodk_tools] - Robot Control Module + - [save_load_matrix] - Save and load Zivid 4x4 transformation + matrices from and to YAML files. + - [save_load_transformation_matrix] - + assert_affine_matrix_and_save(transformation_matrix.as_matrix(), + yaml_path) + - [save_residuals] - per_pose_residuals = \[ + - [settings_utils] - categories = + zivid.presets.categories2d(camera.info.model) + - [transformation_matrix] - Convenience functions and a class for + 4x4 transformation matrices. + - [white_balance_calibration] - Balance color for 2D capture using + white surface as reference. ## Installation ------ +------------------------------------------------------------------------ Note: @@ -200,61 +254,159 @@ The recommended Python version for these samples is 3.7 - 3.9. Note that Open3D is not available for Python 3.13 and later. ------ +------------------------------------------------------------------------ -1. [Install Zivid - Software](https://support.zivid.com/en/latest//camera/getting-started/software-installation.html). +1. [Install Zivid Software]. -2. [Download Zivid Sample - Data](https://support.zivid.com/en/latest//camera/api-reference/samples/sample-data.html). +2. [Download Zivid Sample Data]. 3. Check out the Zivid Python samples repository: - - ``` sourceCode bash + + ``` bash git clone http://github.com/zivid/zivid-python-samples.git ``` 4. Install the runtime requirements using IDE or command line: -> -> -> ``` sourceCode bash +> ``` bash > cd zivid-python-samples > pip install -r requirements.txt > ``` -> -> ----- -> +> +> ------------------------------------------------------------------------ +> > Note: -> +> > If Open3D fails to install, ensure you are using a Python version > supported by Open3D. Alternatively, you can install only dependencies > required for non-Open3D samples by running: -> -> ``` sourceCode bash +> +> ``` bash > pip install ./modules > ``` -> -> ----- +> +> ------------------------------------------------------------------------ 5. Open and run one of the samples. - - ----- - + + ------------------------------------------------------------------------ + Note: - + Running GUI samples on Windows should be done via `pythonw`. - - ----- + + ------------------------------------------------------------------------ ## Support For more information about the Zivid cameras, please visit our -[Knowledge Base](https://support.zivid.com/en/latest). If you run into -any issues please check out -[Troubleshooting](https://support.zivid.com/en/latest/camera/support/troubleshooting.html). +[Knowledge Base]. If you run into any issues please check out +[Troubleshooting]. ## License -Zivid Samples are distributed under the [BSD -license](https://github.com/zivid/zivid-python-samples/tree/master/LICENSE). +Zivid Samples are distributed under the [BSD license]. + + [accompanying releases]: https://github.com/zivid/zivid-python-samples/tree/master/../../releases + [image]: https://www.zivid.com/hubfs/softwarefiles/images/zivid-generic-github-header.png + [Quick Capture Tutorial]: https://support.zivid.com/en/latest/camera/getting-started/quick-capture-tutorial.html + [Capture Tutorial]: https://support.zivid.com/en/latest/camera/academy/camera/capture-tutorial.html + [Point Cloud Capture Process]: https://support.zivid.com/en/latest/camera/academy/camera/point-cloud-capture-process.html + [2D Image Capture Process]: https://support.zivid.com/en/latest/camera/academy/camera/2d-image-capture-process.html + [2D + 3D Capture Strategy]: https://support.zivid.com/en/latest/camera/academy/camera/2d3d-capture-strategy.html + [File Camera]: https://support.zivid.com/en/latest/camera/academy/camera/file-camera.html + [Projector]: https://support.zivid.com/en/latest/camera/academy/camera/2d-image-projection.html + [Infield Correction]: https://support.zivid.com/en/latest/camera/academy/camera/infield-correction.html + [Warm-up]: https://support.zivid.com/en/latest/camera/academy/camera/warmup.html + [Firmware Update]: https://support.zivid.com/en/latest/camera/academy/camera/firmware-update.html + [Point Cloud Tutorial]: https://support.zivid.com/en/latest/camera/academy/applications/point-cloud-tutorial.html + [Downsample]: https://support.zivid.com/en/latest/camera/academy/applications/downsampling.html + [Transform]: https://support.zivid.com/en/latest/camera/academy/applications/transform.html + [Normals]: https://support.zivid.com/en/latest/camera/academy/applications/normals.html + [Region of Interest Tutorial]: https://support.zivid.com/en/latest/camera/academy/applications/roi.html + [Visualization Tutorial]: https://support.zivid.com/en/latest/camera/academy/applications/visualization-tutorial.html + [Stitching]: https://support.zivid.com/en/latest/camera/academy/applications/stitching.html + [Barcode Detection]: https://support.zivid.com/en/latest/camera/academy/applications/barcode-detection.html + [Hand-Eye Calibration]: https://support.zivid.com/en/latest/camera/academy/applications/hand-eye.html + [Multi-Camera Calibration]: https://support.zivid.com/en/latest/camera/academy/applications/multi-camera-calibration.html + [capture]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture.py + [capture_from_file_camera]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_from_file_camera.py + [capture_hdr_complete_settings]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_hdr_complete_settings.py + [capture_with_settings_from_yml]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_with_settings_from_yml.py + [capture_2d_and_3d]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/advanced/capture_2d_and_3d.py + [capture_and_print_normals]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/advanced/capture_and_print_normals.py + [adapt_settings_for_flickering_ambient_light]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/adapt_settings_for_flickering_ambient_light.py + [camera_info]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/camera_info.py + [camera_user_data]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/camera_user_data.py + [capture_with_diagnostics]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/capture_with_diagnostics.py + [context_manager_with_zivid]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/context_manager_with_zivid.py + [firmware_updater]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/firmware_updater.py + [frame_info]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/frame_info.py + [get_camera_intrinsics]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/get_camera_intrinsics.py + [measure_scene_conditions]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/measure_scene_conditions.py + [warmup]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/warmup.py + [automatic_network_configuration_for_cameras]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/network/automatic_network_configuration_for_cameras.py + [network_configuration]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/info_util_other/network/network_configuration.py + [correct_camera_in_field]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/correct_camera_in_field.py + [reset_camera_in_field]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/reset_camera_in_field.py + [verify_camera_in_field]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/verify_camera_in_field.py + [verify_camera_in_field_from_zdf]: https://github.com/zivid/zivid-python-samples/tree/master/source/camera/maintenance/verify_camera_in_field_from_zdf.py + [capture_and_visualize_normals]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/capture_and_visualize_normals.py + [capture_from_file_camera_vis_3d]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/capture_from_file_camera_vis_3d.py + [capture_vis_3d]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/capture_vis_3d.py + [project_image_start_and_stop]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/project_image_start_and_stop.py + [read_zdf_vis_3d]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/visualization/read_zdf_vis_3d.py + [convert_zdf]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/file_formats/convert_zdf.py + [read_iterate_zdf]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/basic/file_formats/read_iterate_zdf.py + [auto_2d_settings]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/auto_2d_settings.py + [capture_undistort_2d]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/capture_undistort_2d.py + [color_balance]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/color_balance.py + [create_depth_map]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/create_depth_map.py + [1]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/downsample.py + [gamma_correction]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/gamma_correction.py + [capture_vis_3d_in_loop]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/visualization/capture_vis_3d_in_loop.py + [capture_vis_3d_in_loop_with_keypress_exit]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/visualization/capture_vis_3d_in_loop_with_keypress_exit.py + [get_checkerboard_pose_from_zdf]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/transform/get_checkerboard_pose_from_zdf.py + [transform_point_cloud_from_millimeters_to_meters]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/transform/transform_point_cloud_from_millimeters_to_meters.py + [transform_point_cloud_via_aruco_marker]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/transform/transform_point_cloud_via_aruco_marker.py + [transform_point_cloud_via_checkerboard]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/transform/transform_point_cloud_via_checkerboard.py + [roi_box_via_aruco_marker]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/roi/roi_box_via_aruco_marker.py + [roi_box_via_checkerboard]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/roi/roi_box_via_checkerboard.py + [stitch_continuously_rotating_object]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/stitching/stitch_continuously_rotating_object.py + [stitch_using_robot_mounted_camera]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/stitching/stitch_using_robot_mounted_camera.py + [stitch_via_local_point_cloud_registration]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/stitching/stitch_via_local_point_cloud_registration.py + [barcode_detector]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/barcode/barcode_detector.py + [hand_eye_calibration]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/hand_eye_calibration.py + [hand_eye_gui]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/hand_eye_gui.py + [pose_conversion_gui]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/pose_conversion_gui.py + [pose_conversions]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/pose_conversions.py + [utilize_hand_eye_calibration]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/utilize_hand_eye_calibration.py + [verify_hand_eye_with_visualization]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/verify_hand_eye_with_visualization.py + [universal_robots_perform_hand_eye_calibration]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/ur_hand_eye_calibration/universal_robots_perform_hand_eye_calibration.py + [robodk_hand_eye_calibration]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/robodk_hand_eye_calibration/robodk_hand_eye_calibration.py + [robodk_verify_hand_eye_calibration]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/hand_eye_calibration/robodk_hand_eye_calibration/robodk_verify_hand_eye_calibration.py + [multi_camera_calibration]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/multi_camera_calibration.py + [multi_camera_calibration_from_zdf]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/multi_camera_calibration_from_zdf.py + [stitch_by_transformation]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/stitch_by_transformation.py + [stitch_by_transformation_from_zdf]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/multi_camera/stitch_by_transformation_from_zdf.py + [project_and_find_marker]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/projector/project_and_find_marker.py + [read_project_and_capture_image]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/projector/read_project_and_capture_image.py + [reproject_points]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/projector/reproject_points.py + [robodk_robot_guidance]: https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/robot_guidance/robodk_robot_guidance.py + [calibration_board_utils]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/calibration_board_utils.py + [camera_verification]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/camera_verification.py + [color_to_grayscale]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/color_to_grayscale.py + [display]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/display.py + [paths]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/paths.py + [robodk_tools]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/robodk_tools.py + [save_load_matrix]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/save_load_matrix.py + [save_load_transformation_matrix]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/save_load_transformation_matrix.py + [save_residuals]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/save_residuals.py + [settings_utils]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/settings_utils.py + [transformation_matrix]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/transformation_matrix.py + [white_balance_calibration]: https://github.com/zivid/zivid-python-samples/tree/master/modules/zividsamples/white_balance_calibration.py + [Install Zivid Software]: https://support.zivid.com/en/latest//camera/getting-started/software-installation.html + [Download Zivid Sample Data]: https://support.zivid.com/en/latest//camera/api-reference/samples/sample-data.html + [Knowledge Base]: https://support.zivid.com/en/latest + [Troubleshooting]: https://support.zivid.com/en/latest/camera/support/troubleshooting.html + [BSD license]: https://github.com/zivid/zivid-python-samples/tree/master/LICENSE diff --git a/modules/zividsamples/save_load_matrix.py b/modules/zividsamples/save_load_matrix.py index aae67bb0..a332bb2d 100644 --- a/modules/zividsamples/save_load_matrix.py +++ b/modules/zividsamples/save_load_matrix.py @@ -1,6 +1,9 @@ """ Save and load Zivid 4x4 transformation matrices from and to YAML files. +The translation part of the matrix must use the same unit as the point cloud it is applied to. +Zivid point clouds are in millimeters by default, so robot poses and transforms are also expected in millimeters. + """ from pathlib import Path diff --git a/source/applications/advanced/barcode_detector.py b/source/applications/advanced/barcode/barcode_detector.py similarity index 100% rename from source/applications/advanced/barcode_detector.py rename to source/applications/advanced/barcode/barcode_detector.py diff --git a/source/applications/advanced/capture_undistort_2d.py b/source/applications/advanced/capture_undistort_2d.py new file mode 100644 index 00000000..12d8eb95 --- /dev/null +++ b/source/applications/advanced/capture_undistort_2d.py @@ -0,0 +1,176 @@ +""" +Use camera intrinsics to undistort a 2D image. + +The example will prompt the user for whether to capture an image (2D) or a point cloud (3D). +In both instances it will operate on an BGRA image. However, in the 3D case it will extract +the BGRA image from the point cloud. The 2D variant is faster. + +Note: This example uses experimental SDK features, which may be modified, moved, or deleted in the future without notice. + +For more information on lens distortion and undistorting the 2D image, check out this tutorial: +https://support.zivid.com/en/latest/camera/reference-articles/color-spaces-and-output-formats.html + +""" + +from typing import Tuple + +import cv2 +import numpy as np +import zivid +import zivid.experimental.calibration +from zividsamples.display import display_bgr, display_pointcloud + + +def _image_to_bgr(image: zivid.Image) -> np.ndarray: + """Convert a Zivid BGRA image to an OpenCV BGR image. + + Args: + image: Zivid BGRA image + + Returns: + bgr: BGR image (HxWx3 ndarray) + + """ + bgra = image.copy_data() + return cv2.cvtColor(bgra, cv2.COLOR_BGRA2BGR) + + +def _get_image_3d(camera: zivid.Camera, settings: zivid.Settings) -> np.ndarray: + """Capture a point cloud and extract its color image as an OpenCV BGR image. + + Args: + camera: Zivid Camera handle + settings: Capture settings + + Returns: + bgr: BGR image (HxWx3 ndarray) + + """ + print("3D mode") + + print("Capturing frame") + frame = camera.capture_2d_3d(settings) + + print("Visualizing point cloud") + display_pointcloud(frame) + + print("Converting to OpenCV BGRA image") + image = frame.point_cloud().copy_image("bgra_srgb") + + image_file = "Image.png" + print(f"Saving 2D color image to file: {image_file}") + image.save(image_file) + + return _image_to_bgr(image) + + +def _get_image_2d(camera: zivid.Camera, settings_2d: zivid.Settings2D) -> np.ndarray: + """Capture a 2D frame and return its color image as an OpenCV BGR image. + + Args: + camera: Zivid Camera handle + settings_2d: 2D capture settings + + Returns: + bgr: BGR image (HxWx3 ndarray) + + """ + print("2D mode") + + print("Capturing 2D frame") + frame_2d = camera.capture_2d(settings_2d) + + print("Getting BGRA image") + image = frame_2d.image_bgra_srgb() + + print("Converting to OpenCV BGR image") + + image_file = "Image.png" + print(f"Saving 2D color image to file: {image_file}") + image.save(image_file) + + return _image_to_bgr(image) + + +def _reformat_camera_intrinsics(camera_intrinsics: zivid.CameraIntrinsics) -> Tuple[np.ndarray, np.ndarray]: + """Reformat Zivid camera intrinsics into an OpenCV camera matrix and distortion coefficients. + + Args: + camera_intrinsics: Zivid camera intrinsics + + Returns: + camera_matrix: OpenCV camera matrix (3x3 ndarray) + distortion_coefficients: OpenCV distortion coefficients (1x5 ndarray) + + """ + distortion_coefficients = np.zeros((1, 5), dtype=np.float64) + camera_matrix = np.zeros((3, 3), dtype=np.float64) + + distortion_coefficients[0, 0] = camera_intrinsics.distortion.k1 + distortion_coefficients[0, 1] = camera_intrinsics.distortion.k2 + distortion_coefficients[0, 2] = camera_intrinsics.distortion.p1 + distortion_coefficients[0, 3] = camera_intrinsics.distortion.p2 + distortion_coefficients[0, 4] = camera_intrinsics.distortion.k3 + + camera_matrix[0, 0] = camera_intrinsics.camera_matrix.fx + camera_matrix[0, 2] = camera_intrinsics.camera_matrix.cx + camera_matrix[1, 1] = camera_intrinsics.camera_matrix.fy + camera_matrix[1, 2] = camera_intrinsics.camera_matrix.cy + camera_matrix[2, 2] = 1 + + return camera_matrix, distortion_coefficients + + +def _main() -> None: + app = zivid.Application() + + print("Connecting to camera") + camera = app.connect_camera() + + command = input('Enter "2d" or "3d" to select mode, then press Enter/Return to confirm\n') + use_2d = command in ("2d", "2D") + + settings_2d = zivid.Settings2D(acquisitions=[zivid.Settings2D.Acquisition()]) + + settings = zivid.Settings( + acquisitions=[zivid.Settings.Acquisition()], + color=settings_2d, + ) + + bgr = _get_image_2d(camera, settings_2d) if use_2d else _get_image_3d(camera, settings) + + print("Undistorting BGR image") + + if use_2d: + camera_matrix, distortion_coefficients = _reformat_camera_intrinsics( + zivid.experimental.calibration.intrinsics(camera, settings_2d) + ) + else: + camera_matrix, distortion_coefficients = _reformat_camera_intrinsics( + zivid.experimental.calibration.intrinsics(camera, settings) + ) + + size = (bgr.shape[1], bgr.shape[0]) + optimal_camera_matrix = cv2.getOptimalNewCameraMatrix(camera_matrix, distortion_coefficients, size, 1, size)[0] + + bgr_undistorted = cv2.undistort(bgr, camera_matrix, distortion_coefficients) + bgr_undistorted_full = cv2.undistort(bgr, camera_matrix, distortion_coefficients, None, optimal_camera_matrix) + + image_distorted_file = "ImageDistorted.jpg" + display_bgr(bgr, "Distorted BGR image") + print(f"Visualizing and saving BGR image to file: {image_distorted_file}") + cv2.imwrite(image_distorted_file, bgr) + + image_undistorted_file = "ImageUndistorted.jpg" + display_bgr(bgr_undistorted, "Undistorted BGR image") + print(f"Visualizing and saving undistorted BGR image to file: {image_undistorted_file}") + cv2.imwrite(image_undistorted_file, bgr_undistorted) + + image_undistorted_full_file = "ImageUndistortedFull.jpg" + display_bgr(bgr_undistorted_full, "Undistorted BGR image - full") + print(f"Visualizing and saving undistorted BGR image (full) to file: {image_undistorted_full_file}") + cv2.imwrite(image_undistorted_full_file, bgr_undistorted_full) + + +if __name__ == "__main__": + _main() diff --git a/source/applications/advanced/create_depth_map.py b/source/applications/advanced/create_depth_map.py index 4faeae9c..3d220d96 100644 --- a/source/applications/advanced/create_depth_map.py +++ b/source/applications/advanced/create_depth_map.py @@ -8,7 +8,6 @@ import cv2 import numpy as np import zivid -from zividsamples.display import display_bgr from zividsamples.paths import get_sample_data_path @@ -50,19 +49,6 @@ def _point_cloud_to_cv_bgr(point_cloud: zivid.PointCloud) -> np.ndarray: return bgra[:, :, :3] -def _visualize_and_save_image(image: np.ndarray, image_file: str, title: str) -> None: - """Visualize and save image to file. - - Args: - image: BGR image (HxWx3 ndarray) - image_file: File name - title: OpenCV Window name - - """ - display_bgr(image, title) - cv2.imwrite(image_file, image) - - def _main() -> None: # Application class must be initialized before using other Zivid classes. app = zivid.Application() # noqa: F841 # pylint: disable=unused-variable @@ -78,14 +64,20 @@ def _main() -> None: bgr_image_file = "ImageRGB.png" print(f"Visualizing and saving BGR image to file: {bgr_image_file}") - _visualize_and_save_image(bgr, bgr_image_file, "BGR image") + cv2.imshow("BGR image", bgr) + print("Press any key to continue") + cv2.waitKey(0) + cv2.imwrite(bgr_image_file, bgr) print("Converting to Depth map in OpenCV format") z_color_map = _point_cloud_to_cv_z(point_cloud) depth_map_file = "DepthMap.png" print(f"Visualizing and saving Depth map to file: {depth_map_file}") - _visualize_and_save_image(z_color_map, depth_map_file, "Depth map") + cv2.imshow("Depth map", z_color_map) + print("Press any key to continue") + cv2.waitKey(0) + cv2.imwrite(depth_map_file, z_color_map) if __name__ == "__main__": diff --git a/source/applications/advanced/downsample.py b/source/applications/advanced/downsample.py index 6d1904f1..4b65ff10 100644 --- a/source/applications/advanced/downsample.py +++ b/source/applications/advanced/downsample.py @@ -9,7 +9,6 @@ from pathlib import Path import zivid -from zividsamples.display import display_pointcloud from zividsamples.paths import get_sample_data_path @@ -33,6 +32,22 @@ def _options() -> argparse.Namespace: return parser.parse_args() +def visualize_point_cloud(point_cloud: zivid.PointCloud) -> None: + """Display point cloud provided either as PointCloud. + + Args: + point_cloud: zivid.PointCloud + + """ + with zivid.visualization.Visualizer() as visualizer: + visualizer.set_window_title("Zivid Point Cloud Visualizer") + visualizer.colors_enabled = True + visualizer.axis_indicator_enabled = True + visualizer.show(point_cloud) + visualizer.reset_to_fit() + visualizer.run() + + def _main() -> None: user_options = _options() data_file = user_options.zdf_path @@ -45,7 +60,7 @@ def _main() -> None: print(f"Before downsampling: {point_cloud.width * point_cloud.height} point cloud") - display_pointcloud(point_cloud) + visualize_point_cloud(point_cloud) print("Downsampling point cloud") print("This does not modify the current point cloud but returns") @@ -60,7 +75,7 @@ def _main() -> None: print(f"After downsampling: {point_cloud.width * point_cloud.height} point cloud") - display_pointcloud(point_cloud) + visualize_point_cloud(point_cloud) if __name__ == "__main__": diff --git a/source/applications/advanced/hand_eye_calibration/pose_conversions.py b/source/applications/advanced/hand_eye_calibration/pose_conversions.py index 8c84191c..a4478944 100644 --- a/source/applications/advanced/hand_eye_calibration/pose_conversions.py +++ b/source/applications/advanced/hand_eye_calibration/pose_conversions.py @@ -4,6 +4,9 @@ Zivid primarily operate with a (4x4) transformation matrix. This example shows how to use Eigen to convert to and from: AxisAngle, Rotation Vector, Roll-Pitch-Yaw, Quaternion. +Note: the translation part of the transformation matrix is in millimeters (mm), since Zivid point clouds are in +millimeters. If your robot reports translation in meters, multiply it by 1000 before saving the pose. + The convenience functions from this example can be reused in applicable applications. The YAML files for this sample can be found under the main instructions for Zivid samples. diff --git a/source/applications/advanced/hand_eye_calibration/ur_hand_eye_calibration/universal_robots_perform_hand_eye_calibration.py b/source/applications/advanced/hand_eye_calibration/ur_hand_eye_calibration/universal_robots_perform_hand_eye_calibration.py index 6a1b3b6d..c35883c5 100644 --- a/source/applications/advanced/hand_eye_calibration/ur_hand_eye_calibration/universal_robots_perform_hand_eye_calibration.py +++ b/source/applications/advanced/hand_eye_calibration/ur_hand_eye_calibration/universal_robots_perform_hand_eye_calibration.py @@ -175,7 +175,8 @@ def _get_frame_and_transform_matrix( frame = camera.capture_2d_3d(settings) robot_pose = np.array(con.receive().actual_TCP_pose) - translation = robot_pose[:3] * 1000 + meters_to_millimeters = 1000 + translation = robot_pose[:3] * meters_to_millimeters rotation_vector = robot_pose[3:] rotation = Rotation.from_rotvec(rotation_vector) transform = np.eye(4) diff --git a/source/applications/advanced/projector/README.md b/source/applications/advanced/projector/README.md new file mode 100644 index 00000000..d6f02795 --- /dev/null +++ b/source/applications/advanced/projector/README.md @@ -0,0 +1,3 @@ +# 2D Image Projection + +> **Tutorial:** Read the full [2D Image Projection](https://support.zivid.com/en/latest/camera/academy/camera/2d-image-projection.html) tutorial on Zivid Knowledge Base. diff --git a/source/applications/advanced/project_and_find_marker.py b/source/applications/advanced/projector/project_and_find_marker.py similarity index 100% rename from source/applications/advanced/project_and_find_marker.py rename to source/applications/advanced/projector/project_and_find_marker.py diff --git a/source/applications/advanced/read_project_and_capture_image.py b/source/applications/advanced/projector/read_project_and_capture_image.py similarity index 100% rename from source/applications/advanced/read_project_and_capture_image.py rename to source/applications/advanced/projector/read_project_and_capture_image.py diff --git a/source/applications/advanced/reproject_points.py b/source/applications/advanced/projector/reproject_points.py similarity index 100% rename from source/applications/advanced/reproject_points.py rename to source/applications/advanced/projector/reproject_points.py diff --git a/source/applications/advanced/roi_box_via_aruco_marker.py b/source/applications/advanced/roi/roi_box_via_aruco_marker.py similarity index 100% rename from source/applications/advanced/roi_box_via_aruco_marker.py rename to source/applications/advanced/roi/roi_box_via_aruco_marker.py diff --git a/source/applications/advanced/roi_box_via_checkerboard.py b/source/applications/advanced/roi/roi_box_via_checkerboard.py similarity index 100% rename from source/applications/advanced/roi_box_via_checkerboard.py rename to source/applications/advanced/roi/roi_box_via_checkerboard.py diff --git a/source/applications/advanced/stitch_continuously_rotating_object.py b/source/applications/advanced/stitching/stitch_continuously_rotating_object.py similarity index 100% rename from source/applications/advanced/stitch_continuously_rotating_object.py rename to source/applications/advanced/stitching/stitch_continuously_rotating_object.py diff --git a/source/applications/advanced/stitch_using_robot_mounted_camera.py b/source/applications/advanced/stitching/stitch_using_robot_mounted_camera.py similarity index 100% rename from source/applications/advanced/stitch_using_robot_mounted_camera.py rename to source/applications/advanced/stitching/stitch_using_robot_mounted_camera.py diff --git a/source/applications/advanced/stitch_via_local_point_cloud_registration.py b/source/applications/advanced/stitching/stitch_via_local_point_cloud_registration.py similarity index 100% rename from source/applications/advanced/stitch_via_local_point_cloud_registration.py rename to source/applications/advanced/stitching/stitch_via_local_point_cloud_registration.py diff --git a/source/applications/advanced/get_checkerboard_pose_from_zdf.py b/source/applications/advanced/transform/get_checkerboard_pose_from_zdf.py similarity index 99% rename from source/applications/advanced/get_checkerboard_pose_from_zdf.py rename to source/applications/advanced/transform/get_checkerboard_pose_from_zdf.py index 354fdc0a..8b465cf2 100644 --- a/source/applications/advanced/get_checkerboard_pose_from_zdf.py +++ b/source/applications/advanced/transform/get_checkerboard_pose_from_zdf.py @@ -23,7 +23,7 @@ f"however it might not be available for your Python version: {sys.version_info.major}.{sys.version_info.minor}. " "See https://pypi.org/project/open3d/ for supported versions." ) - sys.exit(1) + raise def _create_open3d_point_cloud(point_cloud: zivid.PointCloud) -> o3d.geometry.PointCloud: diff --git a/source/applications/advanced/transform_point_cloud_from_millimeters_to_meters.py b/source/applications/advanced/transform/transform_point_cloud_from_millimeters_to_meters.py similarity index 100% rename from source/applications/advanced/transform_point_cloud_from_millimeters_to_meters.py rename to source/applications/advanced/transform/transform_point_cloud_from_millimeters_to_meters.py diff --git a/source/applications/advanced/transform_point_cloud_via_aruco_marker.py b/source/applications/advanced/transform/transform_point_cloud_via_aruco_marker.py similarity index 100% rename from source/applications/advanced/transform_point_cloud_via_aruco_marker.py rename to source/applications/advanced/transform/transform_point_cloud_via_aruco_marker.py diff --git a/source/applications/advanced/transform_point_cloud_via_checkerboard.py b/source/applications/advanced/transform/transform_point_cloud_via_checkerboard.py similarity index 100% rename from source/applications/advanced/transform_point_cloud_via_checkerboard.py rename to source/applications/advanced/transform/transform_point_cloud_via_checkerboard.py diff --git a/source/applications/advanced/visualization/capture_vis_3d_in_loop.py b/source/applications/advanced/visualization/capture_vis_3d_in_loop.py new file mode 100644 index 00000000..37a48e15 --- /dev/null +++ b/source/applications/advanced/visualization/capture_vis_3d_in_loop.py @@ -0,0 +1,57 @@ +""" +Capture point clouds, with color, from the Zivid camera, and visualize them in a loop. + +""" + +import threading +import time + +import zivid + + +def _main() -> None: + app = zivid.Application() + + print("Connecting to camera") + camera = app.connect_camera() + + print("Creating default settings") + settings = zivid.Settings( + engine=zivid.Settings.Engine.phase, + acquisitions=[zivid.Settings.Acquisition()], + color=zivid.Settings2D(acquisitions=[zivid.Settings2D.Acquisition()]), + ) + + print("Capturing frame") + frame = camera.capture_2d_3d(settings) + + print("Setting up visualization") + visualizer_running = threading.Event() + + print("Visualizing point cloud") + with zivid.visualization.Visualizer() as visualizer: + visualizer.show(frame) + visualizer.reset_to_fit() + + def _capture_thread() -> None: + while visualizer_running.is_set(): + new_frame = camera.capture_2d_3d(settings) + if visualizer_running.is_set(): + visualizer.show(new_frame) + time.sleep(0.01) + + capture_thread = threading.Thread(target=_capture_thread) + + print("Running visualizer. Blocking until window closes.") + visualizer_running.set() + capture_thread.start() + visualizer.run() + visualizer_running.clear() + + capture_thread.join() + + print("Visualizer closed") + + +if __name__ == "__main__": + _main() diff --git a/source/applications/advanced/visualization/capture_vis_3d_in_loop_with_keypress_exit.py b/source/applications/advanced/visualization/capture_vis_3d_in_loop_with_keypress_exit.py new file mode 100644 index 00000000..9414d3be --- /dev/null +++ b/source/applications/advanced/visualization/capture_vis_3d_in_loop_with_keypress_exit.py @@ -0,0 +1,105 @@ +""" +Capture point clouds, with color, from the Zivid camera, and visualize them in a loop. Press 'q' to exit. + +""" + +import sys +import threading +import time + +import zivid + +if sys.platform == "win32": + import msvcrt +else: + import select + import termios + import tty + + +def _get_key_non_blocking() -> str: + if sys.platform == "win32": + if msvcrt.kbhit(): + return msvcrt.getch().decode(errors="ignore") + return "" + readable = select.select([sys.stdin], [], [], 0)[0] + if readable: + return sys.stdin.read(1) + return "" + + +def _main() -> None: + app = zivid.Application() + + print("Connecting to camera") + camera = app.connect_camera() + + print("Creating default settings") + settings = zivid.Settings( + engine=zivid.Settings.Engine.phase, + acquisitions=[zivid.Settings.Acquisition()], + color=zivid.Settings2D(acquisitions=[zivid.Settings2D.Acquisition()]), + ) + + print("Capturing frame") + frame = camera.capture_2d_3d(settings) + + print("Setting up visualization") + visualizer_running = threading.Event() + accept_end = threading.Event() + accept_end.set() + quit_requested = threading.Event() + + use_raw_terminal = sys.platform != "win32" and sys.stdin.isatty() + if use_raw_terminal: + old_terminal_settings = termios.tcgetattr(sys.stdin) + tty.setcbreak(sys.stdin.fileno()) + try: + print("Visualizing point cloud") + with zivid.visualization.Visualizer() as visualizer: + visualizer.show(frame) + visualizer.reset_to_fit() + + def _capture_and_keypress_thread() -> None: + print("Press 'q' in the terminal to quit") + while not quit_requested.is_set(): + if not visualizer_running.wait(timeout=0.01): + continue + key = _get_key_non_blocking() + if key == "q": + print("Closing application because user pressed 'q'") + quit_requested.set() + visualizer.close() + else: + accept_end.clear() + new_frame = camera.capture_2d_3d(settings) + if visualizer_running.is_set(): + visualizer.show(new_frame) + accept_end.set() + time.sleep(0.01) + + capture_thread = threading.Thread(target=_capture_and_keypress_thread) + capture_thread.start() + + print("Running visualizer. Blocking until window closes.") + while True: + visualizer_running.set() + visualizer.run() + visualizer_running.clear() + + if quit_requested.is_set(): + break + print("Visualizer window closed by user. It will be reopened if we're currently capturing.") + if accept_end.is_set(): + break + + capture_thread.join() + + print("Visualizer closed") + finally: + if use_raw_terminal: + termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_terminal_settings) + + +if __name__ == "__main__": + _main() diff --git a/source/applications/basic/visualization/capture_and_visualize_normals.py b/source/applications/basic/visualization/capture_and_visualize_normals.py index c7b0774f..8075a98f 100644 --- a/source/applications/basic/visualization/capture_and_visualize_normals.py +++ b/source/applications/basic/visualization/capture_and_visualize_normals.py @@ -17,7 +17,7 @@ f"however it might not be available for your Python version: {sys.version_info.major}.{sys.version_info.minor}. " "See https://pypi.org/project/open3d/ for supported versions." ) - sys.exit(1) + raise def _copy_to_open3d_point_cloud(xyz: np.ndarray, rgb: np.ndarray, normals: np.ndarray) -> o3d.geometry.PointCloud: diff --git a/source/applications/basic/visualization/capture_vis_3d.py b/source/applications/basic/visualization/capture_vis_3d.py index 53204ed8..7304bf40 100644 --- a/source/applications/basic/visualization/capture_vis_3d.py +++ b/source/applications/basic/visualization/capture_vis_3d.py @@ -5,7 +5,6 @@ import zivid import zivid.settings2d -from zividsamples.display import display_pointcloud def _main() -> None: @@ -24,10 +23,14 @@ def _main() -> None: print("Capturing frame") frame = camera.capture_2d_3d(settings) - point_cloud = frame.point_cloud() - print("Visualizing point cloud") - display_pointcloud(point_cloud) + with zivid.visualization.Visualizer() as visualizer: + visualizer.set_window_title("Zivid Point Cloud Visualizer") + visualizer.colors_enabled = True + visualizer.axis_indicator_enabled = True + visualizer.show(frame) + visualizer.reset_to_fit() + visualizer.run() if __name__ == "__main__": diff --git a/source/applications/point_cloud_tutorial.md b/source/applications/point_cloud_tutorial.md deleted file mode 100644 index d01fc983..00000000 --- a/source/applications/point_cloud_tutorial.md +++ /dev/null @@ -1,379 +0,0 @@ -# Point Cloud Tutorial - -Note\! This tutorial has been generated for use on Github. For original -tutorial see: -[point\_cloud\_tutorial](https://support.zivid.com/en/latest/camera/academy/applications/point-cloud-tutorial.html) - - - ---- - -*Contents:* -[**Introduction**](#Introduction) | -[**Frame**](#Frame) | -[**Point**](#Point-Cloud) | -[**Downsample**](#Downsample) | -[**Voxel**](#Voxel-downsample) | -[**Normals**](#Normals) | -[**Visualize**](#Visualize) | -[**Conclusion**](#Conclusion) | -[**Version**](#Version-History) - ---- - - - -## Introduction - -This tutorial describes how to use Zivid SDK to work with [Point -Cloud](https://support.zivid.com/en/latest//camera/reference-articles/point-cloud-structure-and-output-formats.html) -data. - ------ - -Tip: - -> If you prefer watching a video, our webinar [Getting your point cloud -> ready for your -> application](https://www.zivid.com/webinars-page?wchannelid=ffpqbqc7sg&wmediaid=h66zph71vo) -> covers the Point Cloud Tutorial. - -**Prerequisites** - - - Install [Zivid - Software](https://support.zivid.com/en/latest//camera/getting-started/software-installation.html). - - For Python: install - [zivid-python](https://github.com/zivid/zivid-python#installation) - -## Frame - -The `zivid.Frame` contains the point cloud and color image (stored on -compute device memory) and the capture and camera information. Capture -^^^^^^^ - -When you capture with Zivid, you get a frame in return. The point cloud -is stored in the frame, and the frame is stored in the GPU memory. The -capture can contain color or not, depending of the method that you call. -For more information see this `table with different capture -modes`. - -### Capture with color - -If you want to capture a point cloud with color, you can use the -`Zivid::Camera::capture2D3D()` method. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L22-L23)) - -``` sourceCode python -frame = camera.capture_2d_3d(settings) -``` - -### Capture without color - -If you want to capture a point cloud without color, you can use the -`Zivid::Camera::capture3D()` method. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L124)) - -``` sourceCode python -frame_3d = camera.capture_3d(settings) -``` - -Check -[capture\_tutorial](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_tutorial.md) -for detailed instructions on how to capture. - -#### Load - -The frame can also be loaded from a ZDF file. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/basic/file_formats/read_iterate_zdf.py#L14-L17)) - -``` sourceCode python -data_file = get_sample_data_path() / "Zivid3D.zdf" -print(f"Reading point cloud from file: {data_file}") -frame = zivid.Frame(data_file) -``` - -## Point Cloud - -#### Get handle from Frame - -You can now get a handle to the point cloud data on the GPU. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/basic/file_formats/read_iterate_zdf.py#L20)) - -``` sourceCode python -point_cloud = frame.point_cloud() -``` - -Point cloud contains XYZ, RGB, and SNR, laid out on a 2D grid. - -For more info check out [Point Cloud -Structure](https://support.zivid.com/en/latest//camera/reference-articles/point-cloud-structure-and-output-formats.html). - -The function `zivid.frame.point_cloud()` does not perform any copying -from GPU memory. - ------ - -Note: - -`zivid.camera.capture_2d_3d()` and `zivid.camera.capture_3d()` methods -return at some moment in time after the camera completes capturing raw -images. The handle from `zivid.frame.point_cloud()` is available -instantly. However, the actual point cloud data becomes available only -after the processing on the GPU is finished. Any calls to data-copy -functions (section below) will block and wait for processing to finish -before proceeding with the requested copy operation. - -For detailed explanation, see [Point Cloud Capture -Process](https://support.zivid.com/en/latest/camera/academy/camera/point-cloud-capture-process.html). - ------ - -#### Unorganized point cloud - -It is possible to convert the organized point cloud to an unorganized -point cloud. While doing so, all NaN values are removed, and the point -cloud is flattened to a 1D array. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/multi_camera/stitch_by_transformation.py#L166)) - -``` sourceCode python -unorganized_point_cloud = frame.point_cloud().to_unorganized_point_cloud() -``` - -### Combining multiple unorganized point clouds - -The unorganized point cloud can be extended with additional unorganized -point clouds. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/multi_camera/stitch_by_transformation_from_zdf.py#L80)) - -``` sourceCode python -stitched_point_cloud.extend(current_point_cloud.transform(transformation_matrix)) -``` - -#### Copy from GPU to CPU memory - -You can now selectively copy data based on what is required. This is the -complete list of output data formats and how to copy them from the GPU. -Most of these APIs also applies to the unorganized point cloud. - -| Return type | Copy functions | Data per pixel | Total data | -| ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------------- | ---------- | -| `numpy.ndarray([height,width,3], dtype=float32)` | `PointCloud.copy_data("xyz")` | 12 bytes | 28 MB | -| `numpy.ndarray([height,width,3], dtype=float32)` | `PointCloud.copy_data("xyzw")` | 16 bytes | 37 MB | -| `numpy.ndarray([height,width], dtype=float32)` | `PointCloud.copy_data("z")` | 4 bytes | 9 MB | -| `numpy.ndarray([height,width,4], dtype=uint8)` | `PointCloud.copy_data("rgba")` | 4 bytes | 9 MB | -| `numpy.ndarray([height,width,4], dtype=uint8)` | `PointCloud.copy_data("bgra")` | 4 bytes | 9 MB | -| `numpy.ndarray([height,width,4], dtype=uint8)` | `PointCloud.copy_data("srgb")` | 4 bytes | 9 MB | -| `numpy.ndarray([height,width], dtype=float32)` | `PointCloud.copy_data("snr")` | 4 bytes | 9 MB | -| `numpy.ndarray([height,width], dtype=[('x', ' [Sampling -> (3D)](https://support.zivid.com/en/latest/camera/reference-articles/settings/sampling.html) -> describes a hardware-based sub-/downsample method that reduces the -> resolution of the point cloud during capture while also reducing the -> acquisition and capture time. - ------ - ------ - -Note: - -`Zivid::UnorganizedPointCloud` does not support downsampling, but it -does support voxel downsampling, see `voxel_downsample`. - ------ - -Downsampling can be done in-place, which modifies the current point -cloud. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/downsample.py#L59)) - -``` sourceCode python -point_cloud.downsample(zivid.PointCloud.Downsampling.by2x2) -``` - -It is also possible to get the downsampled point cloud as a new point -cloud instance, which does not alter the existing point cloud. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/downsample.py#L53)) - -``` sourceCode python -downsampled_point_cloud = point_cloud.downsampled(zivid.PointCloud.Downsampling.by2x2) -``` - -Zivid SDK supports the following downsampling rates: `by2x2`, `by3x3`, -and `by4x4`, with the possibility to perform downsampling multiple -times. - -## Voxel downsample - -`Zivid::UnorganizedPointCloud` supports voxel downsampling. The API -takes two arguments: - -1. `voxelSize` - the size of the voxel in millimeters. -2. `minPointsPerVoxel` - the minimum number of points per voxel to keep - it. - -Voxel downsampling subdivides 3D space into a grid of cubic voxels with -a given size. If a given voxel contains a number of points at or above -the given limit, all those source points are replaced with a single -point with the following properties: - - - Position (XYZ) is an SNR-weighted average of the source points' - positions, i.e. a high-confidence source point will have a greater - influence on the resulting position than a low-confidence one. - - Color (RGBA) is the average of the source points' colors. - - Signal-to-noise ratio (SNR) is sqrt(sum(SNR^2)) of the source - points' SNR values, i.e. the SNR of a new point will increase with - both the number and the confidence of the source points that were - used to compute its position. - -Using minPointsPerVoxel \> 1 is particularly useful for removing noise -and artifacts from unorganized point clouds that are a combination of -point clouds captured from different angles. This is because a given -artifact is most likely only present in one of the captures, and -minPointsPerVoxel can be used to only fill voxels that both captures -"agree" on. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/multi_camera/stitch_by_transformation.py#L172)) - -``` sourceCode python -final_point_cloud = stitched_point_cloud.voxel_downsampled(0.5, 1) -``` - -## Normals - -Some applications require computing -[normals](https://support.zivid.com/en/latest//camera/academy/applications/normals.html) -from the point cloud. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/advanced/capture_and_print_normals.py#L46-L47)) - -``` sourceCode python -print("Computing normals and copying them to CPU memory") -normals = point_cloud.copy_data("normals") -``` - -The Normals API computes the normal at each point in the point cloud and -copies normals from the GPU memory to the CPU memory. The result is a -matrix of normal vectors, one for each point in the input point cloud. -The size of normals is equal to the size of the input point cloud. - -## Visualize - -Having the frame allows you to visualize the point cloud. - -No source available for {language\_name}You can visualize the point -cloud from the point cloud object as well. - -No source available for {language\_name}For more information, check out -[Visualization -Tutorial](https://support.zivid.com/en/latest/camera/academy/applications/visualization-tutorial.html), -where we cover point cloud, color image, depth map, and normals -visualization, with implementations using third party libraries. - -## Conclusion - -This tutorial shows how to use the Zivid SDK to extract the point cloud, -manipulate it, transform it, and visualize it. - -## Version History - -| SDK | Changes | -| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 2.16.0 | Added support for `Zivid::UnorganizedPointCloud`. `transformed` is added as a function to `Zivid::PointCloud` (also available in `Zivid::UnorganizedPointCloud`). | -| 2.11.0 | Added support for SRGB color space. | -| 2.10.0 | [:orphan:](https://support.zivid.com/en/latest/camera/academy/camera/monochrome-capture.html) introduces a faster alternative to `downsample_point_cloud_tutorial`. | diff --git a/source/camera/basic/capture_tutorial.md b/source/camera/basic/capture_tutorial.md deleted file mode 100644 index 6fed5919..00000000 --- a/source/camera/basic/capture_tutorial.md +++ /dev/null @@ -1,493 +0,0 @@ -# Capture Tutorial - -Note\! This tutorial has been generated for use on Github. For original -tutorial see: -[capture\_tutorial](https://support.zivid.com/en/latest/camera/academy/camera/capture-tutorial.html) - - - ---- - -*Contents:* -[**Introduction**](#Introduction) | -[**Initialize**](#Initialize) | -[**Connect**](#Connect) | -[**Configure**](#Configure) | -[**Capture**](#Capture-2D3D) | -[**Save**](#Save) | -[**File**](#File-Camera) | -[**Multithreading**](#Multithreading) | -[**Conclusion**](#Conclusion) - ---- - - - -## Introduction - -This tutorial describes how to use the Zivid SDK to capture point clouds -and 2D images. - -**Prerequisites** - - - Install [Zivid - Software](https://support.zivid.com/en/latest//camera/getting-started/software-installation.html). - - For Python: install - [zivid-python](https://github.com/zivid/zivid-python#installation) - -## Initialize - -Calling any of the APIs in the Zivid SDK requires initializing the Zivid -application and keeping it alive while the program runs. - ------ - -Note: - -`Zivid::Application` must be kept alive while operating the Zivid -Camera. This is essentially the Zivid driver. - ------ - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L10)) - -``` sourceCode python -app = zivid.Application() -``` - -## Connect - -Now we can connect to the camera. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L13)) - -``` sourceCode python -camera = app.connect_camera() -``` - -### Specific Camera - -Sometimes multiple cameras are connected to the same computer, but it -might be necessary to work with a specific camera in the code. This can -be done by providing the serial number of the wanted camera. - -``` sourceCode python -camera = app.connect_camera(serial_number="2020C0DE") -``` - ------ - -Note: - -> The serial number of your camera is shown in the Zivid Studio. - ------ - -You may also list all cameras connected to the computer, and view their -serial numbers through - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/info_util_other/camera_info.py#L16-L19)) - -``` sourceCode python -cameras = app.cameras() -for camera in cameras: - print(f"Camera Info: {camera.info}") - print(f"Camera State: {camera.state}") -``` - -## Configure - -As with all cameras there are settings that can be configured. - -### Presets - -The recommendation is to use -[Presets](https://support.zivid.com/en/latest/camera/reference-articles/presets-settings.html) -available in Zivid Studio and as .yml files (see below). Presets are -designed to work well for most cases right away, making them a great -starting point. If needed, you can easily fine-tune the settings for -better results. You can edit the YAML files in any text editor or code -the settings manually. - -### Load - -You can export camera settings to .yml files from Zivid Studio. These -can be loaded and applied in the API. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_hdr_complete_settings.py#L264-L269)) - -``` sourceCode python -settings_file = "Settings.yml" -print(f"Loading settings from file: {settings_file}") -settings_from_file = zivid.Settings.load(settings_file) -``` - -### Save - -You can also save settings to .yml file. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_hdr_complete_settings.py#L264-L266)) - -``` sourceCode python -settings_file = "Settings.yml" -print(f"Saving settings to file: {settings_file}") -settings.save(settings_file) -``` - -### Manual configuration - -Another option is to configure settings manually. For more information -about what each settings does, please see [Camera -Settings](https://support.zivid.com/en/latest/camera/reference-articles/camera-settings.html). -Then, the next step it's [Capturing High Quality Point -Clouds](https://support.zivid.com/en/latest/camera/academy/camera/capturing-high-quality-point-clouds.html) - -#### Single 2D and 3D Acquisition - Default settings - -We can create settings for a single acquisition capture. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L16-L19)) - -``` sourceCode python -settings = zivid.Settings( - acquisitions=[zivid.Settings.Acquisition()], - color=zivid.Settings2D(acquisitions=[zivid.Settings2D.Acquisition()]), -) -``` - -#### Multi Acquisition HDR - -We may also create settings with multiple acquisitions for an HDR -capture. - -([go to source]()) - -``` sourceCode python -settings = zivid.Settings() -for exposure in [1000, 10000]: - print(f"Adding acquisition with exposure time of {exposure} microseconds") - settings.acquisitions.append( - zivid.Settings.Acquisition(exposure_time=datetime.timedelta(microseconds=exposure)) - ) -``` - -#### Fully Configured Settings - -2D Settings, such as color balance and gamma, configured manually: - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_hdr_complete_settings.py#L172-L185)) - -``` sourceCode python -print("Configuring settings for capture:") -settings_2d = zivid.Settings2D() -settings_2d.sampling.color = zivid.Settings2D.Sampling.Color.rgb -settings_2d.sampling.pixel = zivid.Settings2D.Sampling.Pixel.all -settings_2d.sampling.interval.enabled = False -settings_2d.sampling.interval.duration = timedelta(microseconds=10000) - -settings_2d.processing.color.balance.red = 1.0 -settings_2d.processing.color.balance.blue = 1.0 -settings_2d.processing.color.balance.green = 1.0 -settings_2d.processing.color.gamma = 1.0 - -settings_2d.processing.color.experimental.mode = zivid.Settings2D.Processing.Color.Experimental.Mode.automatic -``` - -Manually configured 3D settings such as engine, region of interest, -filter settings and more: - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_hdr_complete_settings.py#L186-L237)) - -``` sourceCode python -settings = zivid.Settings() -settings.engine = zivid.Settings.Engine.stripe - -settings.region_of_interest.box.enabled = True -settings.region_of_interest.box.point_o = [1000, 1000, 1000] -settings.region_of_interest.box.point_a = [1000, -1000, 1000] -settings.region_of_interest.box.point_b = [-1000, 1000, 1000] -settings.region_of_interest.box.extents = [-1000, 1000] - -settings.region_of_interest.depth.enabled = True -settings.region_of_interest.depth.range = [200, 2000] - -settings.processing.filters.cluster.removal.enabled = True -settings.processing.filters.cluster.removal.max_neighbor_distance = 10 -settings.processing.filters.cluster.removal.min_area = 100 - -settings.processing.filters.hole.repair.enabled = True -settings.processing.filters.hole.repair.hole_size = 0.2 -settings.processing.filters.hole.repair.strictness = 1 - -settings.processing.filters.noise.removal.enabled = True -settings.processing.filters.noise.removal.threshold = 7.0 - -settings.processing.filters.noise.suppression.enabled = True -settings.processing.filters.noise.repair.enabled = True - -settings.processing.filters.outlier.removal.enabled = True -settings.processing.filters.outlier.removal.threshold = 5.0 - -settings.processing.filters.reflection.removal.enabled = True -settings.processing.filters.reflection.removal.mode = ( - zivid.Settings.Processing.Filters.Reflection.Removal.Mode.global_ -) - -settings.processing.filters.smoothing.gaussian.enabled = True -settings.processing.filters.smoothing.gaussian.sigma = 1.5 - -settings.processing.filters.experimental.contrast_distortion.correction.enabled = True -settings.processing.filters.experimental.contrast_distortion.correction.strength = 0.4 - -settings.processing.filters.experimental.contrast_distortion.removal.enabled = False -settings.processing.filters.experimental.contrast_distortion.removal.threshold = 0.5 - -settings.processing.resampling.mode = zivid.Settings.Processing.Resampling.Mode.upsample2x2 - -settings.diagnostics.enabled = False - -settings.color = settings_2d - -_set_sampling_pixel(settings, camera) -print(settings) -``` - -Different values per acquisition are also possible: - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_hdr_complete_settings.py#L239-L252)) - -``` sourceCode python -print("Configuring acquisition settings different for all HDR acquisitions") -exposure_values = _get_exposure_values(camera) -for aperture, gain, exposure_time, brightness in exposure_values: - settings.acquisitions.append( - zivid.Settings.Acquisition( - aperture=aperture, - exposure_time=exposure_time, - brightness=brightness, - gain=gain, - ) - ) -acquisition_settings_2d = make_settings_2d(camera).Acquisition() -settings.color.acquisitions.append(acquisition_settings_2d) -``` - -## Capture 2D3D - -Now we can capture a 2D and 3D image (point cloud with color). Whether -there is a single acquisition or multiple acquisitions (HDR) is given by -the number of `acquisitions` in `settings`. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L22-L23)) - -``` sourceCode python -frame = camera.capture_2d_3d(settings) -``` - -The `zivid.Frame` contains the point cloud, the color image, the -capture, and the camera information (all of which are stored on the -compute device memory). Capture 3D ^^^^^^^^^^ - -If we only want to capture 3D, the points cloud without color, we can do -so via the `capture3D` API. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L124)) - -``` sourceCode python -frame_3d = camera.capture_3d(settings) -``` - -### Capture 2D - -If we only want to capture a 2D image, which is faster than 3D, we can -do so via the `capture2D` API. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L93)) - -``` sourceCode python -frame_2d = camera.capture_2d(settings) -``` - -## Save - -We can now save our results. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L29-L31)) - -``` sourceCode python -data_file = "Frame.zdf" -frame.save(data_file) -``` - ------ - -Tip: - -> You can open and view `Frame.zdf` file in [Zivid -> Studio](https://support.zivid.com/en/latest//camera/getting-started/studio-guide.html). - -### Export - -In the next code example, the point cloud is exported to the .ply -format. For other exporting options, see [Point -Cloud](https://support.zivid.com/en/latest//camera/reference-articles/point-cloud-structure-and-output-formats.html) -for a list of supported formats. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L33-L35)) - -``` sourceCode python -data_file_ply = "PointCloud.ply" -frame.save(data_file_ply) -``` - -### Load - -Once saved, the frame can be loaded from a ZDF file. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/basic/file_formats/read_iterate_zdf.py#L14-L17)) - -``` sourceCode python -data_file = get_sample_data_path() / "Zivid3D.zdf" -print(f"Reading point cloud from file: {data_file}") -frame = zivid.Frame(data_file) -``` - -### Save 2D - -From a `capture2D()` you get a `Frame2D`. There are two color spaces -available for 2D images: linear RGB and sRGB. The `imageRGBA()` will -return an image in the linear RGB color space. If you append `_SRGB` to -the function name then the returned image will be in the sRGB color -space - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L98)) - -``` sourceCode python -image_rgba = frame_2d.image_rgba() -.. tab-item:: sRGB -``` - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L109)) - -``` sourceCode python -image_srgb = frame_2d.image_rgba_srgb() -``` - -Then, we can save the 2D image in linear RGB or sRGB color space. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L99-L101)) - -``` sourceCode python -image_file = "ImageRGBA_linear.png" -print(f"Saving 2D color image (sRGB color space) to file: {image_file}") -image_rgba.save(image_file) -.. tab-item:: sRGB -``` - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L110-L112)) - -``` sourceCode python -image_file = "ImageRGBA_sRGB.png" -print(f"Saving 2D color image (sRGB color space) to file: {image_file}") -image_srgb.save(image_file) -``` - -We can get 2D color image directly from the point cloud. This image will -have the same resolution as the point cloud and it will be in the sRGB -color space. - -([go to source]()) - -``` sourceCode python -point_cloud = frame.point_cloud() -image_2d_in_point_cloud_resolution = point_cloud.copy_image("bgra_srgb") -``` - -We can get the 2D color image from `Frame2D`, which is part of the -`Frame` object, obtained from `capture2D3D()`. This image will have the -resolution given by the 2D settings inside the 2D3D settings. - -([go to source]()) - -``` sourceCode python -image_2d = frame.frame_2d().image_bgra_srgb() -``` - -## File Camera - -A [file -camera](https://support.zivid.com/en/latest//camera/academy/camera/file-camera.html) -allows you to experiment with the SDK without access to a physical -camera. The file cameras can be found in [Sample -Data](https://support.zivid.com/en/latest/camera/api-reference/samples/sample-data.html) -where there are multiple file cameras to choose from. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_from_file_camera.py#L33)) - -``` sourceCode python -default=get_sample_data_path() / "FileCameraZivid2PlusMR60.zfc", -``` - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_from_file_camera.py#L48)) - -``` sourceCode python -camera = app.create_file_camera(file_camera) -``` - -The acquisition settings should be initialized like shown below, but you -are free to alter the processing settings. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_from_file_camera.py#L51-L64)) - -``` sourceCode python -settings = zivid.Settings() -settings.acquisitions.append(zivid.Settings.Acquisition()) -settings.processing.filters.smoothing.gaussian.enabled = True -settings.processing.filters.smoothing.gaussian.sigma = 1 -settings.processing.filters.reflection.removal.enabled = True -settings.processing.filters.reflection.removal.mode = "global" -settings_2d = zivid.Settings2D() -settings_2d.acquisitions.append(zivid.Settings2D.Acquisition()) -settings_2d.processing.color.balance.blue = 1.0 -settings_2d.processing.color.balance.green = 1.0 -settings_2d.processing.color.balance.red = 1.0 - -settings.color = settings_2d -``` - -You can read more about the file camera option in [File -Camera](https://support.zivid.com/en/latest/camera/academy/camera/file-camera.html). - -## Multithreading - -Operations on camera objects are thread-safe, but other operations like -listing cameras and connecting to cameras should be executed in -sequence. Find out more in -[capture\_tutorial](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_tutorial.md). - -## Conclusion - -This tutorial shows how to use the Zivid SDK to connect to, configure, -capture, and save from the Zivid camera. diff --git a/source/camera/basic/quick_capture_tutorial.md b/source/camera/basic/quick_capture_tutorial.md deleted file mode 100644 index 590819b7..00000000 --- a/source/camera/basic/quick_capture_tutorial.md +++ /dev/null @@ -1,124 +0,0 @@ -# Quick Capture Tutorial - -Note\! This tutorial has been generated for use on Github. For original -tutorial see: -[quick\_capture\_tutorial](https://support.zivid.com/en/latest/camera/getting-started/quick-capture-tutorial.html) - - - ---- - -*Contents:* -[**Introduction**](#Introduction) | -[**Initialize**](#Initialize) | -[**Connect**](#Connect) | -[**Configure**](#Configure) | -[**Capture**](#Capture) | -[**Save**](#Save) | -[**Utilize**](#Utilize) - ---- - - - -## Introduction - -This tutorial describes the most basic way to use the Zivid SDK to -capture point clouds. - -**Prerequisites** - - - Install [Zivid - Software](https://support.zivid.com/en/latest//camera/getting-started/software-installation.html). - - For Python: install - [zivid-python](https://github.com/zivid/zivid-python#installation) - -## Initialize - -Calling any of the APIs in the Zivid SDK requires initializing the Zivid -application and keeping it alive while the program runs. - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L10)) - -``` sourceCode python -app = zivid.Application() -``` - -## Connect - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L13)) - -``` sourceCode python -camera = app.connect_camera() -``` - -## Configure - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_with_settings_from_yml.py#L90)) - -``` sourceCode python -settings = zivid.Settings.load(user_options.settings_path) -``` - -## Capture - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L22-L23)) - -``` sourceCode python -frame = camera.capture_2d_3d(settings) -``` - -## Save - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L29-L31)) - -``` sourceCode python -data_file = "Frame.zdf" -frame.save(data_file) -.. tab-item:: Export -``` - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py#L33-L35)) - -``` sourceCode python -data_file_ply = "PointCloud.ply" -frame.save(data_file_ply) -``` - -For other exporting options, see [Point -Cloud](https://support.zivid.com/en/latest//camera/reference-articles/point-cloud-structure-and-output-formats.html) -for a list of supported formats - -## Utilize - -([go to -source](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/basic/file_formats/read_iterate_zdf.py#L20-L22)) - -``` sourceCode python -point_cloud = frame.point_cloud() -xyz = point_cloud.copy_data("xyz") -rgba = point_cloud.copy_data("rgba_srgb") -``` - ------ - -Tip: - -1. You can export Preset settings to YML from [Zivid - Studio](https://support.zivid.com/en/latest//camera/getting-started/studio-guide.html) - -\#. You can open and view `Frame.zdf` file in [Zivid -Studio](https://support.zivid.com/en/latest//camera/getting-started/studio-guide.html). -.. rubric:: Conclusion - -This tutorial shows the most basic way to use the Zivid SDK to connect -to, capture, and save from the Zivid camera. - -For a more in-depth tutorial check out the complete -[capture\_tutorial](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/basic/capture_tutorial.md). diff --git a/source/camera/info_util_other/automatic_network_configuration_for_cameras.py b/source/camera/info_util_other/network/automatic_network_configuration_for_cameras.py similarity index 100% rename from source/camera/info_util_other/automatic_network_configuration_for_cameras.py rename to source/camera/info_util_other/network/automatic_network_configuration_for_cameras.py diff --git a/source/camera/info_util_other/network_configuration.py b/source/camera/info_util_other/network/network_configuration.py similarity index 100% rename from source/camera/info_util_other/network_configuration.py rename to source/camera/info_util_other/network/network_configuration.py