-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserialization.h
More file actions
53 lines (41 loc) · 1.48 KB
/
Copy pathserialization.h
File metadata and controls
53 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <fstream>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
BOOST_SERIALIZATION_SPLIT_FREE(cv::Mat)
namespace boost {
namespace serialization {
/*** Mat ***/
template<class Archive>
void save(Archive & ar, const cv::Mat& m, const unsigned int version)
{
size_t elemSize = m.elemSize(), elemType = m.type();
ar & m.cols;
ar & m.rows;
ar & elemSize;
ar & elemType; // element type.
size_t dataSize = m.cols * m.rows * m.elemSize();
for (size_t dc = 0; dc < dataSize; ++dc) {
ar & m.data[dc];
}
}
template<class Archive>
void load(Archive & ar, cv::Mat& m, const unsigned int version)
{
int cols, rows;
size_t elemSize, elemType;
ar & cols;
ar & rows;
ar & elemSize;
ar & elemType;
m.create(rows, cols, elemType);
size_t dataSize = m.cols * m.rows * elemSize;
std::cout << "reading matrix data rows, cols, elemSize, type, datasize: (" << m.rows << "," << m.cols << "," << m.elemSize() << "," << m.type() << "," << dataSize << ")" << std::endl;
for (size_t dc = 0; dc < dataSize; ++dc) {
ar & m.data[dc];
}
}
}
}