使用ZED相机踩坑记录(3)---采集左右相机图片

如题。
参考了这位前辈的代码,只是里面的几句因为版本不同而改了。
我用的是SDK 3.3

import cv2
import pyzed.sl as sl
import time


AUTO = True  # 自动拍照,或手动按s键拍照
INTERVAL = 2 # 自动拍照间隔

# camera_settings = sl.CAMERA_SETTINGS.CAMERA_SETTINGS_BRIGHTNESS
str_camera_settings = "BRIGHTNESS"
step_camera_settings = 1

counter = 0
utc = time.time()
pattern = (12, 8) # 棋盘格尺寸
folder = "/home/imu/ZED/zed-examples-master/left_right_image/" # 拍照文件目录


init = sl.InitParameters()
cam = sl.Camera()
status = cam.open(init)
step_camera_settings = 1
runtime = sl.RuntimeParameters()
mat1 = sl.Mat()
mat2 = sl.Mat()

def shot(pos, frame):
    global counter
    path = folder + pos + "_" + str(counter) + ".jpg"

    cv2.imwrite(path, frame)
    print("snapshot saved into: " + path)

key = ''
while True:
    err = cam.grab(runtime)
    cam.retrieve_image(mat1, sl.VIEW.LEFT)
    cam.retrieve_image(mat2, sl.VIEW.RIGHT)
    cv2.imshow("ZED-R", mat2.get_data())
    cv2.imshow("ZED-L", mat1.get_data())
    now = time.time()
    if AUTO and now - utc >= INTERVAL:
        shot("left", mat1.get_data())
        shot("right", mat2.get_data())
        counter += 1
        utc = now

    key = cv2.waitKey(1)
    if key == ord("q"):
        break


    # cv2.waitKey(5)
cv2.destroyWindow("ZED-R")
cv2.destroyWindow("ZED-L")


你可能感兴趣的:(ZED)