-
Notifications
You must be signed in to change notification settings - Fork 37
/
MatSerilization.h
146 lines (119 loc) · 3.89 KB
/
MatSerilization.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef __MATSERIALIZATION_H_
#define __MATSERIALIZATION_H_
#include <opencv2/opencv.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/base_object.hpp>
//BOOST_CLASS_EXPORT_GUID(::cv::Matx<double,1,4>);
BOOST_SERIALIZATION_SPLIT_FREE(::cv::Mat)
BOOST_SERIALIZATION_SPLIT_FREE(::cv::Point2f)
BOOST_SERIALIZATION_SPLIT_FREE(::cv::KeyPoint)
//BOOST_SERIALIZATION_SPLIT_FREE(::cv::Matx)
namespace boost
{
namespace serialization
{
/** Serialization support for cv::Mat */
template<class Archive>
void save(Archive & ar, const ::cv::Mat& m, const unsigned int version)
{
size_t elem_size = m.elemSize();
size_t elem_type = m.type();
ar & m.cols;
ar & m.rows;
ar & elem_size;
ar & elem_type;
const size_t data_size = m.cols * m.rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
} /** Serialization support for cv::Mat */
template <class Archive>
void load(Archive & ar, ::cv::Mat& m, const unsigned int version)
{
int cols, rows;
size_t elem_size, elem_type;
ar & cols;
ar & rows;
ar & elem_size;
ar & elem_type;
m.create(rows, cols, elem_type);
size_t data_size = m.cols * m.rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
}
template<class Archive>
void save(Archive & ar, const::cv::Point2f& m, const unsigned int version)
{
ar&m.x;
ar&m.y;
}
template<class Archive>
void load(Archive & ar, ::cv::Point2f& m, const unsigned int version)
{
ar&m.x;
ar&m.y;
}
template<class Archive>
void save(Archive & ar, const ::cv::KeyPoint& m, const unsigned int version)
{
ar & m.angle;
ar & m.class_id;
ar & m.octave;
ar & m.pt;
ar & m.response;
ar & m.size;
}
template<class Archive>
void load(Archive & ar, ::cv::KeyPoint& m, const unsigned int version)
{
ar & m.angle;
ar & m.class_id;
ar & m.octave;
ar & m.pt;
ar & m.response;
ar & m.size;
}
template<class Archive, int m, int n>
inline void serialize(
Archive & ar,
cv::Matx<bool, m, n> & t,
const unsigned int file_version
)
{
boost::serialization::split_free(ar, t, file_version);
}
template<class Archive, typename _Tp, int m, int n>
void serialize(Archive& ar, ::cv::Matx<_Tp, m, n>& _m, const unsigned int /*version*/) {
ar & make_array<_Tp>(_m.val,m*n);
}
template<class Archive, typename _Tp, int cn>
void serialize(Archive& ar, ::cv::Vec<_Tp ,cn>& _m, const unsigned int /*version*/) {
ar & make_array<_Tp>(_m.val, cn);
}
template<class Archive, typename _Tp>
void serialize(Archive& ar, ::cv::Scalar_<_Tp>& _m, const unsigned int /*version*/) {
ar & make_array<_Tp>(_m.val,_m.channels);
}
}}
#endif//!__MATSERIALIZATION_H_
/************************************************************************/
/* std::vector < std::pair<std::string, cv::Scalar>> outlist;
for (auto i = all_feature_map.begin(); i != all_feature_map.end();i++)
{
cv::Scalar tmp_scalar = cv::sum(cv::abs(i->second - Fc6FeatureMat1));
outlist.push_back(std::pair<std::string, cv::Scalar>(i->first,tmp_scalar));
}
std::sort(outlist.begin(), outlist.end(), compare);
input_file.close();
std::ofstream osf(last_result_filename, std::ios::out);
boost::archive::xml_oarchive xmloa1(osf);
cv::Scalar tmp2;
tmp2.val[0] = 0.3;
tmp2.val[1] = 0.1;
tmp2.val[2] = 0.1;
tmp2.val[3] = 0.1;
xmloa1 << BOOST_SERIALIZATION_NVP(outlist); */
/************************************************************************/