forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.cpp
181 lines (145 loc) · 4.61 KB
/
core.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "core.h"
#include <string.h>
// Mat_New creates a new empty Mat
Mat Mat_New() {
return new cv::Mat();
}
// Mat_NewWithSize creates a new Mat with a specific size dimension and number of channels.
Mat Mat_NewWithSize(int rows, int cols, int type) {
return new cv::Mat(rows, cols, type, 0.0);
}
// Mat_NewFromScalar creates a new Mat from a Scalar. Intended to be used
// for Mat comparison operation such as InRange.
Mat Mat_NewFromScalar(Scalar ar, int type) {
cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4);
return new cv::Mat(1, 1, type, c);
}
// Mat_Close deletes an existing Mat
void Mat_Close(Mat m) {
delete m;
}
// Mat_Empty tests if a Mat is empty
int Mat_Empty(Mat m) {
return m->empty();
}
// Mat_Clone returns a clone of this Mat
Mat Mat_Clone(Mat m) {
return new cv::Mat(m->clone());
}
// Mat_CopyTo copies this Mat to another Mat.
void Mat_CopyTo(Mat m, Mat dst) {
m->copyTo(*dst);
}
// Mat_Region returns a Mat of a region of another Mat
Mat Mat_Region(Mat m, Rect r) {
return new cv::Mat(*m, cv::Rect(r.x, r.y, r.width, r.height));
}
// Mat_Mean calculates the mean value M of array elements, independently for each channel, and return it as Scalar vector
// TODO pass second paramter with mask
Scalar Mat_Mean(Mat m) {
cv::Scalar c = cv::mean(*m);
Scalar scal = Scalar();
scal.val1 = c.val[0];
scal.val2 = c.val[1];
scal.val3 = c.val[2];
scal.val4 = c.val[3];
return scal;
}
void LUT(Mat src, Mat lut, Mat dst) {
cv::LUT(*src, *lut, *dst);
}
// Mat_Rows returns how many rows in this Mat.
int Mat_Rows(Mat m) {
return m->rows;
}
// Mat_Cols returns how many columns in this Mat.
int Mat_Cols(Mat m) {
return m->cols;
}
// Mat_GetUChar returns a specific row/col value from this Mat expecting
// each element to contain a schar aka CV_8U.
uint8_t Mat_GetUChar(Mat m, int row, int col) {
return m->at<uchar>(row, col);
}
// Mat_GetSChar returns a specific row/col value from this Mat expecting
// each element to contain a schar aka CV_8S.
int8_t Mat_GetSChar(Mat m, int row, int col) {
return m->at<schar>(row, col);
}
// Mat_GetShort returns a specific row/col value from this Mat expecting
// each element to contain a short aka CV_16S.
int16_t Mat_GetShort(Mat m, int row, int col) {
return m->at<short>(row, col);
}
// Mat_GetInt returns a specific row/col value from this Mat expecting
// each element to contain an int aka CV_32S.
int32_t Mat_GetInt(Mat m, int row, int col) {
return m->at<int>(row, col);
}
// Mat_GetFloat returns a specific row/col value from this Mat expecting
// each element to contain a float aka CV_32F.
float Mat_GetFloat(Mat m, int row, int col) {
return m->at<float>(row, col);
}
// Mat_GetDouble returns a specific row/col value from this Mat expecting
// each element to contain a double aka CV_64F.
double Mat_GetDouble(Mat m, int row, int col) {
return m->at<double>(row, col);
}
void Mat_AbsDiff(Mat src1, Mat src2, Mat dst) {
cv::absdiff(*src1, *src2, *dst);
}
void Mat_Add(Mat src1, Mat src2, Mat dst) {
cv::add(*src1, *src2, *dst);
}
void Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst) {
cv::addWeighted(*src1, alpha, *src2, beta, gamma, *dst);
}
void Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst) {
cv::bitwise_and(*src1, *src2, *dst);
}
void Mat_BitwiseNot(Mat src1, Mat dst) {
cv::bitwise_not(*src1, *dst);
}
void Mat_BitwiseOr(Mat src1, Mat src2, Mat dst) {
cv::bitwise_or(*src1, *src2, *dst);
}
void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst) {
cv::bitwise_xor(*src1, *src2, *dst);
}
void Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst) {
cv::inRange(*src, *lowerb, *upperb, *dst);
}
int Mat_GetOptimalDFTSize(int vecsize) {
return cv::getOptimalDFTSize(vecsize);
}
void Mat_DFT(Mat m, Mat dst) {
cv::dft(*m, *dst);
}
void Mat_Merge(Mat m, size_t count, Mat dst) {
cv::merge(m, count, *dst);
}
void Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ) {
cv:normalize(*src, *dst, alpha, beta, typ);
}
// TermCriteria_New creates a new TermCriteria
TermCriteria TermCriteria_New(int typ, int maxCount, double epsilon) {
return new cv::TermCriteria(typ, maxCount, epsilon);
}
void Contours_Close(struct Contours cs) {
delete cs.contours;
}
void KeyPoints_Close(struct KeyPoints ks) {
delete ks.keypoints;
}
void Rects_Close(struct Rects rs) {
delete rs.rects;
}
void ByteArray_Release(struct ByteArray buf) {
delete[] buf.data;
}
struct ByteArray toByteArray(const char* buf, int len) {
ByteArray ret = {new char[len], len};
memcpy(ret.data, buf, len);
return ret;
}