Hi, here you have
import cv2
import depthai as dai
import time
import os
# Define possible resolutionsresolutions = {
ord('s'): dai.ColorCameraProperties.SensorResolution.THE_4_K, ord('d'): dai.ColorCameraProperties.SensorResolution.THE_1080_P, ord('f'): dai.ColorCameraProperties.SensorResolution.THE_12_MP }
# Status to restart resolution
reset_resolution = True
# Output folder pathoutput_folder =
#Create a pipelinepipeline = dai.Pipeline()
# Adding an RGB camera to the pipeline
camRgb = pipeline.create(dai.node.ColorCamera)
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
#camRgb.setResolution(current_resolution)
# Add output nodesxout
Rgb = pipeline.create(dai.node.XLinkOut)
xoutRgb.setStreamName("rgb")
camRgb.video.link(xoutRgb.input)
# Start the pipeline and obtain the output queues
with dai.Device(pipeline) as device:
queueRgb = device.getOutputQueue("rgb", maxSize=8, blocking=False)
while True:
inRgb = queueRgb.get()
if inRgb is not None
resized_frame = cv2.resize(inRgb.getCvFrame(), (640, 480))
cv2.imshow("RGB", resized_frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
if key == ord('r'):
reset_resolution = True # Set status to reset resolution
print("Resolution status reset")
elif key in resolutions:
reset_resolution = False # Disable reset state
current_resolution = resolutions[key]
camRgb = pipeline.create(dai.node.ColorCamera)
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
camRgb.setResolution(current_resolution)
print(f "Resolution changed to {current_resolution.name}")
if not reset_resolution:
print("Waiting to change resolution...")
time.sleep(8)
# Capture image at current resolution
print("Current resolution: ", current_resolution)
time.sleep(8)
file_filename = f"capture_{current_resolution.name}.jpg"
full_path = os.path.join(output_folder, filename)
cv2.imwrite(full_path, inRgb.getCvFrame())
print(f"Image captured and saved as '{full_path}'")
current_resolution = None
cv2.destroyAllWindows()