Skip to content

Commit

Permalink
Samples: Automatic updates to public repository
Browse files Browse the repository at this point in the history
Remember to do the following:
    1. Ensure that modified/deleted/new files are correct
    2. Make this commit message relevant for the changes
    3. Force push
    4. Delete branch after PR is merged

If this commit is an update from one SDK version to another,
make sure to create a release tag for previous version.
  • Loading branch information
csu-bot-zivid committed Sep 13, 2024
1 parent dc99df8 commit 6fa70ec
Show file tree
Hide file tree
Showing 42 changed files with 590 additions and 1,600 deletions.
23 changes: 3 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python samples

This repository contains python code samples for Zivid SDK v2.13.1. For
This repository contains python code samples for Zivid SDK v2.11.1. For
tested compatibility with earlier SDK versions, please check out
[accompanying
releases](https://github.com/zivid/zivid-python-samples/tree/master/../../releases).
Expand Down Expand Up @@ -60,9 +60,6 @@ from the camera can be used.
- [capture\_hdr\_print\_normals](https://github.com/zivid/zivid-python-samples/tree/master/source/camera/advanced/capture_hdr_print_normals.py) - Capture Zivid point clouds, compute normals and print a
subset.
- **info\_util\_other**
- [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 set the IP addresses of any number of
cameras to be in the same subnet as the provided IP address
of the network interface.
- [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.
Expand All @@ -72,8 +69,6 @@ from the camera can be used.
- [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.
- [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.
- [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) - A basic warm-up method for a Zivid camera with specified
time and capture cycle.
- **maintenance**
Expand Down Expand Up @@ -119,23 +114,15 @@ from the camera can be used.
images to find the marker coordinates (2D and 3D).
- [reproject\_points](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/reproject_points.py) - Illuminate checkerboard (Zivid Calibration Board) corners
by getting checkerboard pose
- [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.
- [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**
- [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
camera frame to robot base 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
Expand All @@ -147,14 +134,10 @@ from the camera can be used.
- [display](https://github.com/zivid/zivid-python-samples/tree/master/source/sample_utils/display.py) - Display relevant data for Zivid Samples.
- [paths](https://github.com/zivid/zivid-python-samples/tree/master/source/sample_utils/paths.py) - Get relevant paths for Zivid Samples.
- [robodk\_tools](https://github.com/zivid/zivid-python-samples/tree/master/source/sample_utils/robodk_tools.py) - Robot Control Module
- [save\_load\_matrix](https://github.com/zivid/zivid-python-samples/tree/master/source/sample_utils/save_load_matrix.py) - Save and load Zivid 4x4 transformation matrices from and to
YAML files.
- [save\_load\_matrix](https://github.com/zivid/zivid-python-samples/tree/master/source/sample_utils/save_load_matrix.py) - try:
- [white\_balance\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/sample_utils/white_balance_calibration.py) - Balance color for 2D capture using white surface as reference.
- **applications**
- **advanced**
- **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.
- **verify\_hand\_eye\_calibration**
- [robodk\_verify\_hand\_eye\_calibration](https://github.com/zivid/zivid-python-samples/tree/master/source/applications/advanced/verify_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.
Expand Down
3 changes: 2 additions & 1 deletion continuous-integration/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function install_www_deb {
rm -r $TMP_DIR || exit
}

install_www_deb "https://downloads.zivid.com/sdk/releases/2.13.1+18e79e79-1/u${VERSION_ID:0:2}/zivid_2.13.1+18e79e79-1_amd64.deb" || exit
install_www_deb "https://downloads.zivid.com/sdk/releases/2.11.1+de9b5dae-1/u${VERSION_ID:0:2}/zivid-telicam-driver_3.0.1.1-3_amd64.deb" || exit
install_www_deb "https://downloads.zivid.com/sdk/releases/2.11.1+de9b5dae-1/u${VERSION_ID:0:2}/zivid_2.11.1+de9b5dae-1_amd64.deb" || exit

python3 -m pip install --upgrade pip || exit
python3 -m pip install --requirement "$ROOT_DIR/requirements.txt" || exit
Expand Down
17 changes: 17 additions & 0 deletions pyproject.constraints
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated file, do not edit @ 2023-11-20 07:12:00
#
# Command:
# python infrastructure/tools/launchers/dependency_updater.py --max-processes=30
#
# To update all Python requirements and constraints manually, you should run:
#
# python infrastructure/tools/launchers/dependency_updater.py
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --all-extras --extra-index-url=http://se-ci-elastic-server-1.localdomain:8081/artifactory/api/pypi/zivid-pypi/simple --output-file=sdk/samples/public/python/pyproject.constraints --strip-extras --trusted-host=se-ci-elastic-server-1.localdomain sdk/samples/public/python/pyproject.toml
#
--extra-index-url http://se-ci-elastic-server-1.localdomain:8081/artifactory/api/pypi/zivid-pypi/simple
--trusted-host se-ci-elastic-server-1.localdomain

62 changes: 52 additions & 10 deletions source/applications/advanced/auto_2d_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ def _find_white_mask_and_distance_to_checkerboard(camera: zivid.Camera) -> Tuple
"""
try:
settings = _capture_assistant_settings(camera)
frame = camera.capture(settings)
point_cloud = camera.capture(settings).point_cloud()

checkerboard_pose = zivid.calibration.detect_calibration_board(frame).pose().to_matrix()
checkerboard_pose = zivid.calibration.detect_feature_points(point_cloud).pose().to_matrix()
distance_to_checkerboard = checkerboard_pose[2, 3]

rgb = frame.point_cloud().copy_data("rgba")[:, :, :3]
rgb = point_cloud.copy_data("rgba")[:, :, :3]
white_squares_mask = find_white_mask_from_checkerboard(rgb)
except RuntimeError as exc:
raise RuntimeError("Unable to find checkerboard, make sure it is in view of the camera.") from exc
Expand All @@ -175,7 +175,37 @@ def _find_lowest_acceptable_fnum(camera: zivid.Camera, image_distance_near: floa
Lowest acceptable f-number that gives a focused image
"""
if camera.info.model == zivid.CameraInfo.Model.zividTwo:
if camera.info.model == zivid.CameraInfo.Model.zividOnePlusSmall:
focus_distance = 500
focal_length = 16
circle_of_confusion = 0.015
fnum_min = 1.4
if image_distance_near < 300 or image_distance_far > 1000:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
f"({image_distance_far:.2f}) is outside recommended working distance for camera [300, 1000]"
)
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusMedium:
focus_distance = 1000
focal_length = 16
circle_of_confusion = 0.015
fnum_min = 1.4
if image_distance_near < 500 or image_distance_far > 2000:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
f"({image_distance_far:.2f}) is outside recommended working distance for camera [500, 2000]"
)
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusLarge:
focus_distance = 1800
focal_length = 16
circle_of_confusion = 0.015
fnum_min = 1.4
if image_distance_near < 1200 or image_distance_far > 3000:
print(
f"WARNING: Closest imaging distance ({image_distance_near:.2f}) or farthest imaging distance"
f"({image_distance_far:.2f}) is outside recommended working distance for camera [1200, 3000]"
)
elif camera.info.model == zivid.CameraInfo.Model.zividTwo:
focus_distance = 700
focal_length = 8
circle_of_confusion = 0.015
Expand Down Expand Up @@ -258,7 +288,13 @@ def _find_lowest_exposure_time(camera: zivid.Camera) -> float:
Lowest exposure time [us] for given camera
"""
if camera.info.model == zivid.CameraInfo.Model.zividTwo:
if camera.info.model == zivid.CameraInfo.Model.zividOnePlusSmall:
exposure_time = 6500
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusMedium:
exposure_time = 6500
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusLarge:
exposure_time = 6500
elif camera.info.model == zivid.CameraInfo.Model.zividTwo:
exposure_time = 1677
elif camera.info.model == zivid.CameraInfo.Model.zividTwoL100:
exposure_time = 1677
Expand Down Expand Up @@ -287,7 +323,13 @@ def _find_max_brightness(camera: zivid.Camera) -> float:
Highest projector brightness value for given camera
"""
if camera.info.model == zivid.CameraInfo.Model.zividTwo:
if camera.info.model == zivid.CameraInfo.Model.zividOnePlusSmall:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusMedium:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividOnePlusLarge:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividTwo:
brightness = 1.8
elif camera.info.model == zivid.CameraInfo.Model.zividTwoL100:
brightness = 1.8
Expand Down Expand Up @@ -517,10 +559,10 @@ def _print_poor_pixel_distribution(rgb: np.ndarray) -> None:
black_and = np.sum(np.logical_and(np.logical_and(rgb[:, :, 0] == 0, rgb[:, :, 1] == 0), rgb[:, :, 2] == 0))

print("Distribution of saturated (255) and black (0) pixels with final settings:")
print(f"Saturated pixels (at least one channel): {saturated_or}\t ({100 * saturated_or / total_num_pixels:.2f}%)")
print(f"Saturated pixels (all channels):\t {saturated_and}\t ({100 * saturated_and / total_num_pixels:.2f}%)")
print(f"Black pixels (at least one channel):\t {black_or}\t ({100 * black_or / total_num_pixels:.2f}%)")
print(f"Black pixels (all channels):\t\t {black_and}\t ({100 * black_and / total_num_pixels:.2f}%)")
print(f"Saturated pixels (at least one channel): {saturated_or}\t ({100*saturated_or/total_num_pixels:.2f}%)")
print(f"Saturated pixels (all channels):\t {saturated_and}\t ({100*saturated_and/total_num_pixels:.2f}%)")
print(f"Black pixels (at least one channel):\t {black_or}\t ({100*black_or/total_num_pixels:.2f}%)")
print(f"Black pixels (all channels):\t\t {black_and}\t ({100*black_and/total_num_pixels:.2f}%)")


def _plot_image_with_histogram(rgb: np.ndarray, settings_2d: zivid.Settings2D) -> None:
Expand Down
14 changes: 7 additions & 7 deletions source/applications/advanced/get_checkerboard_pose_from_zdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def _create_open3d_point_cloud(point_cloud: zivid.PointCloud) -> o3d.geometry.Po
xyz = np.nan_to_num(xyz).reshape(-1, 3)
rgb = rgba[:, :, 0:3].reshape(-1, 3)

point_cloud_open3d = o3d.geometry.PointCloud(o3d.utility.Vector3dVector(xyz.astype(np.float64)))
point_cloud_open3d.colors = o3d.utility.Vector3dVector(rgb.astype(np.float64) / 255)
point_cloud_open3d = o3d.geometry.PointCloud(o3d.utility.Vector3dVector(xyz))
point_cloud_open3d.colors = o3d.utility.Vector3dVector(rgb / 255)

refined_point_cloud_open3d = o3d.geometry.PointCloud.remove_non_finite_points(
point_cloud_open3d, remove_nan=True, remove_infinite=True
Expand All @@ -50,7 +50,7 @@ def _visualize_checkerboard_point_cloud_with_coordinate_system(
Args:
point_cloud_open3d: An Open3d point cloud of a checkerboard
transform: Transformation matrix (4x4)
transform: Transformation matrix
"""
coord_system_mesh = o3d.geometry.TriangleMesh.create_coordinate_frame(size=30)
Expand All @@ -72,18 +72,18 @@ def _main() -> None:
point_cloud = frame.point_cloud()

print("Detecting checkerboard and estimating its pose in camera frame")
camera_to_checkerboard_transform = zivid.calibration.detect_calibration_board(frame).pose().to_matrix()
print(f"Camera pose in checkerboard frame:\n{camera_to_checkerboard_transform}")
transform_camera_to_checkerboard = zivid.calibration.detect_feature_points(point_cloud).pose().to_matrix()
print(f"Camera pose in checkerboard frame:\n{transform_camera_to_checkerboard}")

transform_file_name = "CameraToCheckerboardTransform.yaml"
print(f"Saving detected checkerboard pose to YAML file: {transform_file_name}")
transform_file_path = Path(__file__).parent / transform_file_name
assert_affine_matrix_and_save(camera_to_checkerboard_transform, transform_file_path)
assert_affine_matrix_and_save(transform_camera_to_checkerboard, transform_file_path)

print("Visualizing checkerboard with coordinate system")
checkerboard_point_cloud = _create_open3d_point_cloud(point_cloud)
_visualize_checkerboard_point_cloud_with_coordinate_system(
checkerboard_point_cloud, camera_to_checkerboard_transform
checkerboard_point_cloud, transform_camera_to_checkerboard
)


Expand Down
Loading

0 comments on commit 6fa70ec

Please sign in to comment.