-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUtil.h
95 lines (74 loc) · 2.46 KB
/
Util.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
#ifndef OPENCV_NDK_UTIL_H
#define OPENCV_NDK_UTIL_H
#include <unistd.h>
#include <android/log.h>
// used to get logcat outputs which can be regex filtered by the LOG_TAG we give
// So in Logcat you can filter this example by putting OpenCV-NDK
#define LOG_TAG "NativeBarcodeTracker"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define ASSERT(cond, fmt, ...) \
if (!(cond)) { \
__android_log_assert(#cond, LOG_TAG, fmt, ##__VA_ARGS__); \
}
// A Data Structure to communicate resolution between camera and ImageReader
struct ImageFormat {
int32_t width;
int32_t height;
int32_t format; // ex) YUV_420
};
/**
* A helper class to assist image size comparison, by comparing the absolute
* size
* regardless of the portrait or landscape mode.
*/
class Display_Dimension {
public:
Display_Dimension(int32_t w, int32_t h) : w_(w), h_(h), portrait_(false) {
if (h > w) {
// make it landscape
w_ = h;
h_ = w;
portrait_ = true;
}
}
Display_Dimension(const Display_Dimension &other) {
w_ = other.w_;
h_ = other.h_;
portrait_ = other.portrait_;
}
Display_Dimension(void) {
w_ = 0;
h_ = 0;
portrait_ = false;
}
Display_Dimension &operator=(const Display_Dimension &other) {
w_ = other.w_;
h_ = other.h_;
portrait_ = other.portrait_;
return (*this);
}
bool IsSameRatio(Display_Dimension &other) {
return (w_ * other.h_ == h_ * other.w_);
}
bool operator>(Display_Dimension &other) {
return (w_ >= other.w_ & h_ >= other.h_);
}
bool operator==(Display_Dimension &other) {
return (w_ == other.w_ && h_ == other.h_ && portrait_ == other.portrait_);
}
Display_Dimension operator-(Display_Dimension &other) {
Display_Dimension delta(w_ - other.w_, h_ - other.h_);
return delta;
}
void Flip(void) { portrait_ = !portrait_; }
bool IsPortrait(void) { return portrait_; }
int32_t width(void) { return w_; }
int32_t height(void) { return h_; }
int32_t org_width(void) { return (portrait_ ? h_ : w_); }
int32_t org_height(void) { return (portrait_ ? w_ : h_); }
private:
int32_t w_, h_;
bool portrait_;
};
#endif // OPENCV_NDK_UTIL_H