warp_mesh.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 // Inludes common necessary includes for development using depthai library
4 #include "depthai/depthai.hpp"
5 
6 int main() {
7  using namespace std;
8 
9  // Create pipeline
10  dai::Pipeline pipeline;
11 
12  auto camRgb = pipeline.create<dai::node::ColorCamera>();
13  camRgb->setPreviewSize(496, 496);
14  camRgb->setInterleaved(false);
15  auto maxFrameSize = camRgb->getPreviewWidth() * camRgb->getPreviewHeight() * 3;
16 
17  // Warp preview frame 1
18  auto warp1 = pipeline.create<dai::node::Warp>();
19  // Create a custom warp mesh
20  dai::Point2f tl(20, 20);
21  dai::Point2f tr(460, 20);
22  dai::Point2f ml(100, 250);
23  dai::Point2f mr(400, 250);
24  dai::Point2f bl(20, 460);
25  dai::Point2f br(460, 460);
26  warp1->setWarpMesh({tl, tr, ml, mr, bl, br}, 2, 3);
27  constexpr std::tuple<int, int> WARP1_OUTPUT_FRAME_SIZE = {992, 500};
28  warp1->setOutputSize(WARP1_OUTPUT_FRAME_SIZE);
29  warp1->setMaxOutputFrameSize(std::get<0>(WARP1_OUTPUT_FRAME_SIZE) * std::get<1>(WARP1_OUTPUT_FRAME_SIZE) * 3);
30  warp1->setInterpolation(dai::Interpolation::NEAREST_NEIGHBOR);
31  warp1->setHwIds({1});
32 
33  camRgb->preview.link(warp1->inputImage);
34  auto xout1 = pipeline.create<dai::node::XLinkOut>();
35  xout1->setStreamName("out1");
36  warp1->out.link(xout1->input);
37 
38  // Warp preview frame 2
39  auto warp2 = pipeline.create<dai::node::Warp>();
40  // Create a custom warp mesh
41  // clang-format off
42  std::vector<dai::Point2f> mesh2 = {
43  {20, 20}, {250, 100}, {460, 20},
44  {100,250}, {250, 250}, {400, 250},
45  {20, 480}, {250,400}, {460,480}
46  };
47  // clang-format on
48  warp2->setWarpMesh(mesh2, 3, 3);
49  warp2->setMaxOutputFrameSize(maxFrameSize);
50  warp2->setInterpolation(dai::Interpolation::BICUBIC);
51  warp2->setHwIds({2});
52 
53  camRgb->preview.link(warp2->inputImage);
54  auto xout2 = pipeline.create<dai::node::XLinkOut>();
55  xout2->setStreamName("out2");
56  warp2->out.link(xout2->input);
57 
58  dai::Device device(pipeline);
59  auto q1 = device.getOutputQueue("out1", 8, false);
60  auto q2 = device.getOutputQueue("out2", 8, false);
61  while(true) {
62  auto in1 = q1->get<dai::ImgFrame>();
63  if(in1) {
64  cv::imshow("Warped preview 1", in1->getCvFrame());
65  }
66  auto in2 = q2->get<dai::ImgFrame>();
67  if(in2) {
68  cv::imshow("Warped preview 2", in2->getCvFrame());
69  }
70  int key = cv::waitKey(1);
71  if(key == 'q' || key == 'Q') return 0;
72  }
73  return 0;
74 }
dai::node::XLinkOut
XLinkOut node. Sends messages over XLink.
Definition: XLinkOut.hpp:14
dai::Interpolation::NEAREST_NEIGHBOR
@ NEAREST_NEIGHBOR
main
int main()
Definition: warp_mesh.cpp:6
dai::Pipeline
Represents the pipeline, set of nodes and connections between them.
Definition: Pipeline.hpp:100
dai::Interpolation::BICUBIC
@ BICUBIC
tl
Definition: 3rdparty/tl/optional.hpp:106
dai::node::ColorCamera
ColorCamera node. For use with color sensors.
Definition: ColorCamera.hpp:16
dai::Point2f
Definition: Point2f.hpp:16
dai::Device::getOutputQueue
std::shared_ptr< DataOutputQueue > getOutputQueue(const std::string &name)
Definition: Device.cpp:86
depthai.hpp
dai::node::Warp
Warp node. Capability to crop, resize, warp, ... incoming image frames.
Definition: Warp.hpp:16
dai::node::Warp::setWarpMesh
void setWarpMesh(const float *meshData, int numMeshPoints, int width, int height)
Definition: Warp.cpp:34
dai::Pipeline::create
std::shared_ptr< N > create()
Definition: Pipeline.hpp:145
dai::ImgFrame
Definition: ImgFrame.hpp:25
dai::Device
Definition: Device.hpp:21
std
Definition: Node.hpp:366
dai::node::ColorCamera::setPreviewSize
void setPreviewSize(int width, int height)
Set preview output size.
Definition: ColorCamera.cpp:121
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