10 #ifndef CTRL_UTILS_OPENCV_H_
11 #define CTRL_UTILS_OPENCV_H_
13 #include <opencv2/opencv.hpp>
26 inline void FromString(
const std::string& str, cv::Mat& image) {
28 std::stringstream ss(str);
49 std::vector<unsigned char> buffer(size);
50 ss.read(
reinterpret_cast<char*
>(buffer.data()), size);
53 cv::imdecode(buffer, cv::IMREAD_UNCHANGED, &image);
59 image.create(rows, cols, type);
62 ss.read(
reinterpret_cast<char*
>(image.data),
63 image.total() * image.elemSize());
74 inline std::string ToString(
const cv::Mat& image) {
77 ss << image.type() <<
" ";
79 std::vector<unsigned char> buffer;
80 switch (image.type()) {
90 cv::imencode(
".png", image, buffer);
93 ss << buffer.size() <<
" ";
94 ss.write(
reinterpret_cast<char*
>(buffer.data()), buffer.size());
101 cv::imencode(
".exr", image, buffer);
104 ss << buffer.size() <<
" ";
105 ss.write(
reinterpret_cast<char*
>(buffer.data()), buffer.size());
109 ss << image.rows <<
" " << image.cols <<
" ";
112 ss.write(
reinterpret_cast<char*
>(image.data),
113 image.total() * image.elemSize());
Definition: ctrl_utils.cc:18
nlohmann::json FromString(const std::string &str)
Definition: json.h:27