image_manip_node_test.cpp
Go to the documentation of this file.
1 #include <chrono>
2 
3 #include "depthai/depthai.hpp"
4 
6 // TEST
7 // ImageManipNode test
9 int main() {
10  using namespace std;
11  using namespace std::chrono;
12  using namespace std::chrono_literals;
13 
14  // Create pipeline
15  dai::Pipeline p;
16  auto xin = p.create<dai::node::XLinkIn>();
17  auto imageManip = p.create<dai::node::ImageManip>();
18  auto xout = p.create<dai::node::XLinkOut>();
19 
20  // resize
21  const int originalWidth = 640, originalHeight = 360;
22  const int width = 337, height = 225;
23 
24  // Properties
25  xin->setStreamName("in");
26  xout->setStreamName("out");
27  imageManip->initialConfig.setResize(width, height);
28 
29  // Link plugins CAM -> XLINK
30  xin->out.link(imageManip->inputImage);
31  imageManip->out.link(xout->input);
32 
33  // Try connecting to an available device
34  dai::Device d(p);
35 
36  auto in = d.getInputQueue("in");
37  auto out = d.getOutputQueue("out");
38 
39  // Send 10 messages
40  for(int i = 0; i < 10; i++) {
41  // Create 'rgb interleaved' frame
42  dai::ImgFrame inFrame;
43  inFrame.getData().resize(originalWidth * originalHeight * 3);
44  inFrame.setWidth(originalWidth);
45  inFrame.setHeight(originalHeight);
47 
48  // Send the frame
49  in->send(inFrame);
50 
51  // Retrieve the resized frame
52  auto outFrame = out->get<dai::ImgFrame>();
53 
54  // Check that out frame is resized
55  if(outFrame->getWidth() != width || outFrame->getHeight() != height) {
56  return -1;
57  }
58  }
59 
60  // Exit with success error code
61  return 0;
62 }
dai::node::XLinkIn::out
Output out
Definition: XLinkIn.hpp:25
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::RGB888p
@ RGB888p
dai::Buffer::getData
std::vector< std::uint8_t > & getData() const
Get non-owning reference to internal buffer.
Definition: Buffer.cpp:13
dai::ImgFrame::setWidth
ImgFrame & setWidth(unsigned int width)
Definition: pipeline/datatype/ImgFrame.cpp:99
dai::Device::getOutputQueue
std::shared_ptr< DataOutputQueue > getOutputQueue(const std::string &name)
Definition: Device.cpp:86
depthai.hpp
dai::Pipeline::create
std::shared_ptr< N > create()
Definition: Pipeline.hpp:145
dai::ImgFrame
Definition: ImgFrame.hpp:25
main
int main()
Definition: image_manip_node_test.cpp:9
dai::node::ImageManip
ImageManip node. Capability to crop, resize, warp, ... incoming image frames.
Definition: ImageManip.hpp:15
dai::Device
Definition: Device.hpp:21
dai::ImgFrame::setType
ImgFrame & setType(Type type)
Definition: pipeline/datatype/ImgFrame.cpp:118
dai::ImgFrame::setHeight
ImgFrame & setHeight(unsigned int height)
Definition: pipeline/datatype/ImgFrame.cpp:105
std
Definition: Node.hpp:366
dai::node::XLinkIn
XLinkIn node. Receives messages over XLink.
Definition: XLinkIn.hpp:14
dai::Device::getInputQueue
std::shared_ptr< DataInputQueue > getInputQueue(const std::string &name)
Definition: Device.cpp:120
dai::Node::Output::link
void link(const Input &in)
Definition: Node.cpp:84
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