Skip to content

Commit

Permalink
Update Python samples to SDK 2.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisasc committed Jun 17, 2022
1 parent 8a413c6 commit 3b3142e
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 77 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
ignore =
### Disabled because of conflicts with black
E203, # whitespace before ':'
E231, # missing whitespace after ','
### Disabled because it makes the samples look worse
F841, # local variable is assigned but not never used
W503, # line break before binary operator

# Covered better by pylint
max-line-length = 9999
exclude =
# No need to traverse our git directory
.git,
# No need to traverse 3rd party libraries
source/applications/advanced/hand_eye_calibration/ur_hand_eye_calibration/3rdParty/*
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ releases](https://github.com/zivid/zivid-python-samples/tree/master/../../releas
[**License**](#License)

---



## Samples list

There are two main categories of samples: **Camera** and
Expand All @@ -28,13 +31,13 @@ image or other data from the camera. These samples shows how the data
from the camera can be used.

- **camera**
- **basic** ([quick tutorial](source/camera/basic/quick_capture_tutorial.md) / [complete tutorial](source/camera/basic/capture_tutorial.md))
- **basic**
- [capture](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture.py) - Capture point clouds, with color, from the Zivid camera.
- [capture\_2d](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_2d.py) - Capture 2D images from 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, from the Zivid file
camera.
- [capture\_assistant](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_assistant.py) - Use Capture Assistant to capture point clouds, with color,
from 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, from the Zivid file
camera.
- [capture\_hdr](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/basic/capture_hdr.py) - Capture point clouds, with color, from the Zivid 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.
Expand All @@ -47,49 +50,52 @@ 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**
- [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 settings from YML file and diagnostics enabled.
- [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).
- [print\_version\_info](https://github.com/zivid/zivid-python-samples/tree/master//source/camera/info_util_other/print_version_info.py) - Print version information for Python, zivid-python and
Zivid SDK, then list cameras and print camera info for each
connected 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 settings from YML file and diagnostics enabled.
- [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.
- **applications**
- **basic**
- **visualization**
- [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.
- [capture\_hdr\_vis\_normals](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/basic/visualization/capture_hdr_vis_normals.py) - Capture Zivid point clouds, compute normals and
convert to color map and display.
- [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.
- [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**
- [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.
- [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 (.ply, .csv, .txt, .png, .jpg, .bmp,
.tiff).
- [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**
- [downsample](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/downsample.py) - Downsample point cloud from a ZDF file.
- [color\_balance](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/color_balance.py) - Balance color of 2D image.
- [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.
- [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.
- [mask\_point\_cloud](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/mask_point_cloud.py) - Read point cloud data from a ZDF file, apply a binary
mask, and visualize it.
- [color\_balance](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/color_balance.py) - Balance color of 2D image.
- [gamma\_correction](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/gamma_correction.py) - Capture 2D image with gamma correction.
- **hand\_eye\_calibration**
- [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.
- [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).
- [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 frame to robot base frame using 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).
- **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.
- **sample\_utils**
- [paths](https://github.com/zivid/zivid-python-samples/tree/master//source/sample_utils/paths.py) - Get relevant paths for Zivid Samples.
- [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.

## Installation

Expand Down
42 changes: 42 additions & 0 deletions source/applications/advanced/hand_eye_calibration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Hand Eye Calibration

To fully understand Hand-Eye Calibration, please see the [tutorial][Tutorial-url] in our Knowledge Base.

-----------------
The following applications creates a **Transformation Matrix** from data provided by a user

[HandEyeCalibration][HandEyeCalibration-url]:

* Application which walks through the collection of calibration poses
1. Provide robot pose to application (manual entry)
2. Application takes an image of the calibration object, and calculates pose
3. Move robot to new position, enter command to Add Pose
4. Repeat i.-iii. until 10-20 pose pairs are collected
5. Enter command to perform calibration and return a **Transformation Matrix**

[ZividHandEyeCalibration][ZividHandEyeCalibration-url]

* [CLI application][CLI application-url] which takes a collection of pose pairs (e.g. output of steps i.-iii. in [HandEyeCalibration][HandEyeCalibration-url]) and returns a **Transformation Matrix**. This application comes with the Windows installer and is part of the tools deb for Ubuntu.

-----------------
The following applications assume that a **Transformation Matrix** has been found

[**UtilizeHandEyeCalibration**][UtilizeHandEyeCalibration-url]:

* Shows how to transform position and rotation (pose) in Camera co-ordinate system to Robot co-ordinate system.
* Example use case - "Bin Picking":
1. Acquire point cloud of objects to pick with Zivid camera
2. Find optimal picking pose for object and **transform to robot co-ordinate system**
3. Use transformed pose to calculate robot path and execute pick

[**PoseConversions**][PoseConversions-url]:

* Zivid primarily operate with a (4x4) Transformation Matrix (Rotation Matrix + Translation Vector). This example shows how to use Eigen to convert to and from:
* AxisAngle, Rotation Vector, Roll-Pitch-Yaw, Quaternion

[HandEyeCalibration-url]: hand_eye_calibration.py
[UtilizeHandEyeCalibration-url]: utilize_hand_eye_calibration.py
[ZividHandEyeCalibration-url]: https://support.zivid.com/latest/academy/applications/hand-eye/hand-eye-calibration-process.html
[Tutorial-url]: https://support.zivid.com/latest/academy/applications/hand-eye.html
[PoseConversions-url]: pose_conversions.py
[CLI application-url]: https://support.zivid.com/latest/academy/applications/hand-eye/zivid_CLI_tool_for_hand_eye_calibration.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@
import zivid


def _acquire_checkerboard_frame(camera):
"""Acquire checkerboard frame.
Args:
camera: Zivid camera
Returns:
frame: Zivid frame
"""
print("Configuring settings")
settings = zivid.Settings()
settings.acquisitions.append(zivid.Settings.Acquisition())
settings.acquisitions[0].aperture = 8.0
settings.acquisitions[0].exposure_time = datetime.timedelta(microseconds=20000)
settings.processing.filters.smoothing.gaussian.enabled = True
print("Capturing checkerboard image")
return camera.capture(settings)


def _enter_robot_pose(index):
"""Robot pose user input.
Expand Down Expand Up @@ -71,6 +51,25 @@ def _perform_calibration(hand_eye_input):
print(f"Unknown calibration type: '{calibration_type}'")


def _assisted_capture(camera):
"""Acquire frame with capture assistant.
Args:
camera: Zivid camera
Returns:
frame: Zivid frame
"""

suggest_settings_parameters = zivid.capture_assistant.SuggestSettingsParameters(
max_capture_time=datetime.timedelta(milliseconds=800),
ambient_light_frequency=zivid.capture_assistant.SuggestSettingsParameters.AmbientLightFrequency.none,
)
settings = zivid.capture_assistant.suggest_settings(camera, suggest_settings_parameters)
return camera.capture(settings)


def _main():
app = zivid.Application()

Expand All @@ -87,7 +86,7 @@ def _main():
try:
robot_pose = _enter_robot_pose(current_pose_id)

frame = _acquire_checkerboard_frame(camera)
frame = _assisted_capture(camera)

print("Detecting checkerboard in point cloud")
detection_result = zivid.calibration.detect_feature_points(frame.point_cloud())
Expand Down
Loading

0 comments on commit 3b3142e

Please sign in to comment.