DaoAI World C++ SDK industrial 2.24.8.0
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1// Copyright (c) 2024, DaoAI Robotics. All rights reserved.
2// Version: 0.0.0
3
4#pragma once
5#include "API_EXPORT.h"
6#include <iostream>
7#include <vector>
8#include "config.h"
9#include <memory>
10#include <variant>
11#include <cmath>
12#include <map>
13namespace DaoAI
14{
15 namespace DeepLearning
16 {
17 enum class DeviceType
18 {
19 CPU, GPU
20 };
21
22 class Point
23 {
24 public:
25 DAOAI_API Point(const float& x, const float& y, const float& confidence = 0, const std::string& label = "");
26 DAOAI_API Point(const float& x, const float& y, const std::string& label);
29
30 // overload operator<< to print out polygon object
31 friend DAOAI_API std::ostream& operator<<(std::ostream& ss, const Point& point);
32
33 DAOAI_API Point operator+(const Point& point) const;
34 DAOAI_API Point operator-(const Point& point) const;
35
36 float x = 0, y = 0, confidence = 0;
37 std::string label = "";
38 };
39
40 class Polygon
41 {
42 public:
43 DAOAI_API Polygon(const std::vector<Point>& points);
46
47 // overload operator<< to print out polygon object
48 friend DAOAI_API std::ostream& operator<<(std::ostream& ss, const Polygon& polygon);
49
50 // overload operator<< to print out polygon object
51 friend DAOAI_API std::stringstream& operator<<(std::stringstream& ss, const Polygon& polygon);
52
53 std::vector<Point> points;
54 };
55
56 class Box
57 {
58 public:
59
60 enum class Type
61 {
62 XYXY, XYWH
63 };
64
69
75 DAOAI_API Box(const Point& p1, const Point& p2, const float& angle = NAN);
76
84 DAOAI_API Box(const float& a1, const float& a2, const float& a3, const float& a4, const float& angle = NAN, const Type& type = Type::XYXY);
85
87
88#ifndef BUILD_INFERNCE_CLIENT
93#endif // !BUILD_INFERNCE_CLIENT
94
95 DAOAI_API std::string toString() const;
96
97 // overload operator<< to print out polygon object
98 friend DAOAI_API std::ostream& operator<<(std::ostream& ss, const Box& box);
99
100 // overload operator<< to print out polygon object
101 friend DAOAI_API std::stringstream& operator<<(std::stringstream& ss, const Box& box);
102
106 DAOAI_API float h() const;
107
111 DAOAI_API float w() const;
112
116 DAOAI_API float x1() const;
117
121 DAOAI_API float y1() const;
122
126 DAOAI_API float x2() const;
127
131 DAOAI_API float y2() const;
132
136 DAOAI_API float angle() const;
137
141 DAOAI_API float area() const;
142
143#ifndef BUILD_INFERENCE_CLIENT
147 DAOAI_API float iou(const Box& box) const;
148
152 DAOAI_API Box intersect(const Box& box) const;
153
157 DAOAI_API Box merge(const Box& box) const;
158
159
165 DAOAI_API bool contains(const Box& box) const;
166
167#endif // !BUILD_INFERENCE_CLIENT
168
173 DAOAI_API Box toType(const Type& type) const;
174
175 std::vector<float> data;
177 };
178
179#ifndef BUILD_INFERENCE_CLIENT
180 class Image
181 {
182 public:
183 enum class Type
184 {
186 };
187
193
201 DAOAI_API Image(const int& image_height, const int& image_width, const Image::Type& type, void* data);
202
210 DAOAI_API Image(const int& image_height, const int& image_width, const Image::Type& type, std::shared_ptr<uint8_t[]> data_ptr);
211
212
217 DAOAI_API Image(const std::string& file_path);
218
219 DAOAI_API virtual ~Image();
220
225 DAOAI_API void save(const std::string& file_path) const;
226
227 // create a deep copy of the Image object
229
230 DAOAI_API uint8_t* getData() const;
231
234 private:
235 uint8_t *data;
236 std::shared_ptr<uint8_t[]> data_ptr;
237
238 };
239
240 class Mask
241 {
242 public:
244
245 DAOAI_API Mask(const Image& image);
246
247 Mask(const Image& image, const Box& location, const int& image_height, const int& image_width);
248
250
251 DAOAI_API Mask merge(const Mask& mask) const;
252
253 DAOAI_API std::vector<Polygon> toPolygons() const;
254
255 DAOAI_API long long area() const;
256
258
260 private:
261 std::vector<Image> image_data;
262 std::vector<Box> locations;
263 };
264#else
265 class Mask
266 {
267 public:
268 Mask();
269 Mask(const std::string& base64_image_data);
270 Mask(const std::vector<Polygon> polygon_data);
271
272 // either polygon_data or base64_image_data should be non-null
273 std::unique_ptr<std::vector<Polygon>> polygon_data;
274 std::unique_ptr<std::string> base64_image_data;
275 };
276#endif // !BUILD_INFERENCE_CLIENT
277 }
278}
#define DAOAI_API
Definition API_EXPORT.h:13
Definition common.h:57
DAOAI_API Polygon toPolygon() const
Convert to polygon type considering box angle.
Type type
Definition common.h:176
DAOAI_API std::string toString() const
DAOAI_API float h() const
Bounding box height.
std::vector< float > data
Definition common.h:175
DAOAI_API float x1() const
The x coordinate of top-left corner.
Type
Definition common.h:61
DAOAI_API bool contains(const Box &box) const
Check if this box contains another box.
DAOAI_API float w() const
Bounding box width.
DAOAI_API Box intersect(const Box &box) const
Calculate insection box.
DAOAI_API float area() const
The area of the box.
DAOAI_API float iou(const Box &box) const
Calculate iou with a box.
DAOAI_API Box()
Construct a empty box.
DAOAI_API Box toType(const Type &type) const
Convert to different box type.
friend DAOAI_API std::ostream & operator<<(std::ostream &ss, const Box &box)
DAOAI_API float x2() const
The x coordinate of bottom-right corner.
DAOAI_API Box merge(const Box &box) const
Calculate union box.
DAOAI_API float angle() const
The rotate angle of he bounding box.
DAOAI_API Box(const Point &p1, const Point &p2, const float &angle=NAN)
Construct a box given the top-left and right-bottom points.
DAOAI_API float y2() const
The y coordinate of bottom-right corner.
DAOAI_API Box(const float &a1, const float &a2, const float &a3, const float &a4, const float &angle=NAN, const Type &type=Type::XYXY)
Construct a box given the coordinates of top-left and bottom-right points.
friend DAOAI_API std::stringstream & operator<<(std::stringstream &ss, const Box &box)
DAOAI_API float y1() const
The y coordinate of top-left corner.
Definition common.h:181
DAOAI_API uint8_t * getData() const
DAOAI_API Image()
Default constructor for Image object.
DAOAI_API Image clone() const
Type type
Definition common.h:233
DAOAI_API Image(const int &image_height, const int &image_width, const Image::Type &type, void *data)
Construct image from data buffer.
Type
Definition common.h:184
virtual DAOAI_API ~Image()
DAOAI_API Image(const std::string &file_path)
Construct image from file path.
int height
Definition common.h:232
DAOAI_API void save(const std::string &file_path) const
Save the image to a file.
int width
Definition common.h:232
DAOAI_API Image(const int &image_height, const int &image_width, const Image::Type &type, std::shared_ptr< uint8_t[]> data_ptr)
Construct image from data buffer.
Definition common.h:241
DAOAI_API Mask(const Image &image)
DAOAI_API long long area() const
Mask(const Image &image, const Box &location, const int &image_height, const int &image_width)
int height
Definition common.h:259
DAOAI_API Mask merge(const Mask &mask) const
DAOAI_API std::vector< Polygon > toPolygons() const
DAOAI_API Image toImage() const
int width
Definition common.h:259
Definition common.h:23
DAOAI_API Point operator-(const Point &point) const
friend DAOAI_API std::ostream & operator<<(std::ostream &ss, const Point &point)
DAOAI_API Point(const float &x, const float &y, const std::string &label)
std::string label
Definition common.h:37
DAOAI_API Point operator+(const Point &point) const
DAOAI_API Point(const float &x, const float &y, const float &confidence=0, const std::string &label="")
float x
Definition common.h:36
float y
Definition common.h:36
float confidence
Definition common.h:36
Definition common.h:41
DAOAI_API Polygon(const std::vector< Point > &points)
friend DAOAI_API std::stringstream & operator<<(std::stringstream &ss, const Polygon &polygon)
std::vector< Point > points
Definition common.h:53
friend DAOAI_API std::ostream & operator<<(std::ostream &ss, const Polygon &polygon)
DeviceType
Definition common.h:18
Definition common.h:14