|
| 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 | +} |
0 commit comments