device_queue_event.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 // Includes common necessary includes for development using depthai library
4 #include "depthai/depthai.hpp"
5 
6 int main() {
7  // Create pipeline
8  dai::Pipeline pipeline;
9 
10  // Define sources and outputs
11  auto camRgb = pipeline.create<dai::node::ColorCamera>();
12  auto camMono = pipeline.create<dai::node::MonoCamera>();
13  auto xoutRgb = pipeline.create<dai::node::XLinkOut>();
14  auto xoutMono = pipeline.create<dai::node::XLinkOut>();
15 
16  xoutRgb->setStreamName("rgb");
17  xoutMono->setStreamName("mono");
18 
19  // Properties
20  camRgb->setInterleaved(true);
21  camRgb->setPreviewSize(300, 300);
22 
23  // Linking
24  camRgb->preview.link(xoutRgb->input);
25  camMono->out.link(xoutMono->input);
26 
27  // Connect to device and start pipeline
28  dai::Device device(pipeline);
29 
30  // Clear queue events
31  device.getQueueEvents();
32 
33  while(true) {
34  auto ev = device.getQueueEvent();
35 
36  if(ev == "rgb") {
37  auto rgb = device.getOutputQueue(ev)->get<dai::ImgFrame>();
38  cv::imshow("rgb", rgb->getFrame());
39  } else if(ev == "mono") {
40  auto mono = device.getOutputQueue(ev)->get<dai::ImgFrame>();
41  cv::imshow("mono", mono->getFrame());
42  }
43 
44  int key = cv::waitKey(1);
45  if(key == 'q' || key == 'Q') {
46  return 0;
47  }
48  }
49  return 0;
50 }
dai::node::XLinkOut
XLinkOut node. Sends messages over XLink.
Definition: XLinkOut.hpp:14
dai::Pipeline
Represents the pipeline, set of nodes and connections between them.
Definition: Pipeline.hpp:100
dai::node::MonoCamera
MonoCamera node. For use with grayscale sensors.
Definition: MonoCamera.hpp:17
dai::node::ColorCamera
ColorCamera node. For use with color sensors.
Definition: ColorCamera.hpp:16
dai::Device::getOutputQueue
std::shared_ptr< DataOutputQueue > getOutputQueue(const std::string &name)
Definition: Device.cpp:86
dai::node::XLinkOut::input
Input input
Definition: XLinkOut.hpp:27
depthai.hpp
dai::Pipeline::create
std::shared_ptr< N > create()
Definition: Pipeline.hpp:145
main
int main()
Definition: device_queue_event.cpp:6
dai::ImgFrame
Definition: ImgFrame.hpp:25
dai::Device
Definition: Device.hpp:21
dai::Device::getQueueEvent
std::string getQueueEvent(const std::vector< std::string > &queueNames, std::chrono::microseconds timeout=std::chrono::microseconds(-1))
Definition: Device.cpp:238
dai::Device::getQueueEvents
std::vector< std::string > getQueueEvents(const std::vector< std::string > &queueNames, std::size_t maxNumEvents=std::numeric_limits< std::size_t >::max(), std::chrono::microseconds timeout=std::chrono::microseconds(-1))
Definition: Device.cpp:164
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