Skip to content

Commit 1f3f709

Browse files
committed
Merge branch 'SLC_multi_roi_and_device_info_exmaples' into develop
2 parents e96b549 + 6827b42 commit 1f3f709

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

examples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ dai_add_example(feature_tracker FeatureTracker/feature_tracker.cpp ON)
233233
dai_add_example(device_queue_event host_side/device_queue_event.cpp ON)
234234
dai_add_example(opencv_support host_side/opencv_support.cpp ON)
235235
dai_add_example(queue_add_callback host_side/queue_add_callback.cpp ON)
236+
dai_add_example(device_information host_side/device_information.cpp ON)
236237

237238
# ImageManip
238239
dai_add_example(image_manip ImageManip/image_manip_example.cpp ON)
@@ -312,6 +313,7 @@ dai_add_example(spatial_mobilenet_mono SpatialDetection/spatial_mobilenet_mono.c
312313
dai_add_example(spatial_mobilenet SpatialDetection/spatial_mobilenet.cpp ON)
313314
dai_add_example(spatial_tiny_yolo_v3 SpatialDetection/spatial_tiny_yolo.cpp ON)
314315
dai_add_example(spatial_tiny_yolo_v4 SpatialDetection/spatial_tiny_yolo.cpp ON)
316+
dai_add_example(spatial_calculator_multi_roi SpatialDetection/spatial_calculator_multi_roi.cpp ON)
315317

316318
target_compile_definitions(spatial_mobilenet_mono PRIVATE BLOB_PATH="${mobilenet_blob}")
317319
target_compile_definitions(spatial_mobilenet PRIVATE BLOB_PATH="${mobilenet_blob}")
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include <iostream>
2+
3+
#include "utility.hpp"
4+
5+
// Includes common necessary includes for development using depthai library
6+
#include "depthai/depthai.hpp"
7+
8+
static constexpr float stepSize = 0.05f;
9+
10+
static std::atomic<bool> newConfig{false};
11+
12+
int main() {
13+
using namespace std;
14+
15+
// Create pipeline
16+
dai::Pipeline pipeline;
17+
18+
// Define sources and outputs
19+
auto monoLeft = pipeline.create<dai::node::MonoCamera>();
20+
auto monoRight = pipeline.create<dai::node::MonoCamera>();
21+
auto stereo = pipeline.create<dai::node::StereoDepth>();
22+
auto spatialLocationCalculator = pipeline.create<dai::node::SpatialLocationCalculator>();
23+
24+
auto xoutDepth = pipeline.create<dai::node::XLinkOut>();
25+
auto xoutSpatialData = pipeline.create<dai::node::XLinkOut>();
26+
auto xinSpatialCalcConfig = pipeline.create<dai::node::XLinkIn>();
27+
28+
xoutDepth->setStreamName("depth");
29+
xoutSpatialData->setStreamName("spatialData");
30+
xinSpatialCalcConfig->setStreamName("spatialCalcConfig");
31+
32+
// Properties
33+
monoLeft->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
34+
monoLeft->setBoardSocket(dai::CameraBoardSocket::LEFT);
35+
monoRight->setResolution(dai::MonoCameraProperties::SensorResolution::THE_400_P);
36+
monoRight->setBoardSocket(dai::CameraBoardSocket::RIGHT);
37+
38+
stereo->setDefaultProfilePreset(dai::node::StereoDepth::PresetMode::HIGH_DENSITY);
39+
stereo->setLeftRightCheck(true);
40+
stereo->setExtendedDisparity(true);
41+
spatialLocationCalculator->inputConfig.setWaitForMessage(false);
42+
43+
// Create 10 ROIs
44+
for(int i = 0; i < 10; i++) {
45+
dai::SpatialLocationCalculatorConfigData config;
46+
config.depthThresholds.lowerThreshold = 200;
47+
config.depthThresholds.upperThreshold = 10000;
48+
config.roi = dai::Rect(dai::Point2f(i*0.1, 0.45), dai::Point2f((i+1)*0.1, 0.55));
49+
spatialLocationCalculator->initialConfig.addROI(config);
50+
}
51+
52+
// Linking
53+
monoLeft->out.link(stereo->left);
54+
monoRight->out.link(stereo->right);
55+
56+
spatialLocationCalculator->passthroughDepth.link(xoutDepth->input);
57+
stereo->depth.link(spatialLocationCalculator->inputDepth);
58+
59+
spatialLocationCalculator->out.link(xoutSpatialData->input);
60+
xinSpatialCalcConfig->out.link(spatialLocationCalculator->inputConfig);
61+
62+
// Connect to device and start pipeline
63+
dai::Device device(pipeline);
64+
device.setIrLaserDotProjectorBrightness(1000);
65+
66+
// Output queue will be used to get the depth frames from the outputs defined above
67+
auto depthQueue = device.getOutputQueue("depth", 4, false);
68+
auto spatialCalcQueue = device.getOutputQueue("spatialData", 4, false);
69+
auto color = cv::Scalar(0, 200, 40);
70+
auto fontType = cv::FONT_HERSHEY_TRIPLEX;
71+
72+
while(true) {
73+
auto inDepth = depthQueue->get<dai::ImgFrame>();
74+
75+
cv::Mat depthFrame = inDepth->getFrame(); // depthFrame values are in millimeters
76+
77+
cv::Mat depthFrameColor;
78+
cv::normalize(depthFrame, depthFrameColor, 255, 0, cv::NORM_INF, CV_8UC1);
79+
cv::equalizeHist(depthFrameColor, depthFrameColor);
80+
cv::applyColorMap(depthFrameColor, depthFrameColor, cv::COLORMAP_HOT);
81+
82+
auto spatialData = spatialCalcQueue->get<dai::SpatialLocationCalculatorData>()->getSpatialLocations();
83+
for(auto depthData : spatialData) {
84+
auto roi = depthData.config.roi;
85+
roi = roi.denormalize(depthFrameColor.cols, depthFrameColor.rows);
86+
87+
auto xmin = static_cast<int>(roi.topLeft().x);
88+
auto ymin = static_cast<int>(roi.topLeft().y);
89+
auto xmax = static_cast<int>(roi.bottomRight().x);
90+
auto ymax = static_cast<int>(roi.bottomRight().y);
91+
92+
auto coords = depthData.spatialCoordinates;
93+
auto distance = std::sqrt(coords.x * coords.x + coords.y * coords.y + coords.z * coords.z);
94+
95+
cv::rectangle(depthFrameColor, cv::Rect(cv::Point(xmin, ymin), cv::Point(xmax, ymax)), color);
96+
std::stringstream depthDistance;
97+
depthDistance.precision(2);
98+
depthDistance << fixed << static_cast<float>(distance/1000.0f) << "m";
99+
cv::putText(depthFrameColor, depthDistance.str(), cv::Point(xmin + 10, ymin + 20), fontType, 0.5, color);
100+
}
101+
// Show the frame
102+
cv::imshow("depth", depthFrameColor);
103+
104+
if(cv::waitKey(1) == 'q') {
105+
break;
106+
}
107+
108+
}
109+
return 0;
110+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
3+
// Includes common necessary includes for development using depthai library
4+
#include "depthai/depthai.hpp"
5+
6+
int main() {
7+
8+
std::cout << "Searching for all available devices...\n\n";
9+
auto infos = dai::Device::getAllAvailableDevices();
10+
11+
if(infos.size() <= 0) {
12+
std::cout << "Couldn't find any available devices.\n";
13+
return -1;
14+
}
15+
16+
for(auto& info : infos) {
17+
std::cout << "Found device: " << info.name << " mxid: " << info.mxid << " state: " << info.state << std::endl;
18+
}
19+
20+
// Connect to device and start pipeline
21+
std::cout << "\nBooting the first available camera (" << infos[0].name << ")...\n";
22+
dai::Device device(dai::Pipeline(), infos[0]);
23+
std::cout << "Available camera sensors: ";
24+
for(auto& sensor : device.getCameraSensorNames()) {
25+
std::cout << "Socket: " << sensor.first << " - " << sensor.second << ", ";
26+
}
27+
std::cout << std::endl;
28+
29+
auto eeprom = device.readCalibration2().getEepromData();
30+
std::cout << "Product name: " << eeprom.productName << ", board name: " << eeprom.boardName << std::endl;
31+
32+
return 0;
33+
}

0 commit comments

Comments
 (0)