Skip to content

Commit c0b77f6

Browse files
authored
Merge pull request #199 from zivid/2025-04-07-update-python-samples
Samples: Update to SDK 2.15.0
2 parents 0551b1f + f99da25 commit c0b77f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+132
-119
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python samples
22

3-
This repository contains python code samples for Zivid SDK v2.14.2. For
3+
This repository contains python code samples for Zivid SDK v2.15.0. For
44
tested compatibility with earlier SDK versions, please check out
55
[accompanying
66
releases](https://github.com/zivid/zivid-python-samples/tree/master/../../releases).

continuous-integration/setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function install_www_deb {
2828
rm -r $TMP_DIR || exit
2929
}
3030

31-
install_www_deb "https://downloads.zivid.com/sdk/releases/2.14.2+1a322f18-1/u${VERSION_ID:0:2}/zivid_2.14.2+1a322f18-1_amd64.deb" || exit
32-
install_www_deb "https://downloads.zivid.com/sdk/releases/2.14.2+1a322f18-1/u${VERSION_ID:0:2}/zivid-genicam_2.14.2+1a322f18-1_amd64.deb" || exit
31+
install_www_deb "https://downloads.zivid.com/sdk/releases/2.15.0+5fcc365b-1/u${VERSION_ID:0:2}/zivid_2.15.0+5fcc365b-1_amd64.deb" || exit
32+
install_www_deb "https://downloads.zivid.com/sdk/releases/2.15.0+5fcc365b-1/u${VERSION_ID:0:2}/zivid-genicam_2.15.0+5fcc365b-1_amd64.deb" || exit
3333

3434
python3 -m pip install --upgrade pip || exit
3535
pushd "$ROOT_DIR" || exit

modules/zividsamples/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def display_pointcloud_with_downsampled_normals(
126126
downsampling: A valid Zivid downsampling factor to apply to normals
127127
128128
"""
129-
rgb = point_cloud.copy_data("rgba")[:, :, :3]
129+
rgb = point_cloud.copy_data("rgba_srgb")[:, :, :3]
130130
xyz = point_cloud.copy_data("xyz")
131131
point_cloud.downsample(downsampling)
132132
normals = point_cloud.copy_data("normals")

modules/zividsamples/gui/hand_eye_calibration_gui.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,9 @@ def process_capture(self, frame: zivid.Frame, rgba: NDArray[Shape["N, M, 4"], UI
244244
)
245245
)
246246
if not detection_result.valid():
247-
calibration_object_text = (
248-
"checkerboard"
249-
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard
250-
else "markers"
251-
)
252-
raise RuntimeError(f"Failed to detect {calibration_object_text}")
247+
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:
248+
raise RuntimeError(f"Failed to detect Checkerboard. {detection_result.status_description()}")
249+
raise RuntimeError("Failed to detect Markers.")
253250
rgb = rgba[:, :, :3].copy().astype(np.uint8)
254251
camera_pose = None
255252
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:

modules/zividsamples/gui/hand_eye_settings_tester.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,9 @@ def on_capture_button_clicked(self):
238238
)
239239
)
240240
if not detection_result.valid():
241-
calibration_object_text = (
242-
"checkerboard"
243-
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard
244-
else "markers"
245-
)
246-
raise RuntimeError(f"Failed to detect {calibration_object_text}")
241+
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:
242+
raise RuntimeError(f"Failed to detect Checkerboard. {detection_result.status_description()}")
243+
raise RuntimeError("Failed to detect Markers.")
247244
self.log_detection_result(detection_result)
248245
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:
249246
self.calibration_object_widget.set_checkerboard_image(rgba)
@@ -335,22 +332,23 @@ def log_detection_result(
335332
):
336333
assert self.settings is not None
337334
log_message = ""
338-
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:
339-
pose = detection_result.pose()
340-
checkerboard_pose_in_camera_frame = TransformationMatrix.from_matrix(np.asarray(pose.to_matrix()))
341-
translation = checkerboard_pose_in_camera_frame.translation
342-
log_message += (
343-
f"Calibration board: [{translation[0]:>8.2f}, {translation[1]:>8.2f}, {translation[2]:>8.2f}]"
344-
)
345-
else:
346-
detected_markers = detection_result.detected_markers()
347-
log_message += "Marker - " if len(detected_markers) < 2 else "Markers - "
348-
for marker in detected_markers:
349-
marker_pose_in_camera_frame = TransformationMatrix.from_matrix(np.asarray(marker.pose.to_matrix()))
350-
translation = marker_pose_in_camera_frame.translation
335+
if detection_result.valid():
336+
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:
337+
pose = detection_result.pose()
338+
checkerboard_pose_in_camera_frame = TransformationMatrix.from_matrix(np.asarray(pose.to_matrix()))
339+
translation = checkerboard_pose_in_camera_frame.translation
351340
log_message += (
352-
f"{marker.identifier:>3}: [{translation[0]:>8.2f}, {translation[1]:>8.2f}, {translation[2]:>8.2f}]"
341+
f"Calibration board: [{translation[0]:>8.2f}, {translation[1]:>8.2f}, {translation[2]:>8.2f}]"
353342
)
343+
else:
344+
detected_markers = detection_result.detected_markers()
345+
log_message += "Marker - " if len(detected_markers) < 2 else "Markers - "
346+
for marker in detected_markers:
347+
marker_pose_in_camera_frame = TransformationMatrix.from_matrix(np.asarray(marker.pose.to_matrix()))
348+
translation = marker_pose_in_camera_frame.translation
349+
log_message += f"{marker.identifier:>3}: [{translation[0]:>8.2f}, {translation[1]:>8.2f}, {translation[2]:>8.2f}]"
350+
else:
351+
log_message += f"Detection failed: {detection_result.status_description()}"
354352
log_message += f" (Engine: {self.settings.production.settings_2d3d.engine:>8}, Sampling: {self.settings.production.settings_2d3d.sampling.pixel:>20})"
355353
print(log_message)
356354

modules/zividsamples/gui/hand_eye_verification_gui.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def create_board_in_camera_frame(
4545

4646

4747
def extract_marker_points_in_camera_frame(
48-
markers: Dict[str, MarkerShape]
48+
markers: Dict[str, MarkerShape],
4949
) -> NDArray[Shape["N, 3"], Float32]: # type: ignore
5050
marker_points = np.zeros((len(markers) * 4, 3), dtype=np.float32)
5151
for index, marker in enumerate(markers.values()):
@@ -327,12 +327,9 @@ def process_capture(self, frame: zivid.Frame, rgba: NDArray[Shape["N, M, 4"], UI
327327
)
328328
)
329329
if not detection_result.valid():
330-
calibration_object_text = (
331-
"checkerboard"
332-
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard
333-
else "markers"
334-
)
335-
raise RuntimeError(f"Failed to detect {calibration_object_text}")
330+
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:
331+
raise RuntimeError(f"Failed to detect Checkerboard. {detection_result.status_description()}")
332+
raise RuntimeError("Failed to detect Markers.")
336333

337334
if self.hand_eye_configuration.calibration_object == CalibrationObject.Checkerboard:
338335
self.calibration_board_in_camera_frame_pose_widget.set_transformation_matrix(

modules/zividsamples/gui/pose_pair_selection_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def load_pose_pairs(self, calibration_object: CalibrationObject, marker_configur
240240
if camera_image_path.exists() and detection_result.valid():
241241
qimage_rgba = QImage(str(camera_image_path))
242242
else:
243-
rgba = camera_frame.point_cloud().copy_data("rgba")
243+
rgba = camera_frame.point_cloud().copy_data("rgba_srgb")
244244
rgb = rgba[:, :, :3].copy().astype(np.uint8)
245245
if calibration_object == CalibrationObject.Markers and detection_result.valid():
246246
rgba[:, :, :3] = self.cv2_handler.draw_detected_markers(

modules/zividsamples/gui/settings_selector.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,6 @@ def select_settings(camera: zivid.Camera) -> Optional[zivid.Settings]:
344344
return get_settings_from_file(camera) if settings is None else settings
345345

346346

347-
def _correct_pixel_mapping(camera: zivid.Camera, settings: zivid.Settings) -> PixelMapping:
348-
pixel_mapping = calibration.pixel_mapping(camera, settings)
349-
factor = 1
350-
if settings.color:
351-
if settings.color.sampling.pixel:
352-
sampling_pixel = settings.color.sampling.pixel
353-
factor = {"all": 1, "by2x2": 2, "by4x4": 4}.get(sampling_pixel, 1)
354-
col_stride = int(pixel_mapping.col_stride / factor)
355-
row_stride = int(pixel_mapping.row_stride / factor)
356-
return PixelMapping(row_stride, col_stride, pixel_mapping.row_offset, pixel_mapping.col_offset)
357-
358-
359347
def select_settings_for_hand_eye(camera: zivid.Camera) -> SettingsForHandEyeGUI:
360348
settings = select_settings(camera)
361349
engine, sampling_pixel = (
@@ -367,12 +355,12 @@ def select_settings_for_hand_eye(camera: zivid.Camera) -> SettingsForHandEyeGUI:
367355
return SettingsForHandEyeGUI(
368356
production=SettingsPixelMappingIntrinsics(
369357
settings_2d3d=settings_2d3d,
370-
pixel_mapping=_correct_pixel_mapping(camera, settings_2d3d),
358+
pixel_mapping=calibration.pixel_mapping(camera, settings_2d3d),
371359
intrinsics=calibration.intrinsics(camera, settings_2d3d),
372360
),
373361
hand_eye=SettingsPixelMappingIntrinsics(
374362
settings_2d3d=hand_eye_settings,
375-
pixel_mapping=_correct_pixel_mapping(camera, hand_eye_settings),
363+
pixel_mapping=calibration.pixel_mapping(camera, hand_eye_settings),
376364
intrinsics=calibration.intrinsics(camera, hand_eye_settings),
377365
),
378366
)

modules/zividsamples/gui/stitch_gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def update_stitched_view(self):
187187
point_cloud = capture_at_pose.camera_frame.point_cloud()
188188
capture_at_pose.save_as_ply()
189189
xyz = point_cloud.copy_data("xyz").reshape(-1, 3)
190-
rgb = point_cloud.copy_data("rgba")[:, :, :3].reshape(-1, 3)
190+
rgb = point_cloud.copy_data("rgba_srgb")[:, :, :3].reshape(-1, 3)
191191
valid_indices = np.logical_not(np.isnan(xyz).any(axis=1))
192192
xyz_total.append(xyz[valid_indices])
193193
rgb_total.append(rgb[valid_indices])

modules/zividsamples/white_balance_calibration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def white_balance_calibration(
103103
settings_2d.processing.color.balance.green = corrected_green_balance
104104
settings_2d.processing.color.balance.blue = corrected_blue_balance
105105

106-
rgba = camera.capture_2d(settings_2d).image_rgba().copy_data()
106+
rgba = camera.capture_2d(settings_2d).image_rgba_srgb().copy_data()
107107
mean_color = compute_mean_rgb_from_mask(rgba[:, :, 0:3], mask)
108108

109109
mean_red, mean_green, mean_blue = mean_color[0], mean_color[1], mean_color[2]

0 commit comments

Comments
 (0)