Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
AffineTransform.h
1#pragma once
2
3#include "Module.h"
4#include <map>
5#include <variant>
6#include <string>
7#ifdef APRA_HAS_CUDA_HEADERS
8#include "CudaCommon.h"
9#endif
10
12class DeatilCUDA;
13class DetailDMA;
14class DetailHost;
15class DetailGPU;
16
18{
19public:
32
38
39 // Default constructor for declarative pipeline support
41 {
43 angle = 0.0;
44 x = 0;
45 y = 0;
46 scale = 1.0;
47 }
48
49 AffineTransformProps(TransformType _type, double _angle, int _x = 0, int _y = 0, double _scale = 1.0)
50 {
51 if (_type != TransformType::USING_OPENCV)
52 {
53 throw AIPException(AIP_FATAL, "This constructor only supports Opencv");
54 }
55 angle = _angle;
56 x = _x;
57 y = _y;
58 scale = _scale;
59 type = _type;
60 }
61
62 // Declarative pipeline property binding
63 void applyProperties(const std::map<std::string, std::variant<int64_t, double, bool, std::string>>& props)
64 {
65 for (const auto& [key, value] : props) {
66 if (key == "angle") {
67 if (std::holds_alternative<double>(value)) {
68 angle = std::get<double>(value);
69 } else if (std::holds_alternative<int64_t>(value)) {
70 angle = static_cast<double>(std::get<int64_t>(value));
71 }
72 } else if (key == "x") {
73 if (std::holds_alternative<int64_t>(value)) {
74 x = static_cast<int>(std::get<int64_t>(value));
75 }
76 } else if (key == "y") {
77 if (std::holds_alternative<int64_t>(value)) {
78 y = static_cast<int>(std::get<int64_t>(value));
79 }
80 } else if (key == "scale") {
81 if (std::holds_alternative<double>(value)) {
82 scale = std::get<double>(value);
83 } else if (std::holds_alternative<int64_t>(value)) {
84 scale = static_cast<double>(std::get<int64_t>(value));
85 }
86 } else if (key == "transformType") {
87 if (std::holds_alternative<std::string>(value)) {
88 const auto& strVal = std::get<std::string>(value);
89 if (strVal == "USING_OPENCV") {
91 }
92 // USING_NPPI not supported via TOML (requires cudastream_sp)
93 }
94 }
95 }
96 }
97
98 std::variant<int64_t, double, bool, std::string> getProperty(const std::string& name) const
99 {
100 if (name == "angle") return angle;
101 if (name == "x") return static_cast<int64_t>(x);
102 if (name == "y") return static_cast<int64_t>(y);
103 if (name == "scale") return scale;
104 if (name == "transformType") return type == TransformType::USING_OPENCV ? std::string("USING_OPENCV") : std::string("USING_NPPI");
105 return int64_t(0);
106 }
107#ifdef APRA_HAS_CUDA_HEADERS
108 AffineTransformProps(TransformType _type, Interpolation _interpolation, cudastream_sp &_stream, double _angle, int _x=0, int _y=0, double _scale = 1.0)
109 {
110 if (_type != TransformType::USING_NPPI)
111 {
112 throw AIPException(AIP_FATAL, "This constructor only supports using NPPI");
113 }
114 stream = _stream;
115 angle = _angle;
116 x = _x;
117 y = _y;
118 scale = _scale;
119 interpolation = _interpolation;
120 type = _type;
121 }
122#endif
123
124 int x = 0;
125 int y = 0;
126 double scale = 1.0;
127 double angle;
128#ifdef APRA_HAS_CUDA_HEADERS
129 cudastream_sp stream;
130#endif
133
135 {
136 return ModuleProps::getSerializeSize() + sizeof(int) * 2 + sizeof(double) + sizeof(float) + sizeof(interpolation) + sizeof(type);
137 }
138
139private:
141
142 template <class Archive>
143 void serialize(Archive &ar, const unsigned int version)
144 {
145 ar &boost::serialization::base_object<ModuleProps>(*this);
146 ar &angle &x &y &scale ;
147 ar& interpolation;
148 ar& type;
149 }
150};
151
153{
154
155public:
157 virtual ~AffineTransform();
158 bool init();
159 bool term();
160 void setProps(AffineTransformProps &props);
162
163protected:
164 bool process(frame_container &frames);
165 bool processSOS(frame_sp &frame);
166 bool validateInputPins();
167 bool validateOutputPins();
168 void addInputPin(framemetadata_sp &metadata, string &pinId); // throws exception if validation fails
169 bool shouldTriggerSOS();
170 bool processEOS(string &pinId);
172 bool handlePropsChange(frame_sp& frame);
173 boost::shared_ptr<DetailMemoryAbstract> mDetail;
174};
Definition AffineTransform.h:18
int y
Definition AffineTransform.h:125
int x
Definition AffineTransform.h:124
AffineTransformProps(TransformType _type, double _angle, int _x=0, int _y=0, double _scale=1.0)
Definition AffineTransform.h:49
std::variant< int64_t, double, bool, std::string > getProperty(const std::string &name) const
Definition AffineTransform.h:98
TransformType
Definition AffineTransform.h:34
@ USING_OPENCV
Definition AffineTransform.h:35
@ USING_NPPI
Definition AffineTransform.h:36
Interpolation
Definition AffineTransform.h:20
@ LANCZOS
Definition AffineTransform.h:29
@ CUBIC2P_BSPLINE
Definition AffineTransform.h:25
@ LINEAR
Definition AffineTransform.h:22
@ LANCZOS3_ADVANCED
Definition AffineTransform.h:30
@ NN
Definition AffineTransform.h:21
@ UNDEFINED
Definition AffineTransform.h:24
@ CUBIC
Definition AffineTransform.h:23
@ CUBIC2P_B05C03
Definition AffineTransform.h:27
@ CUBIC2P_CATMULLROM
Definition AffineTransform.h:26
@ SUPER
Definition AffineTransform.h:28
void applyProperties(const std::map< std::string, std::variant< int64_t, double, bool, std::string > > &props)
Definition AffineTransform.h:63
TransformType type
Definition AffineTransform.h:132
void serialize(Archive &ar, const unsigned int version)
Definition AffineTransform.h:143
double scale
Definition AffineTransform.h:126
friend class boost::serialization::access
Definition AffineTransform.h:140
double angle
Definition AffineTransform.h:127
Interpolation interpolation
Definition AffineTransform.h:131
size_t getSerializeSize()
Definition AffineTransform.h:134
AffineTransformProps()
Definition AffineTransform.h:40
Definition AffineTransform.h:153
void addInputPin(framemetadata_sp &metadata, string &pinId)
Definition AffineTransform.cpp:541
virtual ~AffineTransform()
Definition AffineTransform.cpp:447
AffineTransform(AffineTransformProps props)
Definition AffineTransform.cpp:445
AffineTransformProps getProps()
Definition AffineTransform.cpp:634
bool init()
Definition AffineTransform.cpp:576
bool validateOutputPins()
Definition AffineTransform.cpp:508
bool processEOS(string &pinId)
Definition AffineTransform.cpp:623
bool process(frame_container &frames)
Definition AffineTransform.cpp:591
bool term()
Definition AffineTransform.cpp:585
bool shouldTriggerSOS()
Definition AffineTransform.cpp:618
boost::shared_ptr< DetailMemoryAbstract > mDetail
Definition AffineTransform.h:173
bool handlePropsChange(frame_sp &frame)
Definition AffineTransform.cpp:640
AffineTransformProps mProp
Definition AffineTransform.h:171
bool validateInputPins()
Definition AffineTransform.cpp:449
void setProps(AffineTransformProps &props)
Definition AffineTransform.cpp:629
bool processSOS(frame_sp &frame)
Definition AffineTransform.cpp:609
Definition AffineTransform.cpp:369
Definition AffineTransform.cpp:348
Definition AffineTransform.cpp:158
Definition AffineTransform.cpp:390
Definition AffineTransform.cpp:24
Definition Module.h:33
virtual size_t getSerializeSize()
Definition Module.h:101
Definition Module.h:151