7. Others
1. Camera control
(1) Select video mode
Left and right video frames are synchronized and streamed as a single uncompressed video frame in side-by-side format.
The resolution and frame rate of the video can be changed in ZED Explorer or using the API.
(2) Select output view
ZED can output images in different formats, including corrected, uncorrected and grayscale images (left view, right view, side-by-side view, left uncorrected or right uncorrected, left grayscale or right grayscale).
(3) Adjust camera settings
The ZED camera has an on-board ISP (Image Signal Processor) that can perform various image processing algorithms on the raw images captured by the dual image sensors. ISP parameters can be adjusted through ZED Explorer or ZED SDK.
The camera adjustment parameters are synchronized left and right and cannot be adjusted individually.
When your camera's white balance, exposure, and gain are in Auto mode, they automatically adjust based on the brightness in the scene.
NOTE: Increase the Gamma setting in low light environments.
Use API
(1) Camera configuration
Create a camera object and specify InitParameters.
The initial parameters can adjust resolution, FPS, depth sensing parameters, etc. These parameters can only be set before turning on the camera and cannot be changed while the camera is in use.
# Create a ZED camera object
zed = sl.Camera()
# Set configuration parameters
init_params = sl.InitParameters()
init_params.camera_resolution = sl.RESOLUTION.HD1080
init_params.camera_fps = 30
# Open the camera
err = zed.open(init_params)
if err != sl.ERROR_CODE.SUCCESS:
exit(-1)
InitParameters contains default configuration.
(2) Capture image
Specify RuntimeParameters, call grab() to capture new frames, and call retrieveImage() to retrieve captured frames.
retrieveImage() can choose between different views, such as left, right, uncorrected and grayscale images.
image = sl.Mat()
if zed.grab() == SUCCESS:
# A new image is available if grab() returns SUCCESS
zed.retrieve_image(image, sl.VIEW.LEFT) # Retrieve the left image
(3) Adjust camera controls
Camera settings such as exposure and white balance can be set manually at runtime using setcamersettings().
To change camera resolution and frame rate, use InitParameters().
# Set exposure to 50% of camera framerate
zed.set_camera_settings(sl.VIDEO_SETTINGS.EXPOSURE, 50)
# Set white balance to 4600K
zed.set_camera_settings(sl.VIDEO_SETTINGS.WHITE_BALANCE, 4600)
# Reset to auto exposure
zed.set_camera_settings(sl.VIDEO_SETTINGS.EXPOSURE, -1)
complete program
"""
Live camera sample showing the camera information and video in real time and allows to control the different
settings.
"""
import cv2
import pyzed.sl as sl
camera_settings = sl.VIDEO_SETTINGS.BRIGHTNESS
str_camera_settings = "BRIGHTNESS"
step_camera_settings = 1
def main():
print("Running...")
init = sl.InitParameters()
cam = sl.Camera()
if not cam.is_opened():
print("Opening ZED Camera...")
status = cam.open(init)
if status != sl.ERROR_CODE.SUCCESS:
print(repr(status))
exit()
runtime = sl.RuntimeParameters()
mat = sl.Mat()
print_camera_information(cam)
print_help()
key = ''
while key != 113: # for 'q' key
err = cam.grab(runtime)
if err == sl.ERROR_CODE.SUCCESS:
cam.retrieve_image(mat, sl.VIEW.LEFT)
cv2.imshow("ZED", mat.get_data())
key = cv2.waitKey(5)
settings(key, cam, runtime, mat)
else:
key = cv2.waitKey(5)
cv2.destroyAllWindows()
cam.close()
print("\nFINISH")
def print_camera_information(cam):
print("Resolution: {0}, {1}.".format(round(cam.get_camera_information().camera_configuration.resolution.width, 2), cam.get_camera_information().camera_configuration.resolution.height))
print("Camera FPS: {0}.".format(cam.get_camera_information().camera_configuration.fps))
print("Firmware: {0}.".format(cam.get_camera_information().camera_configuration.firmware_version))
print("Serial number: {0}.\n".format(cam.get_camera_information().serial_number))
def print_help():
print("Help for camera setting controls")
print(" Increase camera settings value: +")
print(" Decrease camera settings value: -")
print(" Switch camera settings: s")
print(" Reset all parameters: r")
print(" Record a video: z")
print(" Quit: q\n")
def settings(key, cam, runtime, mat):
if key == 115: # for 's' key
switch_camera_settings()
elif key == 43: # for '+' key
current_value = cam.get_camera_settings(camera_settings)[1]
cam.set_camera_settings(camera_settings, current_value + step_camera_settings)
print(str_camera_settings + ": " + str(current_value + step_camera_settings))
elif key == 45: # for '-' key
current_value = cam.get_camera_settings(camera_settings)[1]
if current_value >= 1:
cam.set_camera_settings(camera_settings, current_value - step_camera_settings)
print(str_camera_settings + ": " + str(current_value - step_camera_settings))
elif key == 114: # for 'r' key
cam.set_camera_settings(sl.VIDEO_SETTINGS.BRIGHTNESS, -1)
cam.set_camera_settings(sl.VIDEO_SETTINGS.CONTRAST, -1)
cam.set_camera_settings(sl.VIDEO_SETTINGS.HUE, -1)
cam.set_camera_settings(sl.VIDEO_SETTINGS.SATURATION, -1)
cam.set_camera_settings(sl.VIDEO_SETTINGS.SHARPNESS, -1)
cam.set_camera_settings(sl.VIDEO_SETTINGS.GAIN, -1)
cam.set_camera_settings(sl.VIDEO_SETTINGS.EXPOSURE, -1)
cam.set_camera_settings(sl.VIDEO_SETTINGS.WHITEBALANCE_TEMPERATURE, -1)
print("Camera settings: reset")
elif key == 122: # for 'z' key
record(cam, runtime, mat)
def switch_camera_settings():
global camera_settings
global str_camera_settings
if camera_settings == sl.VIDEO_SETTINGS.BRIGHTNESS:
camera_settings = sl.VIDEO_SETTINGS.CONTRAST
str_camera_settings = "Contrast"
print("Camera settings: CONTRAST")
elif camera_settings == sl.VIDEO_SETTINGS.CONTRAST:
camera_settings = sl.VIDEO_SETTINGS.HUE
str_camera_settings = "Hue"
print("Camera settings: HUE")
elif camera_settings == sl.VIDEO_SETTINGS.HUE:
camera_settings = sl.VIDEO_SETTINGS.SATURATION
str_camera_settings = "Saturation"
print("Camera settings: SATURATION")
elif camera_settings == sl.VIDEO_SETTINGS.SATURATION:
camera_settings = sl.VIDEO_SETTINGS.SHARPNESS
str_camera_settings = "Sharpness"
print("Camera settings: Sharpness")
elif camera_settings == sl.VIDEO_SETTINGS.SHARPNESS:
camera_settings = sl.VIDEO_SETTINGS.GAIN
str_camera_settings = "Gain"
print("Camera settings: GAIN")
elif camera_settings == sl.VIDEO_SETTINGS.GAIN:
camera_settings = sl.VIDEO_SETTINGS.EXPOSURE
str_camera_settings = "Exposure"
print("Camera settings: EXPOSURE")
elif camera_settings == sl.VIDEO_SETTINGS.EXPOSURE:
camera_settings = sl.VIDEO_SETTINGS.WHITEBALANCE_TEMPERATURE
str_camera_settings = "White Balance"
print("Camera settings: WHITEBALANCE")
elif camera_settings == sl.VIDEO_SETTINGS.WHITEBALANCE_TEMPERATURE:
camera_settings = sl.VIDEO_SETTINGS.BRIGHTNESS
str_camera_settings = "Brightness"
print("Camera settings: BRIGHTNESS")
def record(cam, runtime, mat):
vid = sl.ERROR_CODE.FAILURE
out = False
while vid != sl.ERROR_CODE.SUCCESS and not out:
filepath = input("Enter filepath name: ")
record_param = sl.RecordingParameters(filepath)
vid = cam.enable_recording(record_param)
print(repr(vid))
if vid == sl.ERROR_CODE.SUCCESS:
print("Recording started...")
out = True
print("Hit spacebar to stop recording: ")
key = False
while key != 32: # for spacebar
err = cam.grab(runtime)
if err == sl.ERROR_CODE.SUCCESS:
cam.retrieve_image(mat)
cv2.imshow("ZED", mat.get_data())
key = cv2.waitKey(5)
else:
print("Help: you must enter the filepath + filename + SVO extension.")
print("Recording not started.")
cam.disable_recording()
print("Recording finished.")
cv2.destroyAllWindows()
if __name__ == "__main__":
main()