script_forward_frames.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 
9  // Start defining a pipeline
10  dai::Pipeline pipeline;
11 
12  // Define a source - color camera
13  auto cam = pipeline.create<dai::node::ColorCamera>();
14  // Not needed, you can display 1080P frames as well
15  cam->setIspScale(1, 2);
16 
17  // Script node
18  auto script = pipeline.create<dai::node::Script>();
19  script->setScript(R"(
20  ctrl = CameraControl()
21  ctrl.setCaptureStill(True)
22  # Initially send still event
23  node.io['ctrl'].send(ctrl)
24 
25  normal = True
26  while True:
27  frame = node.io['frames'].get()
28  if normal:
29  ctrl.setAutoExposureCompensation(3)
30  node.io['stream1'].send(frame)
31  normal = False
32  else:
33  ctrl.setAutoExposureCompensation(-3)
34  node.io['stream2'].send(frame)
35  normal = True
36  node.io['ctrl'].send(ctrl)
37  )");
38 
39  cam->still.link(script->inputs["frames"]);
40 
41  // XLinkOut
42  auto xout1 = pipeline.create<dai::node::XLinkOut>();
43  xout1->setStreamName("stream1");
44  script->outputs["stream1"].link(xout1->input);
45 
46  auto xout2 = pipeline.create<dai::node::XLinkOut>();
47  xout2->setStreamName("stream2");
48  script->outputs["stream2"].link(xout2->input);
49 
50  // Connections
51  script->outputs["ctrl"].link(cam->inputControl);
52 
53  // Connect to device with pipeline
54  dai::Device device(pipeline);
55  auto qStream1 = device.getOutputQueue("stream1");
56  auto qStream2 = device.getOutputQueue("stream2");
57  while(true) {
58  cv::imshow("stream1", qStream1->get<dai::ImgFrame>()->getCvFrame());
59  cv::imshow("stream2", qStream2->get<dai::ImgFrame>()->getCvFrame());
60  if(cv::waitKey(1) == 'q') {
61  break;
62  }
63  }
64 }
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::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
depthai.hpp
dai::node::Script::setScript
void setScript(const std::string &script, const std::string &name="")
Definition: Script.cpp:32
dai::Pipeline::create
std::shared_ptr< N > create()
Definition: Pipeline.hpp:145
dai::node::Script
Definition: Script.hpp:15
dai::ImgFrame::getCvFrame
void getCvFrame(T...)
Definition: ImgFrame.hpp:222
dai::ImgFrame
Definition: ImgFrame.hpp:25
main
int main()
Definition: script_forward_frames.cpp:6
dai::Device
Definition: Device.hpp:21
std
Definition: Node.hpp:366
dai::node::ColorCamera::setIspScale
void setIspScale(int numerator, int denominator)
Definition: ColorCamera.cpp:157
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