Created
September 13, 2018 09:02
-
-
Save adujardin/14843cb6f6f1380ad5ca9b948f85c531 to your computer and use it in GitHub Desktop.
Python sample to open 2 ZED with the ZED SDK (https://github.com/stereolabs/zed-python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import pyzed.camera as zcam | |
import pyzed.types as tp | |
import pyzed.core as core | |
import pyzed.defines as sl | |
def main(): | |
print("Running...") | |
init = zcam.PyInitParameters() | |
init.camera_resolution = sl.PyRESOLUTION.PyRESOLUTION_HD720 | |
init.camera_linux_id = 0 | |
init.camera_fps = 30 | |
cam = zcam.PyZEDCamera() | |
if not cam.is_opened(): | |
print("Opening ZED Camera 1...") | |
status = cam.open(init) | |
if status != tp.PyERROR_CODE.PySUCCESS: | |
print(repr(status)) | |
exit() | |
init.camera_linux_id = 1 # Specify the camera index | |
cam2 = zcam.PyZEDCamera() | |
if not cam2.is_opened(): | |
print("Opening ZED Camera 2...") | |
status = cam2.open(init) | |
if status != tp.PyERROR_CODE.PySUCCESS: | |
print(repr(status)) | |
exit() | |
runtime = zcam.PyRuntimeParameters() | |
mat = core.PyMat() | |
mat2 = core.PyMat() | |
print_camera_information(cam) | |
print_camera_information(cam2) | |
key = '' | |
while key != 113: # for 'q' key | |
err = cam.grab(runtime) | |
if err == tp.PyERROR_CODE.PySUCCESS: | |
cam.retrieve_image(mat, sl.PyVIEW.PyVIEW_LEFT) | |
cv2.imshow("ZED 1", mat.get_data()) | |
err = cam2.grab(runtime) | |
if err == tp.PyERROR_CODE.PySUCCESS: | |
cam2.retrieve_image(mat2, sl.PyVIEW.PyVIEW_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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment