forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.cpp
92 lines (75 loc) · 2.38 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
#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_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_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_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 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;
}