DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • 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

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!")

C++

1#include <chrono>
2#include <iostream>
3
4// Includes common necessary includes for development using depthai library
5#include "depthai/depthai.hpp"
6#include "utility.hpp"
7
8int main() {
9    using namespace std::chrono;
10
11    // Create pipeline
12    dai::Pipeline pipeline;
13
14    // Define source and outputs
15    auto camRgb = pipeline.create<dai::node::ColorCamera>();
16    auto videoEnc = pipeline.create<dai::node::VideoEncoder>();
17    auto xoutJpeg = pipeline.create<dai::node::XLinkOut>();
18    auto xoutRgb = pipeline.create<dai::node::XLinkOut>();
19
20    xoutJpeg->setStreamName("jpeg");
21    xoutRgb->setStreamName("rgb");
22
23    // Properties
24    camRgb->setBoardSocket(dai::CameraBoardSocket::CAM_A);
25    camRgb->setResolution(dai::ColorCameraProperties::SensorResolution::THE_4_K);
26    videoEnc->setDefaultProfilePreset(camRgb->getFps(), dai::VideoEncoderProperties::Profile::MJPEG);
27
28    // Linking
29    camRgb->video.link(xoutRgb->input);
30    camRgb->video.link(videoEnc->input);
31    videoEnc->bitstream.link(xoutJpeg->input);
32
33    // Connect to device and start pipeline
34    dai::Device device(pipeline);
35
36    // Queues
37    auto qRgb = device.getOutputQueue("rgb", 30, false);
38    auto qJpeg = device.getOutputQueue("jpeg", 30, true);
39
40    std::string dirName = "rgb_data";
41    createDirectory(dirName);
42
43    while(true) {
44        auto inRgb = qRgb->tryGet<dai::ImgFrame>();
45        if(inRgb != NULL) {
46            cv::imshow("rgb", inRgb->getCvFrame());
47        }
48
49        auto encFrames = qJpeg->tryGetAll<dai::ImgFrame>();
50        for(const auto& encFrame : encFrames) {
51            uint64_t time = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
52            std::stringstream videoStr;
53            videoStr << dirName << "/" << time << ".jpeg";
54            auto videoFile = std::ofstream(videoStr.str(), std::ios::binary);
55            videoFile.write((char*)encFrame->getData().data(), encFrame->getData().size());
56        }
57
58        int key = cv::waitKey(1);
59        if(key == 'q' || key == 'Q') {
60            return 0;
61        }
62    }
63    return 0;
64}

Pipeline

Need assistance?

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