Skip to content

Commit 06507ff

Browse files
author
Matevz Morato
committed
Naming + simplified the example a bit
Should address the requested changes in PR #556.
1 parent ae4c146 commit 06507ff

File tree

3 files changed

+76
-107
lines changed

3 files changed

+76
-107
lines changed

examples/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ dai_add_example(mono_camera_control MonoCamera/mono_camera_control.cpp ON)
278278
dai_add_example(mono_preview MonoCamera/mono_preview.cpp ON)
279279
dai_add_example(mono_full_resolution_saver MonoCamera/mono_full_resolution_saver.cpp ON)
280280

281-
# Multidevice
282-
dai_add_example(multidevice_example mixed/multidevice_example.cpp OFF)
281+
# MultiDevice
282+
dai_add_example(multidevice mixed/multidevice.cpp OFF)
283283

284284
# NeuralNetwork
285285
dai_add_example(concatenate NeuralNetwork/concat_multi_input.cpp ON)

examples/mixed/multidevice.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <chrono>
2+
#include <iostream>
3+
4+
// Includes common necessary includes for development using depthai library
5+
#include "depthai/depthai.hpp"
6+
7+
std::shared_ptr<dai::Pipeline> createPipeline() {
8+
// Start defining a pipeline
9+
auto pipeline = std::make_shared<dai::Pipeline>();
10+
// Define a source - color camera
11+
auto camRgb = pipeline->create<dai::node::ColorCamera>();
12+
13+
camRgb->setPreviewSize(300, 300);
14+
camRgb->setBoardSocket(dai::CameraBoardSocket::RGB);
15+
camRgb->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
16+
camRgb->setInterleaved(false);
17+
18+
// Create output
19+
auto xoutRgb = pipeline->create<dai::node::XLinkOut>();
20+
xoutRgb->setStreamName("rgb");
21+
camRgb->preview.link(xoutRgb->input);
22+
23+
return pipeline;
24+
}
25+
26+
int main(int argc, char** argv) {
27+
auto deviceInfoVec = dai::Device::getAllAvailableDevices();
28+
const auto usbSpeed = dai::UsbSpeed::SUPER;
29+
auto openVinoVersion = dai::OpenVINO::Version::VERSION_2021_4;
30+
31+
std::map<std::string, std::shared_ptr<dai::DataOutputQueue>> qRgbMap;
32+
std::vector<std::shared_ptr<dai::Device>> devices;
33+
34+
for(auto& deviceInfo : deviceInfoVec) {
35+
auto device = std::make_shared<dai::Device>(openVinoVersion, deviceInfo, usbSpeed);
36+
devices.push_back(device);
37+
std::cout << "===Connected to " << deviceInfo.getMxId() << std::endl;
38+
auto mxId = device->getMxId();
39+
auto cameras = device->getConnectedCameras();
40+
auto usbSpeed = device->getUsbSpeed();
41+
auto eepromData = device->readCalibration2().getEepromData();
42+
std::cout << " >>> MXID:" << mxId << std::endl;
43+
std::cout << " >>> Num of cameras:" << cameras.size() << std::endl;
44+
std::cout << " >>> USB speed:" << usbSpeed << std::endl;
45+
if(eepromData.boardName != ""){
46+
std::cout << " >>> Board name:" << eepromData.boardName << std::endl;
47+
}
48+
if(eepromData.productName != ""){
49+
std::cout << " >>> Product name:" << eepromData.productName << std::endl;
50+
}
51+
auto pipeline = createPipeline();
52+
device->startPipeline(*pipeline);
53+
54+
auto qRgb = device->getOutputQueue("rgb", 4, false);
55+
std::string streamName = "rgb-" + eepromData.productName + mxId;
56+
qRgbMap.insert({streamName, qRgb});
57+
}
58+
while(true) {
59+
for(auto& element : qRgbMap) {
60+
auto qRgb = element.second;
61+
auto streamName = element.first;
62+
auto inRgb = qRgb->tryGet<dai::ImgFrame>();
63+
if(inRgb != nullptr) {
64+
cv::imshow(streamName, inRgb->getCvFrame());
65+
}
66+
}
67+
68+
int key = cv::waitKey(1);
69+
if(key == 'q' || key == 'Q') {
70+
return 0;
71+
}
72+
}
73+
return 0;
74+
}

examples/mixed/multidevice_example.cpp

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)