opencv编解码base64字符串

cpp-base64代码地址:
https://github.com/ReneNyffenegger/cpp-base64
下载仓库,并将base64.h,Base64.cpp 加入代码中,

将Mat对象编码为base64字符串

Mat img= imread("xxx.png");
std::vector<uchar> buf;
cv::imencode(".png", img, buf);
auto *data_ptr = reinterpret_cast<unsigned char*>(buf.data());
std::string encode_str = base64_encode(data_ptr, buf.size());
std::cout <<"base64: " encode_str << std::endl;

将base64解码为Mat对象

string dec_str = base64_decode(encode_str);
std::vector<uchar> data(dec_str.begin(), dec_str.end());
cv::Mat image = cv::imdecode(cv::Mat(data), 1);

参考:
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp/