Skip to content

Commit 66e2a49

Browse files
committed
Samples: Let connect sample take camera info as arguments
The connect sample now accepts --serial, --ip and --hostname arguments, so you can pass in your camera's IDs on the command line instead of editing the file by hand. Fixes: - Pose pair selection now uses the updated calibration board detection method when working with a checkerboard. - The live 3D visualization sample now exits cleanly as soon as the window is closed or 'q' is pressed, instead of reopening the visualization window.
1 parent bd174a2 commit 66e2a49

3 files changed

Lines changed: 36 additions & 39 deletions

File tree

modules/zividsamples/gui/calibration/pose_pair_selection_widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def run(self) -> None:
231231
break
232232

233233
detection_result = (
234-
zivid.calibration.detect_feature_points(camera_frame.point_cloud())
234+
zivid.calibration.detect_calibration_board(camera_frame)
235235
if self._calibration_object == CalibrationObject.Checkerboard
236236
else zivid.calibration.detect_markers(
237237
camera_frame, self._marker_configuration.id_list, self._marker_configuration.dictionary
@@ -303,7 +303,7 @@ def run(self) -> None:
303303
break
304304

305305
detection_result = (
306-
zivid.calibration.detect_feature_points(camera_frame.point_cloud())
306+
zivid.calibration.detect_calibration_board(camera_frame)
307307
if self._calibration_object == CalibrationObject.Checkerboard
308308
else zivid.calibration.detect_markers(
309309
camera_frame, self._marker_configuration.id_list, self._marker_configuration.dictionary

source/applications/advanced/visualization/capture_vis_3d_in_loop_with_keypress_exit.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ def _main() -> None:
4646

4747
print("Setting up visualization")
4848
visualizer_running = threading.Event()
49-
accept_end = threading.Event()
50-
accept_end.set()
51-
quit_requested = threading.Event()
49+
visualizer_running.set()
5250

5351
use_raw_terminal = sys.platform != "win32" and sys.stdin.isatty()
5452
if use_raw_terminal:
@@ -62,36 +60,22 @@ def _main() -> None:
6260

6361
def _capture_and_keypress_thread() -> None:
6462
print("Press 'q' in the terminal to quit")
65-
while not quit_requested.is_set():
66-
if not visualizer_running.wait(timeout=0.01):
67-
continue
68-
key = _get_key_non_blocking()
69-
if key == "q":
63+
while visualizer_running.is_set():
64+
if _get_key_non_blocking() == "q":
7065
print("Closing application because user pressed 'q'")
71-
quit_requested.set()
7266
visualizer.close()
73-
else:
74-
accept_end.clear()
75-
new_frame = camera.capture_2d_3d(settings)
76-
if visualizer_running.is_set():
77-
visualizer.show(new_frame)
78-
accept_end.set()
67+
break
68+
new_frame = camera.capture_2d_3d(settings)
69+
if visualizer_running.is_set():
70+
visualizer.show(new_frame)
7971
time.sleep(0.01)
8072

8173
capture_thread = threading.Thread(target=_capture_and_keypress_thread)
8274
capture_thread.start()
8375

84-
print("Running visualizer. Blocking until window closes.")
85-
while True:
86-
visualizer_running.set()
87-
visualizer.run()
88-
visualizer_running.clear()
89-
90-
if quit_requested.is_set():
91-
break
92-
print("Visualizer window closed by user. It will be reopened if we're currently capturing.")
93-
if accept_end.is_set():
94-
break
76+
print("Running visualizer. Blocking until the window closes or 'q' is pressed.")
77+
visualizer.run()
78+
visualizer_running.clear()
9579

9680
capture_thread.join()
9781

source/camera/basic/connect.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
11
"""
22
Connect to a Zivid camera using the different available methods.
33
4-
Replace the IP address and serial number in the code with the ones of your camera.
4+
Replace the IP address, serial number and hostname in the code with the ones of your camera,
5+
or provide them with --serial, --ip and --hostname.
56
67
"""
78

9+
import argparse
10+
811
import zivid
912

1013

14+
def _options() -> argparse.Namespace:
15+
parser = argparse.ArgumentParser(description=__doc__)
16+
17+
parser.add_argument("--serial", required=False, type=str, default="2020C0DE", help="Serial number of the camera")
18+
parser.add_argument("--ip", required=False, type=str, default="172.28.60.5", help="IP address of the camera")
19+
parser.add_argument(
20+
"--hostname", required=False, type=str, default="zivid-2020C0DE.local", help="Hostname of the camera"
21+
)
22+
23+
return parser.parse_args()
24+
25+
1126
def _print_discovered_cameras(app: zivid.Application) -> None:
1227
print("Discovered cameras:")
1328
for camera in app.cameras():
1429
print(f"Serial number: {camera.info.serial_number}, IP address: {camera.state.network.ipv4.address}")
1530

1631

1732
def _main() -> None:
33+
user_options = _options()
34+
1835
app = zivid.Application()
1936

2037
_print_discovered_cameras(app)
2138

22-
print(
23-
"The serial number, IP address and hostname below are placeholders. Replace them with the ones of your camera."
24-
)
25-
2639
print("Connecting to the first available camera")
2740
camera = app.connect_camera()
2841
camera.disconnect()
2942

30-
print("Connecting to the camera with a specific serial number")
31-
camera = app.connect_camera(serial_number="2020C0DE")
43+
print(f"Connecting to the camera with serial number {user_options.serial}")
44+
camera = app.connect_camera(serial_number=user_options.serial)
3245
camera.disconnect()
3346

34-
print("Connecting to the camera at a specific IP address")
35-
camera = app.connect_camera(address=zivid.CameraAddress("172.28.60.5"))
47+
print(f"Connecting to the camera at IP address {user_options.ip}")
48+
camera = app.connect_camera(address=zivid.CameraAddress(user_options.ip))
3649
camera.disconnect()
3750

38-
print("Connecting to the camera at a specific hostname")
51+
print(f"Connecting to the camera at hostname {user_options.hostname}")
3952
# The default hostname format is "zivid-<serial-number>.local".
4053
# The hostname cannot be read or set through the SDK.
41-
camera = app.connect_camera(address=zivid.CameraAddress("zivid-2020C0DE.local"))
54+
camera = app.connect_camera(address=zivid.CameraAddress(user_options.hostname))
4255
camera.disconnect()
4356

4457
print("Connecting to all available cameras")

0 commit comments

Comments
 (0)