12 std::ofstream output(filename);
13 output << j.dump(compact ? -1 : 4);
14 }
else if(ext ==
"cbor") {
15 std::vector<std::uint8_t> cbor_data = json::to_cbor(j);
16 std::ofstream output(filename, std::ios_base::out | std::ios_base::binary);
17 output.write(reinterpret_cast<const std::ofstream::char_type*>(cbor_data.data()), cbor_data.size());
19 throw std::runtime_error(
"unknown json filename extension");
26 std::ifstream input(filename);
35 int cols = j[0].size();
36 cv::Mat_<real> mat(rows, cols);
37 for(
int row = 0; row <
rows; ++row)
for(
int col = 0; col <
cols; ++col)
38 mat(row, col) = j[row][col].get<
real>();
42 cv::Mat_<real> mat(rows, 1);
43 for(
int row = 0; row <
rows; ++row)
44 mat(row, 0) = j[row].get<
real>();
52 json j = json::array();
54 for(
int row = 0; row < mat.rows; ++row) j.push_back(mat(row, 0));
56 for(
int row = 0; row < mat.rows; ++row) {
57 json j_row = json::array();
58 for(
int col = 0; col < mat.cols; ++col) j_row.push_back(mat(row, col));
cv::Mat_< real > decode_mat(const json &j)
void export_json_file(const json &j, const std::string &filename, bool compact)
std::string file_name_extension(const std::string &filename)
json import_json_file(const std::string &filename)
json encode_mat_(const cv::Mat_< real > &mat)