opencv_support.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 // Include OpenCV
7 #include <opencv2/opencv.hpp>
8 
9 int main() {
10  // Create pipeline
11  dai::Pipeline pipeline;
12 
13  // Define source and outputs
14  auto camRgb = pipeline.create<dai::node::ColorCamera>();
15  auto xoutVideo = pipeline.create<dai::node::XLinkOut>();
16  auto xoutPreview = pipeline.create<dai::node::XLinkOut>();
17 
18  xoutVideo->setStreamName("video");
19  xoutPreview->setStreamName("preview");
20 
21  // Properties
22  camRgb->setPreviewSize(300, 300);
23  camRgb->setBoardSocket(dai::CameraBoardSocket::CAM_A);
25  camRgb->setInterleaved(true);
26  camRgb->setColorOrder(dai::ColorCameraProperties::ColorOrder::BGR);
27 
28  // Linking
29  camRgb->video.link(xoutVideo->input);
30  camRgb->preview.link(xoutPreview->input);
31 
32  // Connect to device and start pipeline
33  dai::Device device(pipeline);
34 
35  auto video = device.getOutputQueue("video");
36  auto preview = device.getOutputQueue("preview");
37 
38  while(true) {
39  auto videoFrame = video->get<dai::ImgFrame>();
40  auto previewFrame = preview->get<dai::ImgFrame>();
41 
42  // Get BGR frame from NV12 encoded video frame to show with opencv
43  cv::imshow("video", videoFrame->getCvFrame());
44 
45  // Show 'preview' frame as is (already in correct format, no copy is made)
46  cv::imshow("preview", previewFrame->getFrame());
47 
48  int key = cv::waitKey(1);
49  if(key == 'q' || key == 'Q') return 0;
50  }
51  return 0;
52 }
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::ImgFrame::getFrame
void getFrame(T...)
Definition: ImgFrame.hpp:218
dai::CameraBoardSocket::CAM_A
@ CAM_A
dai::node::ColorCamera
ColorCamera node. For use with color sensors.
Definition: ColorCamera.hpp:16
main
int main()
Definition: opencv_support.cpp:9
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
dai::ColorCameraProperties::ColorOrder::BGR
@ BGR
dai::ImgFrame
Definition: ImgFrame.hpp:25
dai::ColorCameraProperties::SensorResolution::THE_1080_P
@ THE_1080_P
1920 × 1080
dai::Device
Definition: Device.hpp:21
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