2020-01-04 13:10:36 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2021-09-01 20:08:47 +00:00
|
|
|
void Image_IMEncode(const char* fileExt, Mat img, void* vector) {
|
|
|
|
auto vectorPtr = reinterpret_cast<std::vector<uchar> *>(vector);
|
|
|
|
cv::imencode(fileExt, *img, *vectorPtr);
|
2020-01-04 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 20:08:47 +00:00
|
|
|
void Image_IMEncode_WithParams(const char* fileExt, Mat img, IntVector params, void* vector) {
|
|
|
|
auto vectorPtr = reinterpret_cast<std::vector<uchar> *>(vector);
|
2020-01-04 13:10:36 +00:00
|
|
|
std::vector<int> compression_params;
|
|
|
|
|
|
|
|
for (int i = 0, *v = params.val; i < params.length; ++v, ++i) {
|
|
|
|
compression_params.push_back(*v);
|
|
|
|
}
|
|
|
|
|
2021-09-01 20:08:47 +00:00
|
|
|
cv::imencode(fileExt, *img, *vectorPtr, compression_params);
|
2020-01-04 13:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2024-04-02 17:24:34 +00:00
|
|
|
|
|
|
|
void Image_IMDecodeIntoMat(ByteArray buf, int flags, Mat dest) {
|
|
|
|
std::vector<uchar> data(buf.data, buf.data + buf.length);
|
|
|
|
cv::imdecode(data, flags, dest);
|
|
|
|
}
|