rgb_preview.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  using namespace std;
8  // Create pipeline
9  dai::Pipeline pipeline;
10 
11  // Define source and output
12  auto camRgb = pipeline.create<dai::node::ColorCamera>();
13  auto xoutRgb = pipeline.create<dai::node::XLinkOut>();
14 
15  xoutRgb->setStreamName("rgb");
16 
17  // Properties
18  camRgb->setPreviewSize(300, 300);
19  camRgb->setBoardSocket(dai::CameraBoardSocket::CAM_A);
21  camRgb->setInterleaved(false);
22  camRgb->setColorOrder(dai::ColorCameraProperties::ColorOrder::RGB);
23 
24  // Linking
25  camRgb->preview.link(xoutRgb->input);
26 
27  // Connect to device and start pipeline
28  dai::Device device(pipeline, dai::UsbSpeed::SUPER);
29 
30  cout << "Connected cameras: " << device.getConnectedCameraFeatures() << endl;
31 
32  // Print USB speed
33  cout << "Usb speed: " << device.getUsbSpeed() << endl;
34 
35  // Bootloader version
36  if(device.getBootloaderVersion()) {
37  cout << "Bootloader version: " << device.getBootloaderVersion()->toString() << endl;
38  }
39 
40  // Device name
41  cout << "Device name: " << device.getDeviceName() << " Product name: " << device.getProductName() << endl;
42 
43  // Output queue will be used to get the rgb frames from the output defined above
44  auto qRgb = device.getOutputQueue("rgb", 4, false);
45 
46  while(true) {
47  auto inRgb = qRgb->get<dai::ImgFrame>();
48 
49  // Retrieve 'bgr' (opencv format) frame
50  cv::imshow("rgb", inRgb->getCvFrame());
51 
52  int key = cv::waitKey(1);
53  if(key == 'q' || key == 'Q') {
54  break;
55  }
56  }
57  return 0;
58 }
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::CameraBoardSocket::CAM_A
@ CAM_A
dai::node::ColorCamera
ColorCamera node. For use with color sensors.
Definition: ColorCamera.hpp:16
dai::UsbSpeed::SUPER
@ SUPER
dai::DeviceBase::getConnectedCameraFeatures
std::vector< CameraFeatures > getConnectedCameraFeatures()
Definition: DeviceBase.cpp:1109
dai::ColorCameraProperties::ColorOrder::RGB
@ RGB
dai::DeviceBase::getProductName
std::string getProductName()
Definition: DeviceBase.cpp:1220
dai::Device::getOutputQueue
std::shared_ptr< DataOutputQueue > getOutputQueue(const std::string &name)
Definition: Device.cpp:86
main
int main()
Definition: rgb_preview.cpp:6
depthai.hpp
dai::Pipeline::create
std::shared_ptr< N > create()
Definition: Pipeline.hpp:145
dai::DeviceBase::getDeviceName
std::string getDeviceName()
Definition: DeviceBase.cpp:1226
dai::DeviceBase::getBootloaderVersion
tl::optional< Version > getBootloaderVersion()
Definition: DeviceBase.cpp:1188
dai::ImgFrame
Definition: ImgFrame.hpp:25
dai::ColorCameraProperties::SensorResolution::THE_1080_P
@ THE_1080_P
1920 × 1080
dai::Device
Definition: Device.hpp:21
dai::DeviceBase::getUsbSpeed
UsbSpeed getUsbSpeed()
Definition: DeviceBase.cpp:1184
std
Definition: Node.hpp:366
dai::node::ColorCamera::setPreviewSize
void setPreviewSize(int width, int height)
Set preview output size.
Definition: ColorCamera.cpp:121


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