此页面由 AI 自动翻译。查看英文原版
DepthAI
软件栈

本页目录

  • 演示
  • 支持的设备
  • 流水线
  • 源代码

IR 投影仪控制

Supported on:RVC2RVC4
显示左右单声道流,并允许您在运行时更改 IR 点投影仪 和泛光灯(又名泛光 LED)的强度。启用泛光灯可改善深度检测。控件:W/S 用于点强度,A/D 用于泛光强度,Q 退出。仅适用于 Pro 系列设备

演示

此示例需要 DepthAI v3 API,请参阅 安装说明

支持的设备

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

流水线

源代码

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}

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。