cast_diff.cpp
Go to the documentation of this file.
1 #include <depthai/depthai.hpp>
2 #include <filesystem>
3 #include <opencv2/opencv.hpp>
4 
5 constexpr int SHAPE = 720;
6 
7 int main() {
9 
10  auto camRgb = p.create<dai::node::ColorCamera>();
11  auto nn = p.create<dai::node::NeuralNetwork>();
12  auto script = p.create<dai::node::Script>();
13  auto rgbXout = p.create<dai::node::XLinkOut>();
14  auto cast = p.create<dai::node::Cast>();
15  auto castXout = p.create<dai::node::XLinkOut>();
16 
17  camRgb->setVideoSize(SHAPE, SHAPE);
18  camRgb->setPreviewSize(SHAPE, SHAPE);
19  camRgb->setInterleaved(false);
20 
21  nn->setBlobPath(BLOB_PATH);
22 
23  script->setScript(R"(
24  old = node.io['in'].get()
25  while True:
26  frame = node.io['in'].get()
27  node.io['img1'].send(old)
28  node.io['img2'].send(frame)
29  old = frame
30  )");
31 
32  rgbXout->setStreamName("rgb");
33  castXout->setStreamName("cast");
34  cast->setOutputFrameType(dai::RawImgFrame::Type::GRAY8);
35 
36  // Linking
37  camRgb->preview.link(script->inputs["in"]);
38  script->outputs["img1"].link(nn->inputs["img1"]);
39  script->outputs["img2"].link(nn->inputs["img2"]);
40  camRgb->video.link(rgbXout->input);
41  nn->out.link(cast->input);
42  cast->output.link(castXout->input);
43 
44  // Pipeline is defined, now we can connect to the device
45  dai::Device device(p);
46  auto qCam = device.getOutputQueue("rgb", 4, false);
47  auto qCast = device.getOutputQueue("cast", 4, false);
48 
49  while(true) {
50  auto colorFrame = qCam->get<dai::ImgFrame>();
51  if(colorFrame) {
52  cv::imshow("Color", colorFrame->getCvFrame());
53  }
54 
55  auto inCast = qCast->get<dai::ImgFrame>();
56  if(inCast) {
57  cv::imshow("Diff", inCast->getCvFrame());
58  }
59 
60  if(cv::waitKey(1) == 'q') {
61  break;
62  }
63  }
64 
65  return 0;
66 }
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::RawImgFrame::Type::GRAY8
@ GRAY8
dai::node::Cast
Cast node.
Definition: Cast.hpp:14
dai::node::NeuralNetwork::inputs
InputMap inputs
Definition: NeuralNetwork.hpp:52
SHAPE
constexpr int SHAPE
Definition: cast_diff.cpp:5
dai::node::ColorCamera
ColorCamera node. For use with color sensors.
Definition: ColorCamera.hpp:16
dai::node::NeuralNetwork
NeuralNetwork node. Runs a neural inference on input data.
Definition: NeuralNetwork.hpp:18
dai::node::Cast::input
Input input
Definition: Cast.hpp:24
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::node::Script
Definition: Script.hpp:15
dai::ImgFrame
Definition: ImgFrame.hpp:25
dai::Device
Definition: Device.hpp:21
main
int main()
Definition: cast_diff.cpp:7


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