35 #ifndef CALIBRATION_YAML_HH 36 #define CALIBRATION_YAML_HH 44 std::ostream&
writeMatrix (std::ostream& stream, std::string
const& name, uint32_t rows, uint32_t columns, T
const* data)
46 stream << name <<
": !!opencv-matrix\n";
47 stream <<
" rows: " << rows <<
"\n";
48 stream <<
" cols: " << columns <<
"\n";
50 stream <<
" data: [ ";
52 stream.precision (17);
53 stream << std::scientific;
54 for (uint32_t i = 0; i < rows; i++)
61 for (uint32_t j = 0; j < columns; j++)
67 stream << data[i * columns + j];
85 std::string
const&
value ()
const 95 for (std::string::const_iterator iter = expect.
value ().begin (); iter != expect.
value ().end (); ++iter)
102 if (stream.get () != *iter)
104 stream.clear (std::ios_base::failbit);
113 std::istream&
operator >> (std::istream& stream, std::vector<T>& data)
116 while (stream.good ())
126 stream.putback (input);
130 data.push_back (value);
139 else if (input !=
',')
141 stream.clear (std::ios_base::failbit);
149 std::istream&
parseYaml (std::istream& stream, std::map<std::string, std::vector<float> >& data)
152 while (stream.good ())
159 std::getline (stream, comment);
162 stream.putback (input);
170 if (name[name.size () - 1] !=
':')
172 stream.clear (std::ios_base::failbit);
175 name.resize (name.size () - 1);
177 std::vector<float> arrayContents;
178 arrayContents.clear ();
184 stream >> arrayContents;
188 stream.putback (input);
191 uint32_t columns = 0;
192 stream >>
Expect (
"!!opencv-matrix");
193 stream >>
Expect (
"rows:") >> rows;
194 stream >>
Expect (
"cols:") >> columns;
195 stream >>
Expect (
"dt: d");
196 stream >>
Expect (
"data: [") >> arrayContents;
201 data.insert (std::make_pair(name, arrayContents));
205 fprintf (stderr,
"Error parsing data near array \"%s\"", name.c_str());
212 #endif //CALIBRATION_YAML_HH std::istream & operator>>(std::istream &stream, Expect const &expect)
std::ostream & writeMatrix(std::ostream &stream, std::string const &name, uint32_t rows, uint32_t columns, T const *data)
std::string const & value() const
std::istream & parseYaml(std::istream &stream, std::map< std::string, std::vector< float > > &data)
Expect(std::string const &value)