ZED相机捕获图像

1.捕获图像

(1)将该py文件命名为“ZedCaptureImg.py”;
(2)在存放ZedCaptureImg.py文件夹中创建名为“Img”的文件夹;
(3)按“空格”保存图片,按“q”退出运行;

2.ZedCaptureImg.py

import cv2
import pyzed.sl as sl

# Global variable
camera_settings = sl.VIDEO_SETTINGS.BRIGHTNESS
str_camera_settings = "BRIGHTNESS"
step_camera_settings = 1
led_on = True
selection_rect = sl.Rect()
select_in_progress = False
origin_rect = (-1, -1)


def main():
    init = sl.InitParameters()
    cam = sl.Camera()
    status = cam.open(init)
    if status != sl.ERROR_CODE.SUCCESS:
        print("Camera Open : " + repr(status) + ". Exit program.")
        exit()

    runtime = sl.RuntimeParameters()
    mat = sl.Mat()
    win_name = "Camera Control"
    cv2.namedWindow(win_name)
    key = ''
    i = 0
    while key != 113:  # for 'q' key
        err = cam.grab(runtime)
        if err == sl.ERROR_CODE.SUCCESS:  # Check that a new image is successfully acquired
            # cam.retrieve_image(mat, sl.VIEW.LEFT)  # Retrieve left image
            cam.retrieve_image(mat,sl.VIEW.LEFT)  # Retrieve left image
            cvImage = mat.get_data()  # Convert sl.Mat to cv2.Mat
            cv2.imshow(win_name, cvImage)  # Display image
            if cv2.waitKey(1) & 0xFF == ord(' '):
                cv2.imwrite("./img/{}.jpg".format(i), cvImage)
                i = i+1
            print("i: ",i)
        else:
            print("Error during capture : ", err)
            break

        key = cv2.waitKey(5)

    cv2.destroyAllWindows()

    cam.close()



if __name__ == "__main__":
    main()

3. 参数

3.1 分辨率的选择

HD2K 2208*1242 (x2), available framerates: 15 fps.
HD1080 1920*1080 (x2), available framerates: 15, 30, 60 fps.
HD1200 1920*1200 (x2), available framerates: 15, 30, 60 fps.
HD720 1280*720 (x2), available framerates: 15, 30, 60 fps
SVGA 960*600 (x2), available framerates: 15, 30, 60, 120 fps.
VGA 672*376 (x2), available framerates: 15, 30, 60, 100 fps.
AUTO Select the resolution compatible with camera, on ZED X HD1200, HD720 otherwise

3.2 可捕获的视图

HD2K
LEFT
RIGHT
LEFT_GRAY
RIGHT_GRAY
LEFT_UNRECTIFIED
LEFT_UNRECTIFIED_GRAY
RIGHT_UNRECTIFIED_GRAY
SIDE_BY_SIDE
DEPTH
CONFIDENCE
NORMALS
DEPTH_RIGHT
NORMALS_RIGHT

3.3计算获得的视图

DISPARITY Disparity map. Each pixel contains 1 float. sl.MAT_TYPE.F32_C1
DEPTH Depth map, in sl.UNIT defined in sl.InitParameters. Each pixel contains 1 float. sl.MAT_TYPE.F32_C1
CONFIDENCE Certainty/confidence of the depth map. Each pixel contains 1 float. sl.MAT_TYPE.F32_C1
XYZ Point cloud. Each pixel contains 4 float (X, Y, Z, not used). sl.MAT_TYPE.F32_C4
XYZRGBA Colored point cloud. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the RGBA color. sl.MAT_TYPE.F32_C4
XYZBGRA Colored point cloud. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the BGRA color. sl.MAT_TYPE.F32_C4
XYZARGB Colored point cloud. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the ARGB color. sl.MAT_TYPE.F32_C4
XYZABGR Colored point cloud. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the ABGR color. sl.MAT_TYPE.F32_C4
NORMALS Normals vector. Each pixel contains 4 float (X, Y, Z, 0). sl.MAT_TYPE.F32_C4
DISPARITY_RIGHT Disparity map for right sensor. Each pixel contains 1 float. sl.MAT_TYPE.F32_C1
DEPTH_RIGHT Depth map for right sensor. Each pixel contains 1 float. sl.MAT_TYPE.F32_C1
XYZ_RIGHT Point cloud for right sensor. Each pixel contains 4 float (X, Y, Z, not used). sl.MAT_TYPE.F32_C4
XYZRGBA_RIGHT Colored point cloud for right sensor. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the RGBA color. sl.MAT_TYPE.F32_C4
XYZBGRA_RIGHT Colored point cloud for right sensor. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the BGRA color. sl.MAT_TYPE.F32_C4
XYZARGB_RIGHT Colored point cloud for right sensor. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the ARGB color. sl.MAT_TYPE.F32_C4
XYZABGR_RIGHT Colored point cloud for right sensor. Each pixel contains 4 float (X, Y, Z, color). The color needs to be read as an unsigned char[4] representing the ABGR color. sl.MAT_TYPE.F32_C4
NORMALS_RIGHT Normals vector for right view. Each pixel contains 4 float (X, Y, Z, 0). sl.MAT_TYPE.F32_C4
DEPTH_U16_MM Depth map in millimeter whatever the sl.UNIT defined in sl.InitParameters. Invalid values are set to 0, depth values are clamped at 65000. Each pixel contains 1 unsigned short. sl.MAT_TYPE.U16_C1
DEPTH_U16_MM_RIGHT Depth map in millimeter for right sensor. Each pixel contains 1 unsigned short. sl.MAT_TYPE.U16_C1

猜你喜欢

转载自blog.csdn.net/weixin_41837701/article/details/132342195