forked from stereolabs/zed-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_camera.py
90 lines (75 loc) · 2.91 KB
/
multi_camera.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
########################################################################
#
# Copyright (c) 2018, STEREOLABS.
#
# All rights reserved.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
########################################################################
"""
Multi cameras sample showing how to open multiple ZED in one program
"""
import cv2
import pyzed.sl as sl
def main():
print("Running...")
init = sl.InitParameters()
init.camera_resolution = sl.RESOLUTION.RESOLUTION_HD720
init.camera_linux_id = 0
init.camera_fps = 30 # The framerate is lowered to avoid any USB3 bandwidth issues
cam = sl.Camera()
if not cam.is_opened():
print("Opening ZED Camera 1...")
status = cam.open(init)
if status != sl.ERROR_CODE.SUCCESS:
print(repr(status))
exit()
init.camera_linux_id = 1 # selection of the ZED ID
cam2 = sl.Camera()
if not cam2.is_opened():
print("Opening ZED Camera 2...")
status = cam2.open(init)
if status != sl.ERROR_CODE.SUCCESS:
print(repr(status))
exit()
runtime = sl.RuntimeParameters()
mat = sl.Mat()
mat2 = sl.Mat()
print_camera_information(cam)
print_camera_information(cam2)
key = ''
while key != 113: # for 'q' key
# The computation could also be done in a thread, one for each camera
err = cam.grab(runtime)
if err == sl.ERROR_CODE.SUCCESS:
cam.retrieve_image(mat, sl.VIEW.VIEW_LEFT)
cv2.imshow("ZED 1", mat.get_data())
err = cam2.grab(runtime)
if err == sl.ERROR_CODE.SUCCESS:
cam2.retrieve_image(mat2, sl.VIEW.VIEW_LEFT)
cv2.imshow("ZED 2", mat2.get_data())
key = cv2.waitKey(5)
cv2.destroyAllWindows()
cam.close()
print("\nFINISH")
def print_camera_information(cam):
print("Resolution: {0}, {1}.".format(
round(cam.get_resolution().width, 2), cam.get_resolution().height))
print("Camera FPS: {0}.".format(cam.get_camera_fps()))
print("Firmware: {0}.".format(
cam.get_camera_information().firmware_version))
print("Serial number: {0}.\n".format(
cam.get_camera_information().serial_number))
if __name__ == "__main__":
main()