Skip to content

Commit

Permalink
Merge pull request #556 from luxonis/multi_device_example
Browse files Browse the repository at this point in the history
Added an example with multiple devices
  • Loading branch information
Erol444 authored Aug 17, 2022
2 parents e845fca + f8a492b commit 41de567
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ dai_add_example(mono_depth_mobilenetssd mixed/mono_depth_mobilenetssd.cpp ON)
dai_add_example(rgb_encoding_mono_mobilenet mixed/rgb_encoding_mono_mobilenet.cpp ON)
dai_add_example(rgb_encoding_mono_mobilenet_depth mixed/rgb_encoding_mono_mobilenet_depth.cpp ON)
dai_add_example(rgb_encoding_mobilenet mixed/rgb_encoding_mobilenet.cpp ON)
dai_add_example(multiple_devices mixed/multiple_devices.cpp OFF)

target_compile_definitions(mono_depth_mobilenetssd PRIVATE BLOB_PATH="${mobilenet_blob}")
target_compile_definitions(rgb_encoding_mono_mobilenet PRIVATE BLOB_PATH="${mobilenet_blob}")
Expand Down
74 changes: 74 additions & 0 deletions examples/mixed/multiple_devices.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <chrono>
#include <iostream>

// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"

std::shared_ptr<dai::Pipeline> createPipeline() {
// Start defining a pipeline
auto pipeline = std::make_shared<dai::Pipeline>();
// Define a source - color camera
auto camRgb = pipeline->create<dai::node::ColorCamera>();

camRgb->setPreviewSize(300, 300);
camRgb->setBoardSocket(dai::CameraBoardSocket::RGB);
camRgb->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
camRgb->setInterleaved(false);

// Create output
auto xoutRgb = pipeline->create<dai::node::XLinkOut>();
xoutRgb->setStreamName("rgb");
camRgb->preview.link(xoutRgb->input);

return pipeline;
}

int main(int argc, char** argv) {
auto deviceInfoVec = dai::Device::getAllAvailableDevices();
const auto usbSpeed = dai::UsbSpeed::SUPER;
auto openVinoVersion = dai::OpenVINO::Version::VERSION_2021_4;

std::map<std::string, std::shared_ptr<dai::DataOutputQueue>> qRgbMap;
std::vector<std::shared_ptr<dai::Device>> devices;

for(auto& deviceInfo : deviceInfoVec) {
auto device = std::make_shared<dai::Device>(openVinoVersion, deviceInfo, usbSpeed);
devices.push_back(device);
std::cout << "===Connected to " << deviceInfo.getMxId() << std::endl;
auto mxId = device->getMxId();
auto cameras = device->getConnectedCameras();
auto usbSpeed = device->getUsbSpeed();
auto eepromData = device->readCalibration2().getEepromData();
std::cout << " >>> MXID:" << mxId << std::endl;
std::cout << " >>> Num of cameras:" << cameras.size() << std::endl;
std::cout << " >>> USB speed:" << usbSpeed << std::endl;
if(eepromData.boardName != ""){
std::cout << " >>> Board name:" << eepromData.boardName << std::endl;
}
if(eepromData.productName != ""){
std::cout << " >>> Product name:" << eepromData.productName << std::endl;
}
auto pipeline = createPipeline();
device->startPipeline(*pipeline);

auto qRgb = device->getOutputQueue("rgb", 4, false);
std::string streamName = "rgb-" + eepromData.productName + mxId;
qRgbMap.insert({streamName, qRgb});
}
while(true) {
for(auto& element : qRgbMap) {
auto qRgb = element.second;
auto streamName = element.first;
auto inRgb = qRgb->tryGet<dai::ImgFrame>();
if(inRgb != nullptr) {
cv::imshow(streamName, inRgb->getCvFrame());
}
}

int key = cv::waitKey(1);
if(key == 'q' || key == 'Q') {
return 0;
}
}
return 0;
}

0 comments on commit 41de567

Please sign in to comment.