BoostArchiver.h
Go to the documentation of this file.
1 /*
2  * map save/load extension for ORB_SLAM2
3  * This header contains boost headers needed by serialization
4  *
5  * object to save:
6  * - KeyFrame
7  * - KeyFrameDatabase
8  * - Map
9  * - MapPoint
10  */
11 #ifndef BOOST_ARCHIVER_H
12 #define BOOST_ARCHIVER_H
13 #include <boost/serialization/list.hpp>
14 #include <boost/serialization/vector.hpp>
15 #include <boost/serialization/set.hpp>
16 // set serialization needed by KeyFrame::mspChildrens ...
17 #include <boost/serialization/map.hpp>
18 // map serialization needed by KeyFrame::mConnectedKeyFrameWeights ...
19 #include <boost/archive/binary_oarchive.hpp>
20 #include <boost/archive/binary_iarchive.hpp>
21 #include <boost/serialization/split_free.hpp>
22 #include <boost/serialization/base_object.hpp>
23 // base object needed by DBoW2::BowVector and DBoW2::FeatureVector
24 #include <opencv2/core/core.hpp>
25 
28 
29 BOOST_SERIALIZATION_SPLIT_FREE(::cv::Mat)
30 namespace boost{
31  namespace serialization {
32 
33  /* serialization for DBoW2 BowVector */
34  template<class Archive>
35  void serialize(Archive &ar, DBoW2::BowVector &BowVec, const unsigned int file_version)
36  {
37  ar & boost::serialization::base_object< std::map<DBoW2::WordId, DBoW2::WordValue> >(BowVec);
38  }
39  /* serialization for DBoW2 FeatureVector */
40  template<class Archive>
41  void serialize(Archive &ar, DBoW2::FeatureVector &FeatVec, const unsigned int file_version)
42  {
43  ar & boost::serialization::base_object<std::map<DBoW2::NodeId, std::vector<unsigned int> > >(FeatVec);
44  }
45 
46  /* serialization for CV KeyPoint */
47  template<class Archive>
48  void serialize(Archive &ar, ::cv::KeyPoint &kf, const unsigned int file_version)
49  {
50  ar & kf.angle;
51  ar & kf.class_id;
52  ar & kf.octave;
53  ar & kf.response;
54  ar & kf.response;
55  ar & kf.pt.x;
56  ar & kf.pt.y;
57  }
58  /* serialization for CV Mat */
59  template<class Archive>
60  void save(Archive &ar, const ::cv::Mat &m, const unsigned int file_version)
61  {
62  cv::Mat m_ = m;
63  if (!m.isContinuous())
64  m_ = m.clone();
65  size_t elem_size = m_.elemSize();
66  size_t elem_type = m_.type();
67  ar & m_.cols;
68  ar & m_.rows;
69  ar & elem_size;
70  ar & elem_type;
71 
72  const size_t data_size = m_.cols * m_.rows * elem_size;
73 
74  ar & boost::serialization::make_array(m_.ptr(), data_size);
75  }
76  template<class Archive>
77  void load(Archive & ar, ::cv::Mat& m, const unsigned int version)
78  {
79  int cols, rows;
80  size_t elem_size, elem_type;
81 
82  ar & cols;
83  ar & rows;
84  ar & elem_size;
85  ar & elem_type;
86 
87  m.create(rows, cols, elem_type);
88  size_t data_size = m.cols * m.rows * elem_size;
89 
90  ar & boost::serialization::make_array(m.ptr(), data_size);
91  }
92  }
93 }
94 // TODO: boost::iostream zlib compressed binary format
95 #endif // BOOST_ARCHIVER_H
void load(Archive &ar,::cv::Mat &m, const unsigned int version)
Definition: BoostArchiver.h:77
void serialize(Archive &ar,::cv::KeyPoint &kf, const unsigned int file_version)
Definition: BoostArchiver.h:48
Vector of words to represent images.
Definition: BowVector.h:56
Vector of nodes with indexes of local features.
Definition: FeatureVector.h:21
void save(Archive &ar, const ::cv::Mat &m, const unsigned int file_version)
Definition: BoostArchiver.h:60


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05