#include #include #include #include "ffi.hpp" using MatResult = FFIResult; using namespace std; extern "C" { FFIResult cv_imwrite(cv::Mat *img, const char *path) { return try_execute([&]() { cv::imwrite(path, *img); return 0; }, -1); } MatResult cv_imread(const char *path, int flags) { return try_execute([&]() { return new cv::Mat(cv::imread(path, flags)); }, nullptr); } FFIResult cv_imencode(cv::Mat *img, std::vector *dst, char *ext) { return try_execute([&]() { cv::imencode(ext, *img, *dst); return 0; }, -1); } MatResult cv_imdecode(uchar *data, int size, int flags) { vector bytes(data, data + size); return try_execute([&]() { return new cv::Mat(cv::imdecode(bytes, flags)); }, nullptr); } std::vector *cv_new_bytes() { return new std::vector(); } uchar *cv_bytes_data(std::vector *pointer) { return pointer->data(); } std::size_t cv_bytes_size(std::vector *pointer) { return pointer->size(); } void cv_release_bytes(std::vector *pointer) { delete pointer; } }