9#ifndef H5EASY_BITS_OPENCV_HPP
10#define H5EASY_BITS_OPENCV_HPP
12#include "../H5Easy.hpp"
13#include "H5Easy_misc.hpp"
14#include "H5Easy_scalar.hpp"
23struct is_opencv : std::false_type {};
25struct is_opencv<cv::Mat_<T>> : std::true_type {};
28struct io_impl<T, typename std::enable_if<is_opencv<T>::value>::type> {
30 inline static std::vector<size_t> shape(
const T& data)
32 return std::vector<size_t>{
static_cast<size_t>(data.rows),
33 static_cast<size_t>(data.cols)};
36 inline static std::vector<int> shape(
const File& file,
37 const std::string& path,
38 std::vector<size_t> dims)
40 if (dims.size() == 1) {
41 return std::vector<int>{
static_cast<int>(dims[0]), 1ul};
43 if (dims.size() == 2) {
44 return std::vector<int>{
static_cast<int>(dims[0]),
45 static_cast<int>(dims[1])};
48 throw detail::error(file, path,
"H5Easy::load: Inconsistent rank");
51 inline static DataSet dump(File& file,
52 const std::string& path,
54 const DumpOptions& options) {
55 using value_type =
typename T::value_type;
56 DataSet dataset = initDataset<value_type>(file, path, shape(data), options);
57 std::vector<value_type> v(data.begin(), data.end());
58 dataset.write_raw(v.data());
59 if (options.flush()) {
65 inline static T load(
const File& file,
const std::string& path) {
66 using value_type =
typename T::value_type;
67 DataSet dataset = file.getDataSet(path);
68 std::vector<int> dims = shape(file, path, dataset.getDimensions());
69 T data(dims[0], dims[1]);
70 dataset.read(
reinterpret_cast<value_type*
>(data.data));
74 inline static Attribute dumpAttribute(File& file,
75 const std::string& path,
76 const std::string& key,
78 const DumpOptions& options) {
79 using value_type =
typename T::value_type;
80 Attribute attribute = initAttribute<value_type>(file, path, key, shape(data), options);
81 std::vector<value_type> v(data.begin(), data.end());
82 attribute.write_raw(v.data());
83 if (options.flush()) {
89 inline static T loadAttribute(
const File& file,
90 const std::string& path,
91 const std::string& key) {
92 using value_type =
typename T::value_type;
93 DataSet dataset = file.getDataSet(path);
94 Attribute attribute = dataset.getAttribute(key);
95 DataSpace dataspace = attribute.getSpace();
96 std::vector<int> dims = shape(file, path, dataspace.getDimensions());
97 T data(dims[0], dims[1]);
98 attribute.read(
reinterpret_cast<value_type*
>(data.data));