Skip to content

Commit 508f22b

Browse files
committed
Samples: Update zivid python samples
This PR adds the following samples: - Hand eye calibration samples based on RoboDK - Firmware updater - ROI box via checkerboard It also formats and standardize all samples.
1 parent d83c95d commit 508f22b

24 files changed

+704
-98
lines changed

.pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ disable=bad-continuation, ######## Disabled because of conflicts with bl
33
consider-using-enumerate, ######## Temporary disabled ########
44
import-error,
55
missing-docstring,
6-
duplicate-code
6+
no-member,
7+
duplicate-code,
8+
79
[TYPE CHECK]
810
generated-members=cv2.*
911

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ from the camera can be used.
6060
- [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.
6161
- [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,
6262
with settings from YML file and diagnostics enabled.
63+
- [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.
6364
- [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
6465
model).
6566
- [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
@@ -97,9 +98,13 @@ from the camera can be used.
9798
- [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.
9899
- [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
99100
mask, and visualize it.
101+
- [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
102+
to the Zivid Calibration Board.
100103
- **hand\_eye\_calibration**
101104
- [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
102105
+ Translation Vector).
106+
- [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
107+
using the Robodk interface.
103108
- [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
104109
camera frame to robot base frame using Hand-Eye
105110
calibration
@@ -111,43 +116,44 @@ from the camera can be used.
111116
- **sample\_utils**
112117
- [display](https://github.com/zivid/zivid-python-samples/tree/master//source/sample_utils/display.py) - Display relevant data for Zivid Samples.
113118
- [paths](https://github.com/zivid/zivid-python-samples/tree/master//source/sample_utils/paths.py) - Get relevant paths for Zivid Samples.
119+
- **applications**
120+
- **advanced**
121+
- **hand\_eye\_calibration**
122+
- **robodk\_hand\_eye\_calibration**
123+
- [robot\_tools](https://github.com/zivid/zivid-python-samples/tree/master//source/applications/advanced/hand_eye_calibration/robodk_hand_eye_calibration/robot_tools.py) - Robot Control Module
114124

115125
## Installation
116126

117127
1. [Install Zivid
118-
Software](https://support.zivid.com/latest//getting-started/software-installation.html)
128+
Software](https://support.zivid.com/latest//getting-started/software-installation.html).
119129

120-
2. [Install Zivid Python](https://github.com/zivid/zivid-python). Note:
121-
The recommended Python version for these samples is 3.8.
130+
2. [Install Zivid
131+
Python](https://github.com/zivid/zivid-python#installation).
122132

123133
3. [Download Zivid Sample
124-
Data](https://support.zivid.com/latest//api-reference/samples/sample-data.html)
125-
126-
4. \[Optional\] Launch the Python IDE of your choice. Read our
127-
instructions on [setting up
128-
Python](https://support.zivid.com/latest//api-reference/samples/python/setting-up-python.html).
134+
Data](https://support.zivid.com/latest//api-reference/samples/sample-data.html).
129135

130-
5. Install the runtime requirements using IDE or command line:
136+
4. Install the runtime requirements using IDE or command line:
131137

132138
``` sourceCode
133139
pip install -r requirements.txt
134140
```
135141
136-
6. Add the directory source to PYTHONPATH. Navigate to the root of the
142+
5. Add the directory source to PYTHONPATH. Navigate to the root of the
137143
repository and run:
138144
139145
> - PowerShell: `$env:PYTHONPATH=$env:PYTHONPATH + ";$PWD\source"`
140146
> - cmd: `set PYTHONPATH="$PYTHONPATH;$PWD\source"`
141147
> - bash: `export PYTHONPATH="$PYTHONPATH:$PWD/source"`
142148
143-
7. Open and run one of the samples.
149+
6. Open and run one of the samples.
144150
145151
## Support
146152
147153
For more information about the Zivid cameras, please visit our
148154
[Knowledge Base](https://support.zivid.com/latest). If you run into any
149155
issues please check out
150-
[Troubleshooting](https://support.zivid.com/latest/rst/support/troubleshooting.html).
156+
[Troubleshooting](https://support.zivid.com/latest/support/troubleshooting.html).
151157
152158
## License
153159

source/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.rdk filter=lfs diff=lfs merge=lfs -text

source/applications/advanced/color_balance.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import datetime
66
from dataclasses import dataclass
77

8-
import matplotlib.pyplot as plt
98
import numpy as np
109
import zivid
10+
from sample_utils.display import display_rgb
1111

1212

1313
@dataclass
@@ -27,22 +27,6 @@ class MeanColor:
2727
blue: np.float64
2828

2929

30-
def _display_rgb(rgb, title):
31-
"""Display RGB image.
32-
33-
Args:
34-
rgb: RGB image (HxWx3 darray)
35-
title: Image title
36-
37-
Returns None
38-
39-
"""
40-
plt.figure()
41-
plt.imshow(rgb)
42-
plt.title(title)
43-
plt.show(block=False)
44-
45-
4630
def _compute_mean_rgb(rgb, pixels):
4731
"""Compute mean RGB values.
4832
@@ -221,7 +205,7 @@ def _main():
221205
settings_2d = _auto_settings_configuration(camera)
222206

223207
rgba = camera.capture(settings_2d).image_rgba().copy_data()
224-
_display_rgb(rgba[:, :, 0:3], "RGB image before color balance")
208+
display_rgb(rgba[:, :, 0:3], title="RGB image before color balance", block=False)
225209

226210
[red_balance, green_balance, blue_balance] = _color_balance_calibration(camera, settings_2d)
227211

@@ -231,8 +215,7 @@ def _main():
231215
settings_2d.processing.color.balance.blue = blue_balance
232216
rgba_balanced = camera.capture(settings_2d).image_rgba().copy_data()
233217

234-
_display_rgb(rgba_balanced[:, :, 0:3], "RGB image after color balance")
235-
input("Press Enter to close...")
218+
display_rgb(rgba_balanced[:, :, 0:3], title="RGB image after color balance", block=True)
236219

237220

238221
if __name__ == "__main__":

source/applications/advanced/downsample.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ def _main():
4545

4646
display_pointcloud(xyz_donwsampled, rgba_downsampled[:, :, 0:3])
4747

48-
input("Press Enter to close...")
49-
5048

5149
if __name__ == "__main__":
5250
# If running the script from Spyder IDE, first run '%gui qt'

source/applications/advanced/get_checkerboard_pose_from_zdf.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _visualize_checkerboard_point_cloud_with_coordinate_system(point_cloud_open3
6565
coord_system_mesh = o3d.geometry.TriangleMesh.create_coordinate_frame(size=30)
6666
coord_system_mesh.transform(transform)
6767

68-
visualizer = o3d.visualization.Visualizer() # pylint: disable=no-member
68+
visualizer = o3d.visualization.Visualizer()
6969
visualizer.create_window()
7070
visualizer.add_geometry(point_cloud_open3d)
7171
visualizer.add_geometry(coord_system_mesh)
@@ -83,9 +83,7 @@ def _main():
8383
point_cloud = frame.point_cloud()
8484

8585
print("Detecting checkerboard and estimating its pose in camera frame")
86-
transform_camera_to_checkerboard = (
87-
zivid.calibration.detect_feature_points(point_cloud).pose().to_matrix()
88-
) # pylint: disable=no-member
86+
transform_camera_to_checkerboard = zivid.calibration.detect_feature_points(point_cloud).pose().to_matrix()
8987
print(f"Camera pose in checkerboard frame:\n{transform_camera_to_checkerboard}")
9088

9189
transform_file = "CameraToCheckerboardTransform.yaml"

source/applications/advanced/hand_eye_calibration/README.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
To fully understand Hand-Eye Calibration, please see the [tutorial][Tutorial-url] in our Knowledge Base.
44

55
-----------------
6-
The following applications creates a **Transformation Matrix** from data provided by a user
6+
The following applications create a **Transformation Matrix** from data provided by a user
77

8-
[HandEyeCalibration][HandEyeCalibration-url]:
8+
[**HandEyeCalibration**][HandEyeCalibration-url]
99

1010
* Application which walks through the collection of calibration poses
1111
1. Provide robot pose to application (manual entry)
@@ -14,9 +14,26 @@ The following applications creates a **Transformation Matrix** from data provide
1414
4. Repeat i.-iii. until 10-20 pose pairs are collected
1515
5. Enter command to perform calibration and return a **Transformation Matrix**
1616

17-
[ZividHandEyeCalibration][ZividHandEyeCalibration-url]
17+
[**ZividHandEyeCalibration**][ZividHandEyeCalibration-url]
1818

19-
* [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.
19+
* [CLI application][CLI application-url] which takes a collection of pose pairs (e.g. output of steps 1-3 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.
20+
21+
-----------------
22+
23+
There are two samples that show how to perform acquisition of the hand-eye calibration dataset in this repository.
24+
Both samples go through the process of acquiring the pose and point cloud pairs and then process them to return the resulting hand-eye **Transform Matrix**.
25+
26+
[**UniversalRobotsPerformHandEyeCalibration**][URhandeyecalibration-url]
27+
28+
* This sample is created to work specifically with the UR5e robot.
29+
* To follow the tutorial for this sample go to [**UR5e + Python Hand Eye Tutorial**][URHandEyeTutorial-url].
30+
31+
[**RoboDKHandEyeCalibration**][RobodkHandEyeCalibration-url]
32+
33+
The second sample uses RoboDK for robot control and can be used with any robot that the software supports.
34+
The list for the robots that they support can be found [**here**][robodk-robot-library-url].
35+
Poses must be added by the user to their personal rdk file.
36+
To find best pose practice follow the instructions provided on the Zivid knowledge base for the [hand-eye calibration process][ZividHandEyeCalibration-url].
2037

2138
-----------------
2239
The following applications assume that a **Transformation Matrix** has been found
@@ -31,27 +48,31 @@ The following applications assume that a **Transformation Matrix** has been foun
3148

3249
[**PoseConversions**][PoseConversions-url]:
3350

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

3754
[**VerifyHandEyeWithVisualization**][VerifyHandEyeWithVisualization-url]:
3855

3956
Visually demonstrates the hand-eye calibration accuracy by overlapping transformed points clouds.
57+
4058
* The application asks the user for the hand-eye calibration type (manual entry).
41-
* After loading the hand-eye dataset (point clouds and robot poses) and the hand-eye output (transformation matrix), the application repeats the following process for all data pairs:
59+
* After loading the hand-eye dataset (point clouds and robot poses) and the hand-eye output (**transformation matrix**), the application repeats the following process for all data pairs:
4260
1. Transforms the point cloud
4361
2. Finds cartesian coordinates of the checkerboard centroid
4462
3. Creates a region of interest around the checkerboard and filters out points outside the region of interest
4563
4. Saves the point cloud to a PLY file
4664
5. Appends the point cloud to a list (overlapped point clouds)
47-
This application ends by displaying all point clouds from the list.
48-
4965

66+
This application ends by displaying all point clouds from the list.
5067

5168
[HandEyeCalibration-url]: hand_eye_calibration.py
5269
[UtilizeHandEyeCalibration-url]: utilize_hand_eye_calibration.py
5370
[VerifyHandEyeWithVisualization-url]: verify_hand_eye_with_visualization.py
5471
[ZividHandEyeCalibration-url]: https://support.zivid.com/latest/academy/applications/hand-eye/hand-eye-calibration-process.html
5572
[Tutorial-url]: https://support.zivid.com/latest/academy/applications/hand-eye.html
5673
[PoseConversions-url]: pose_conversions.py
57-
[CLI application-url]: https://support.zivid.com/latest/academy/applications/hand-eye/zivid_CLI_tool_for_hand_eye_calibration.html
74+
[CLI application-url]: https://support.zivid.com/latest/academy/applications/hand-eye/zivid_CLI_tool_for_hand_eye_calibration.html
75+
[URhandeyecalibration-url]: ur_hand_eye_calibration/universal_robots_perform_hand_eye_calibration.py
76+
[URHandEyeTutorial-url]: https://support.zivid.com/en/latest/academy/applications/hand-eye/ur5-robot-+-python-generate-dataset-and-perform-hand-eye-calibration.html
77+
[RobodkHandEyeCalibration-url]: robodk_hand_eye_calibration/robodk_hand_eye_calibration.py
78+
[robodk-robot-library-url]: https://robodk.com/supported-robots
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Hand Eye Calibration with RoboDK
2+
3+
Hand-eye calibration is a necessity for any picking scenario that involves a camera and a robot.
4+
This sample offers an easy and adaptable method to perform hand eye with a variety of robots that are supported in RoboDK.
5+
6+
For more on Hand-Eye Calibration, please see the [tutorial](https://support.zivid.com/latest/academy/applications/hand-eye.html) in our Knowledge Base.
7+
8+
If you need help with the sample, visit our Knowledge Base article [here](help.zivid.com) (To be updated)
9+
10+
This sample is made and modeled with a Universal Robots UR5e robot.
11+
It is a requirement that you make your own poses that suit your environment.
12+
If you have a different robot from a UR5e you will need to load in the corresponding robot to your rdk file.
13+
14+
## Installation
15+
16+
1. [Install Zivid Software](https://support.zivid.com/latest//getting-started/software-installation.html)
17+
18+
2. [Install Zivid Python](https://github.com/zivid/zivid-python).
19+
Note: The recommended Python version for these samples is 3.8.
20+
21+
3. [Install RoboDK](https://robodk.com/download)
22+
23+
4. [Install RoboDK python](https://pypi.org/project/robodk/)
24+
25+
Other requirements can be installed using the following command:
26+
27+
pip install -r requirements.txt
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:0486fba0e401503c3bdb4214b63d6f0e3c8d1ce0bcc276532f7a75bff18b73e7
3+
size 4571581
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
robodk
2+
typing

0 commit comments

Comments
 (0)