Go to the documentation of this file.00001 #ifndef cvmat_serialization_H
00002 #define cvmat_serialization_H
00003
00004
00005
00006
00007
00008 #include <opencv2/opencv.hpp>
00009 #include <boost/serialization/split_free.hpp>
00010 #include <boost/serialization/vector.hpp>
00011
00012 BOOST_SERIALIZATION_SPLIT_FREE(::cv::Mat)
00013 namespace boost {
00014 namespace serialization {
00015
00017 template<class Archive>
00018 void save(Archive & ar, const ::cv::Mat& m, const unsigned int version)
00019 {
00020 size_t elem_size = m.elemSize();
00021 size_t elem_type = m.type();
00022
00023 ar & m.cols;
00024 ar & m.rows;
00025 ar & elem_size;
00026 ar & elem_type;
00027
00028 const size_t data_size = m.cols * m.rows * elem_size;
00029 ar & boost::serialization::make_array(m.ptr(), data_size);
00030 }
00031
00033 template<class Archive>
00034 void load(Archive & ar, ::cv::Mat& m, const unsigned int version)
00035 {
00036 int cols, rows;
00037 size_t elem_size, elem_type;
00038
00039 ar & cols;
00040 ar & rows;
00041 ar & elem_size;
00042 ar & elem_type;
00043
00044 m.create(rows, cols, elem_type);
00045
00046 size_t data_size = m.cols * m.rows * elem_size;
00047 ar & boost::serialization::make_array(m.ptr(), data_size);
00048 }
00049
00050 }
00051 }
00052
00053 #endif
00054