DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • RGB Full Resolution Saver
  • Similar samples:
  • Demo
  • Setup
  • Source code
  • Pipeline

RGB Full Resolution Saver

This example saves full-resolution 3840x2160 .jpeg images when c key is pressed. It serves as an example of recording high resolution frames to disk for the purposes of high-resolution ground-truth data.Note that each frame consumes above 2MB of storage, so "spamming" capture key could fill up your storage.

Similar samples:

Demo

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python
C++

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import time
4from pathlib import Path
5import cv2
6import depthai as dai
7
8# Create pipeline
9pipeline = dai.Pipeline()
10
11camRgb = pipeline.create(dai.node.ColorCamera)
12camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
13camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
14
15xoutRgb = pipeline.create(dai.node.XLinkOut)
16xoutRgb.setStreamName("rgb")
17camRgb.video.link(xoutRgb.input)
18
19xin = pipeline.create(dai.node.XLinkIn)
20xin.setStreamName("control")
21xin.out.link(camRgb.inputControl)
22
23# Properties
24videoEnc = pipeline.create(dai.node.VideoEncoder)
25videoEnc.setDefaultProfilePreset(1, dai.VideoEncoderProperties.Profile.MJPEG)
26camRgb.still.link(videoEnc.input)
27
28# Linking
29xoutStill = pipeline.create(dai.node.XLinkOut)
30xoutStill.setStreamName("still")
31videoEnc.bitstream.link(xoutStill.input)
32
33# Connect to device and start pipeline
34with dai.Device(pipeline) as device:
35
36    # Output queue will be used to get the rgb frames from the output defined above
37    qRgb = device.getOutputQueue(name="rgb", maxSize=30, blocking=False)
38    qStill = device.getOutputQueue(name="still", maxSize=30, blocking=True)
39    qControl = device.getInputQueue(name="control")
40
41    # Make sure the destination path is present before starting to store the examples
42    dirName = "rgb_data"
43    Path(dirName).mkdir(parents=True, exist_ok=True)
44
45    while True:
46        inRgb = qRgb.tryGet()  # Non-blocking call, will return a new data that has arrived or None otherwise
47        if inRgb is not None:
48            frame = inRgb.getCvFrame()
49            # 4k / 4
50            frame = cv2.pyrDown(frame)
51            frame = cv2.pyrDown(frame)
52            cv2.imshow("rgb", frame)
53
54        if qStill.has():
55            fName = f"{dirName}/{int(time.time() * 1000)}.jpeg"
56            with open(fName, "wb") as f:
57                f.write(qStill.get().getData())
58                print('Image saved to', fName)
59
60        key = cv2.waitKey(1)
61        if key == ord('q'):
62            break
63        elif key == ord('c'):
64            ctrl = dai.CameraControl()
65            ctrl.setCaptureStill(True)
66            qControl.send(ctrl)
67            print("Sent 'still' event to the camera!")

Pipeline

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.