-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcommon.h
120 lines (101 loc) · 2.11 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef CV_RS_COMMON_H
#define CV_RS_COMMON_H
#include <cstddef>
#include <functional>
#include <opencv2/core.hpp>
typedef struct {
int x;
int y;
} Point2i;
typedef struct {
float x;
float y;
} Point2f;
typedef struct {
int width;
int height;
} Size2i;
typedef struct {
float width;
float height;
} Size2f;
typedef struct {
int x;
int y;
int width;
int height;
} Rect;
typedef struct {
Point2f center;
Size2f size;
float angle;
} RotatedRect;
typedef struct {
int v0;
int v1;
int v2;
int v3;
} Scalar;
typedef struct {
Point2f pt;
float size;
float angle;
float response;
int octave;
int class_id;
} KeyPoint;
typedef struct {
float distance;
int imgIdx;
int queryIdx;
int trainIdx;
} DMatch;
typedef struct {
const char* value;
} CDisposableString;
// Caller is responsible for disposing `error` field
template <typename T>
struct Result {
T value;
CDisposableString error;
static Result<T> FromFunction(std::function<T()> function) {
T value;
char* error = nullptr;
try {
value = function();
} catch (cv::Exception& e) {
const char* err_msg = e.what();
auto len = std::strlen(err_msg);
error = new char[len + 1];
std::strcpy(error, err_msg);
}
return Result<T>{value, CDisposableString{error}};
}
};
// Caller is responsible for disposing `error` field
struct EmptyResult {
CDisposableString error;
static EmptyResult FromFunction(std::function<void()> function) {
char* error = nullptr;
try {
function();
} catch (cv::Exception& e) {
const char* err_msg = e.what();
auto len = std::strlen(err_msg);
error = new char[len + 1];
std::strcpy(error, err_msg);
}
return EmptyResult{CDisposableString{error}};
}
};
template <typename T>
struct CVec {
T* array;
size_t size;
};
template <typename T>
struct COption {
bool hasValue;
T value;
};
#endif // CV_RS_COMMON_H