-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIO.h
53 lines (43 loc) · 1.39 KB
/
IO.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
#pragma once
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <opencv2/core.hpp>
#include <fstream>
BOOST_SERIALIZATION_SPLIT_FREE(cv::Mat)
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);
}
}
}
void saveMat(std::string save_name, cv::Mat m);
void readMat(std::string name, cv::Mat& mat);
void write2obj(std::string input_folder, std::string outname, std::vector<unsigned int>& ks,
std::vector<unsigned int>& ids, int pairsize);