DepthAI
Software Stack

ON THIS PAGE

  • Demo
  • Supported devices
  • Pipeline
  • Source code

IR Projectors Control

Supported on:RVC2RVC4
Displays left/right mono streams and lets you change IR dot projector and flood light (aka. flood LED) intensities on the device at runtime. Enabling flood lights allows for better depth detection. Controls: W/S for dot intensity, A/D for flood intensity, Q to quit. Works only with Pro-series devices.

Demo

This example requires the DepthAI v3 API, see installation instructions.

Supported devices

  • OAK4-D Pro
  • OAK-D Pro W PoE
  • OAK-D Pro W
  • OAK-D Pro PoE
  • OAK-D Pro

Pipeline

Source code

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6dot_intensity = 1
7DOT_STEP = 0.1
8
9flood_intensity = 1
10FLOOD_STEP = 0.1
11
12# Create pipeline
13device = dai.Device()
14with dai.Pipeline(device) as pipeline:
15    monoLeft = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
16    monoRight = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
17
18    # Linking
19    monoLeftOut = monoLeft.requestFullResolutionOutput(type=dai.ImgFrame.Type.NV12)
20    monoRightOut = monoRight.requestFullResolutionOutput(type=dai.ImgFrame.Type.NV12)
21
22    leftQueue = monoLeftOut.createOutputQueue()
23    rightQueue = monoRightOut.createOutputQueue()
24
25    pipeline.start()
26    pipeline.getDefaultDevice().setIrLaserDotProjectorIntensity(dot_intensity)
27    pipeline.getDefaultDevice().setIrFloodLightIntensity(flood_intensity)
28    while pipeline.isRunning():
29        leftSynced = leftQueue.get()
30        rightSynced = rightQueue.get()
31        assert isinstance(leftSynced, dai.ImgFrame)
32        assert isinstance(rightSynced, dai.ImgFrame)
33        cv2.imshow(f"left", leftSynced.getCvFrame())
34        cv2.imshow(f"right", rightSynced.getCvFrame())
35
36        key = cv2.waitKey(1)
37        if key == ord('q'):
38            pipeline.stop()
39            break
40        elif key == ord("w"):
41            dot_intensity += DOT_STEP
42            if dot_intensity > 1:
43                dot_intensity = 1
44            pipeline.getDefaultDevice().setIrLaserDotProjectorIntensity(dot_intensity)
45            print(f"Dot intensity: {dot_intensity}")
46        elif key == ord("s"):
47            dot_intensity -= DOT_STEP
48            if dot_intensity < 0:
49                dot_intensity = 0
50            pipeline.getDefaultDevice().setIrLaserDotProjectorIntensity(dot_intensity)
51            print(f"Dot intensity: {dot_intensity}")
52        elif key == ord("a"):
53            flood_intensity += FLOOD_STEP
54            if flood_intensity > 1:
55                flood_intensity = 1
56            pipeline.getDefaultDevice().setIrFloodLightIntensity(flood_intensity)
57            print(f"Flood intensity: {flood_intensity}")
58        elif key == ord("d"):
59            flood_intensity -= FLOOD_STEP
60            if flood_intensity < 0:
61                flood_intensity = 0
62            pipeline.getDefaultDevice().setIrFloodLightIntensity(flood_intensity)
63            print(f"Flood intensity: {flood_intensity}")

C++

1#include <atomic>
2#include <csignal>
3#include <iostream>
4#include <memory>
5#include <opencv2/opencv.hpp>
6
7#include "depthai/depthai.hpp"
8
9// Global flag for graceful shutdown
10std::atomic<bool> quitEvent(false);
11
12// Signal handler
13void signalHandler(int signum) {
14    quitEvent = true;
15}
16
17// Constants for intensity control
18constexpr float DOT_STEP = 0.1f;
19constexpr float FLOOD_STEP = 0.1f;
20
21int main() {
22    // Set up signal handlers
23    signal(SIGTERM, signalHandler);
24    signal(SIGINT, signalHandler);
25
26    try {
27        // Create device
28        auto device = std::make_shared<dai::Device>();
29
30        // Create pipeline
31        dai::Pipeline pipeline(device);
32
33        // Create camera nodes
34        auto monoLeft = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B);
35        auto monoRight = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C);
36
37        // Configure outputs
38        auto monoLeftOut = monoLeft->requestFullResolutionOutput(dai::ImgFrame::Type::NV12);
39        auto monoRightOut = monoRight->requestFullResolutionOutput(dai::ImgFrame::Type::NV12);
40
41        // Create output queues
42        auto leftQueue = monoLeftOut->createOutputQueue();
43        auto rightQueue = monoRightOut->createOutputQueue();
44
45        // Start pipeline
46        pipeline.start();
47
48        // Initialize intensities
49        float dot_intensity = 1.0f;
50        float flood_intensity = 1.0f;
51
52        // Set initial intensities
53        device->setIrLaserDotProjectorIntensity(dot_intensity);
54        device->setIrFloodLightIntensity(flood_intensity);
55
56        std::cout << "Controls:" << std::endl;
57        std::cout << "  W/S: Increase/decrease dot projector intensity" << std::endl;
58        std::cout << "  A/D: Increase/decrease flood light intensity" << std::endl;
59        std::cout << "  Q: Quit" << std::endl;
60
61        while(pipeline.isRunning() && !quitEvent) {
62            auto leftSynced = leftQueue->get<dai::ImgFrame>();
63            auto rightSynced = rightQueue->get<dai::ImgFrame>();
64
65            if(leftSynced == nullptr || rightSynced == nullptr) continue;
66
67            cv::imshow("left", leftSynced->getCvFrame());
68            cv::imshow("right", rightSynced->getCvFrame());
69
70            int key = cv::waitKey(1);
71            if(key == 'q') {
72                break;
73            } else if(key == 'w') {
74                dot_intensity += DOT_STEP;
75                if(dot_intensity > 1.0f) dot_intensity = 1.0f;
76                device->setIrLaserDotProjectorIntensity(dot_intensity);
77                std::cout << "Dot intensity: " << dot_intensity << std::endl;
78            } else if(key == 's') {
79                dot_intensity -= DOT_STEP;
80                if(dot_intensity < 0.0f) dot_intensity = 0.0f;
81                device->setIrLaserDotProjectorIntensity(dot_intensity);
82                std::cout << "Dot intensity: " << dot_intensity << std::endl;
83            } else if(key == 'a') {
84                flood_intensity += FLOOD_STEP;
85                if(flood_intensity > 1.0f) flood_intensity = 1.0f;
86                device->setIrFloodLightIntensity(flood_intensity);
87                std::cout << "Flood intensity: " << flood_intensity << std::endl;
88            } else if(key == 'd') {
89                flood_intensity -= FLOOD_STEP;
90                if(flood_intensity < 0.0f) flood_intensity = 0.0f;
91                device->setIrFloodLightIntensity(flood_intensity);
92                std::cout << "Flood intensity: " << flood_intensity << std::endl;
93            }
94        }
95
96        // Cleanup
97        pipeline.stop();
98        pipeline.wait();
99
100    } catch(const std::exception& e) {
101        std::cerr << "Error: " << e.what() << std::endl;
102        return 1;
103    }
104
105    return 0;
106}

Need assistance?

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