|
| 1 | +######################################################################## |
| 2 | +# |
| 3 | +# Copyright (c) 2018, STEREOLABS. |
| 4 | +# |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 8 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 9 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 10 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 11 | +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 12 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 13 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 14 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 15 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 16 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 17 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 18 | +# |
| 19 | +######################################################################## |
| 20 | + |
| 21 | +""" |
| 22 | + Multi cameras sample showing how to open multiple ZED in one program |
| 23 | +""" |
| 24 | + |
| 25 | +import cv2 |
| 26 | +import pyzed.camera as zcam |
| 27 | +import pyzed.types as tp |
| 28 | +import pyzed.core as core |
| 29 | +import pyzed.defines as sl |
| 30 | + |
| 31 | + |
| 32 | +def main(): |
| 33 | + print("Running...") |
| 34 | + init = zcam.PyInitParameters() |
| 35 | + init.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720 |
| 36 | + init.camera_linux_id = 0 |
| 37 | + init.camera_fps = 30 # The framerate is lowered to avoid any USB3 bandwidth issues |
| 38 | + cam = zcam.PyZEDCamera() |
| 39 | + if not cam.is_opened(): |
| 40 | + print("Opening ZED Camera 1...") |
| 41 | + status = cam.open(init) |
| 42 | + if status != tp.PyERROR_CODE.PySUCCESS: |
| 43 | + print(repr(status)) |
| 44 | + exit() |
| 45 | + |
| 46 | + init.camera_linux_id = 1 # selection of the ZED ID |
| 47 | + cam2 = zcam.PyZEDCamera() |
| 48 | + if not cam2.is_opened(): |
| 49 | + print("Opening ZED Camera 2...") |
| 50 | + status = cam2.open(init) |
| 51 | + if status != tp.PyERROR_CODE.PySUCCESS: |
| 52 | + print(repr(status)) |
| 53 | + exit() |
| 54 | + |
| 55 | + runtime = zcam.PyRuntimeParameters() |
| 56 | + mat = core.PyMat() |
| 57 | + mat2 = core.PyMat() |
| 58 | + |
| 59 | + print_camera_information(cam) |
| 60 | + print_camera_information(cam2) |
| 61 | + |
| 62 | + key = '' |
| 63 | + while key != 113: # for 'q' key |
| 64 | + # The computation could also be done in a thread, one for each camera |
| 65 | + err = cam.grab(runtime) |
| 66 | + if err == tp.PyERROR_CODE.PySUCCESS: |
| 67 | + cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_LEFT) |
| 68 | + cv2.imshow("ZED 1", mat.get_data()) |
| 69 | + |
| 70 | + err = cam2.grab(runtime) |
| 71 | + if err == tp.PyERROR_CODE.PySUCCESS: |
| 72 | + cam2.retrieve_image(mat2, sl.PyVIEW.PyVIEW_LEFT) |
| 73 | + cv2.imshow("ZED 2", mat2.get_data()) |
| 74 | + |
| 75 | + key = cv2.waitKey(5) |
| 76 | + cv2.destroyAllWindows() |
| 77 | + |
| 78 | + cam.close() |
| 79 | + print("\nFINISH") |
| 80 | + |
| 81 | + |
| 82 | +def print_camera_information(cam): |
| 83 | + print("Resolution: {0}, {1}.".format( |
| 84 | + round(cam.get_resolution().width, 2), cam.get_resolution().height)) |
| 85 | + print("Camera FPS: {0}.".format(cam.get_camera_fps())) |
| 86 | + print("Firmware: {0}.".format( |
| 87 | + cam.get_camera_information().firmware_version)) |
| 88 | + print("Serial number: {0}.\n".format( |
| 89 | + cam.get_camera_information().serial_number)) |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == "__main__": |
| 93 | + main() |
0 commit comments