-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsample_capture_async.py
69 lines (55 loc) · 1.73 KB
/
sample_capture_async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Sample demonstrating how to capture with multiple cameras at the same time."""
import concurrent.futures
import datetime
import time
import zivid
def _capture_sync(cameras: list[zivid.Camera]) -> list[zivid.Frame]:
return [
camera.capture_3d(
zivid.Settings(
acquisitions=[
zivid.Settings.Acquisition(
exposure_time=datetime.timedelta(microseconds=100000)
)
]
)
)
for camera in cameras
]
def _capture_async(cameras: list[zivid.Camera]) -> list[zivid.Frame]:
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [
executor.submit(
camera.capture,
zivid.Settings(
acquisitions=[
zivid.Settings.Acquisition(
exposure_time=datetime.timedelta(microseconds=100000)
)
]
),
)
for camera in cameras
]
return [future.result() for future in futures]
def _main():
app = zivid.Application()
cameras = app.cameras()
for camera in cameras:
camera.connect()
start = time.monotonic()
_capture_async(cameras)
end = time.monotonic()
print(
f"Time taken to capture asynchronously from {len(cameras)} camera(s): {end - start} seconds"
)
start = time.monotonic()
_capture_sync(cameras)
end = time.monotonic()
print(
f"Time taken to capture synchronously from {len(cameras)} camera(s): {end - start} seconds"
)
for camera in cameras:
camera.disconnect()
if __name__ == "__main__":
_main()