30 saveToConfigFile(
"", cfg);
41 out << focalLengthMeters;
42 for (
unsigned int k = 0; k < 5; k++) out << dist[k];
43 out << intrinsicParams;
45 out << nrows << ncols;
58 in >> focalLengthMeters;
60 for (
unsigned int k = 0; k < 5; k++) in >> dist[k];
62 in >> intrinsicParams;
67 in >> __distortionParams;
93 const char* fields[] = {
"K",
"dist",
"f",
"ncols",
"nrows"};
94 mexplus::MxArray params_struct(
95 mexplus::MxArray::Struct(
sizeof(fields) /
sizeof(fields[0]), fields));
98 params_struct.set(
"f", this->focalLengthMeters);
99 params_struct.set(
"ncols", this->ncols);
100 params_struct.set(
"nrows", this->nrows);
101 return params_struct.release();
121 section,
"resolution",
122 format(
"[%u %u]", (
unsigned int)ncols, (
unsigned int)nrows));
130 "[%e %e %e %e %e]", dist[0], dist[1], dist[2], dist[3], dist[4]));
131 if (focalLengthMeters != 0)
132 cfg.
write(section,
"focal_length", focalLengthMeters);
141 vector<uint64_t> out_res;
142 cfg.
read_vector(section,
"resolution", vector<uint64_t>(), out_res,
true);
143 if (out_res.size() != 2)
148 double fx, fy, cx, cy;
154 if (fx < 2.0) fx *= ncols;
155 if (fy < 2.0) fy *= nrows;
156 if (cx < 2.0) cx *= ncols;
157 if (cy < 2.0) cy *= nrows;
159 setIntrinsicParamsFromValues(fx, fy, cx, cy);
163 if (dists.size() != 4 && dists.size() != 5)
167 for (CVectorDouble::Index i = 0; i < dists.size(); i++) dist[i] = dists[i];
170 cfg.
read_double(section,
"focal_length", 0,
false );
178 if (ncols == new_ncols && nrows == new_nrows)
return;
180 ASSERT_(new_nrows > 0 && new_ncols > 0)
182 const double prev_aspect_ratio = ncols / double(nrows);
183 const double new_aspect_ratio = new_ncols / double(new_nrows);
186 std::abs(prev_aspect_ratio - new_aspect_ratio) < 1e-3,
187 "TCamera: Trying to scale camera parameters for a resolution of " 188 "different aspect ratio.")
190 const double K = new_ncols / double(ncols);
196 intrinsicParams(0, 0) *= K;
197 intrinsicParams(1, 1) *= K;
198 intrinsicParams(0, 2) *= K;
199 intrinsicParams(1, 2) *= K;
207 return a.ncols ==
b.ncols &&
a.nrows ==
b.nrows &&
208 a.intrinsicParams ==
b.intrinsicParams &&
a.dist ==
b.dist &&
209 a.focalLengthMeters ==
b.focalLengthMeters;
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
mxArray * convertToMatlab(const Eigen::EigenBase< Derived > &mat)
Convert vectors, arrays and matrices into Matlab vectors/matrices.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define THROW_EXCEPTION(msg)
void scaleToResolution(unsigned int new_ncols, unsigned int new_nrows)
Rescale all the parameters for a new camera resolution (it raises an exception if the aspect ratio is...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
bool operator==(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
This class allows loading and storing values and vectors of different types from a configuration text...
This class implements a config file-like interface over a memory-stored string list.
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
bool operator!=(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void read_vector(const std::string §ion, const std::string &name, const VECTOR_TYPE &defaultValue, VECTOR_TYPE &outValues, bool failIfNotFound=false) const
Reads a configuration parameter of type vector, stored in the file as a string: "[v1 v2 v3 ...
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
GLsizei const GLchar ** string
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
void write(const std::string §ion, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
virtual mxArray * writeToMatlab() const
Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class.
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
This file implements matrix/vector text and binary serialization.
dynamic_vector< double > CVectorDouble
Column vector, like Eigen::MatrixXd, but automatically initialized to zeros since construction...
#define ASSERTMSG_(f, __ERROR_MSG)
GLubyte GLubyte GLubyte a
void loadFromConfigFile(const std::string §ion, const mrpt::utils::CConfigFileBase &cfg)
Load all the params from a config source, in the format used in saveToConfigFile(), that is:
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
Structure to hold the parameters of a pinhole camera model.
void saveToConfigFile(const std::string §ion, mrpt::utils::CConfigFileBase &cfg) const
Save as a config block: