19 #ifndef SNARK_IMAGING_CVMAT_SERIALIZATION_H_
20 #define SNARK_IMAGING_CVMAT_SERIALIZATION_H_
24 #include <boost/date_time/posix_time/posix_time.hpp>
25 #include <opencv2/core/core.hpp>
26 #include <comma/base/types.h>
27 #include <comma/csv/binary.h>
28 #include <comma/visiting/traits.h>
31 namespace snark{
namespace cv_mat {
39 boost::posix_time::ptime timestamp;
46 header(
const cv::Mat& m );
47 header(
const std::pair< boost::posix_time::ptime, cv::Mat >& p );
60 options() : no_header(
false ), header_only(
false ) {}
62 static std::string
usage();
63 static std::string type_usage();
70 serialization(
const std::string& fields,
const comma::csv::format& format,
bool headerOnly =
false,
const header& default_header =
header() );
76 std::size_t put(
const std::pair< boost::posix_time::ptime, cv::Mat >& m,
char* buf )
const;
80 std::size_t
get( std::pair< boost::posix_time::ptime, cv::Mat >& m,
const char* buf )
const;
83 std::pair< boost::posix_time::ptime, cv::Mat >
get(
const char* buf )
const;
86 header get_header(
const char* buf )
const;
89 static const std::string& usage();
92 std::size_t size(
const cv::Mat& m )
const;
95 std::size_t size(
const std::pair< boost::posix_time::ptime, cv::Mat >& m )
const;
98 std::pair< boost::posix_time::ptime, cv::Mat > read( std::istream& is );
101 void write( std::ostream& os,
const std::pair< boost::posix_time::ptime, cv::Mat >& m );
104 boost::scoped_ptr< comma::csv::binary< header > > m_binary;
105 std::vector< char > m_buffer;
112 namespace comma {
namespace visiting {
114 template <>
struct traits< snark::cv_mat::serialization::header >
116 template <
typename K,
typename V >
119 v.apply(
"t", h.timestamp );
120 v.apply(
"rows", h.rows );
121 v.apply(
"cols", h.cols );
122 v.apply(
"type", h.type );
123 v.apply(
"size", h.
size );
126 template <
typename K,
typename V >
129 v.apply(
"t", h.timestamp );
130 v.apply(
"rows", h.rows );
131 v.apply(
"cols", h.cols );
132 v.apply(
"type", h.type );
133 v.apply(
"size", h.
size );
137 template <>
struct traits< snark::cv_mat::serialization::options >
139 template <
typename K,
typename V >
142 v.apply(
"fields", h.fields );
143 v.apply(
"rows", h.rows );
144 v.apply(
"cols", h.cols );
145 v.apply(
"type", h.type );
146 v.apply(
"no-header", h.no_header );
147 v.apply(
"header-only", h.header_only );
150 template <
typename K,
typename V >
153 v.apply(
"fields", h.fields );
154 v.apply(
"rows", h.rows );
155 v.apply(
"cols", h.cols );
156 v.apply(
"type", h.type );
157 v.apply(
"no-header", h.no_header );
158 v.apply(
"header-only", h.header_only );
164 #endif // SNARK_IMAGING_CVMAT_SERIALIZATION_H_