forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgcodecs.cpp
51 lines (38 loc) · 1.41 KB
/
imgcodecs.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
#include "imgcodecs.h"
// Image
Mat Image_IMRead(const char* filename, int flags) {
cv::Mat img = cv::imread(filename, flags);
return new cv::Mat(img);
}
bool Image_IMWrite(const char* filename, Mat img) {
return cv::imwrite(filename, *img);
}
bool Image_IMWrite_WithParams(const char* filename, Mat img, IntVector params) {
std::vector<int> compression_params;
for (int i = 0, *v = params.val; i < params.length; ++v, ++i) {
compression_params.push_back(*v);
}
return cv::imwrite(filename, *img, compression_params);
}
struct ByteArray Image_IMEncode(const char* fileExt, Mat img) {
std::vector<uchar> data;
cv::imencode(fileExt, *img, data);
return toByteArray(reinterpret_cast<const char*>(&data[0]), data.size());
}
struct ByteArray Image_IMEncode_WithParams(const char* fileExt, Mat img, IntVector params) {
std::vector<uchar> data;
std::vector<int> compression_params;
for (int i = 0, *v = params.val; i < params.length; ++v, ++i) {
compression_params.push_back(*v);
}
cv::imencode(fileExt, *img, data, compression_params);
return toByteArray(reinterpret_cast<const char*>(&data[0]), data.size());
}
Mat Image_IMDecode(ByteArray buf, int flags) {
std::vector<char> data;
for (size_t i = 0; i < buf.length; i++) {
data.push_back(buf.data[i]);
}
cv::Mat img = cv::imdecode(data, flags);
return new cv::Mat(img);
}