NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

FgOpenCVSerialization.h
1#pragma once
2
3#include <boost/archive/binary_iarchive.hpp>
4#include <boost/archive/binary_oarchive.hpp>
5#include <boost/serialization/binary_object.hpp>
6#include <boost/serialization/nvp.hpp>
7#include <boost/serialization/vector.hpp>
8#include <opencv2/opencv.hpp>
9
10 namespace boost
11{
12 namespace serialization
13 {
14 template<class Archive>
15 void serialize(Archive &ar, cv::Mat& mat, const unsigned int)
16 {
17 int cols, rows, channels, type;
18 bool continuous;
19
20 if (Archive::is_saving::value) {
21 channels = mat.channels();
22 cols = mat.cols; rows = mat.rows; type = mat.type();
23 continuous = mat.isContinuous();
24 }
25
26 ar& BOOST_SERIALIZATION_NVP(cols);
27 ar& BOOST_SERIALIZATION_NVP(rows);
28 ar& BOOST_SERIALIZATION_NVP(channels);
29 ar& BOOST_SERIALIZATION_NVP(type);
30 ar& BOOST_SERIALIZATION_NVP(continuous);
31
32 if (Archive::is_loading::value)
33 mat.create(rows, cols, CV_MAKETYPE(type, channels));
34
35 if (continuous) {
36 const unsigned int data_size = rows * cols * mat.elemSize();
37 ar & boost::serialization::make_array(mat.ptr(), data_size);
38 }
39 else {
40 const unsigned int row_size = cols*mat.elemSize();
41 for (int i = 0; i < rows; i++) {
42 ar & boost::serialization::make_array(mat.ptr(i), row_size);
43 }
44 }
45 }
46 }
47}