-
Notifications
You must be signed in to change notification settings - Fork 867
/
imgcodecs.cpp
82 lines (64 loc) · 2.28 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
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
#include <stdlib.h>
#include "imgcodecs.h"
// Image
Mat Image_IMRead(const char* filename, int flags) {
cv::Mat img = cv::imread(filename, flags);
return new cv::Mat(img);
}
Mats Image_IMReadMulti(const char* filename, int flags) {
std::vector<cv::Mat> dst;
Mats m = Mats();
bool b = cv::imreadmulti(filename, dst, flags);
if (b) {
m.mats = new Mat[dst.size()];
for (size_t i = 0; i < dst.size(); ++i) {
m.mats[i] = new cv::Mat(dst[i]);
}
m.length = (int)dst.size();
}
return m;
}
Mats Image_IMReadMulti_WithParams(const char* filename, int start, int count, int flags) {
std::vector<cv::Mat> dst;
auto m = Mats();
auto b = cv::imreadmulti(filename, dst, start, count, flags);
if (b) {
m.mats = new Mat[dst.size()];
for (size_t i = 0; i < dst.size(); ++i) {
m.mats[i] = new cv::Mat(dst[i]);
}
m.length = (int)dst.size();
}
return m;
}
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);
}
void Image_IMEncode(const char* fileExt, Mat img, void* vector) {
auto vectorPtr = reinterpret_cast<std::vector<uchar> *>(vector);
cv::imencode(fileExt, *img, *vectorPtr);
}
void Image_IMEncode_WithParams(const char* fileExt, Mat img, IntVector params, void* vector) {
auto vectorPtr = reinterpret_cast<std::vector<uchar> *>(vector);
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, *vectorPtr, compression_params);
}
Mat Image_IMDecode(ByteArray buf, int flags) {
std::vector<uchar> data(buf.data, buf.data + buf.length);
cv::Mat img = cv::imdecode(data, flags);
return new cv::Mat(img);
}
void Image_IMDecodeIntoMat(ByteArray buf, int flags, Mat dest) {
std::vector<uchar> data(buf.data, buf.data + buf.length);
cv::imdecode(data, flags, dest);
}