9 #ifndef H5EASY_BITS_OPENCV_HPP
10 #define H5EASY_BITS_OPENCV_HPP
12 #include "../H5Easy.hpp"
23 struct is_opencv : std::false_type {};
25 struct is_opencv<cv::Mat_<T>> : std::true_type {};
28 struct 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,
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,
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()) {
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));
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()) {
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));
106 #endif // H5_USE_OPENCV
107 #endif // H5EASY_BITS_OPENCV_HPP