multiple_devices.cpp
Go to the documentation of this file.
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::CAM_A);
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 }
dai::node::XLinkOut
XLinkOut node. Sends messages over XLink.
Definition: XLinkOut.hpp:14
createPipeline
std::shared_ptr< dai::Pipeline > createPipeline()
Definition: multiple_devices.cpp:7
dai::CameraBoardSocket::CAM_A
@ CAM_A
dai::node::ColorCamera
ColorCamera node. For use with color sensors.
Definition: ColorCamera.hpp:16
dai::UsbSpeed::SUPER
@ SUPER
depthai.hpp
dai::ImgFrame
Definition: ImgFrame.hpp:25
dai::ColorCameraProperties::SensorResolution::THE_1080_P
@ THE_1080_P
1920 × 1080
dai::DeviceBase::getAllAvailableDevices
static std::vector< DeviceInfo > getAllAvailableDevices()
Definition: DeviceBase.cpp:228
dai::node::ColorCamera::setPreviewSize
void setPreviewSize(int width, int height)
Set preview output size.
Definition: ColorCamera.cpp:121
main
int main(int argc, char **argv)
Definition: multiple_devices.cpp:26
dai::node::XLinkOut::setStreamName
void setStreamName(const std::string &name)
Definition: XLinkOut.cpp:13


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19