31 saveToConfigFile(
"", cfg);
38 out << focalLengthMeters;
39 for (
unsigned int k = 0; k < 5; k++) out << dist[k];
40 out << intrinsicParams;
42 out << nrows << ncols;
52 in >> focalLengthMeters;
54 for (
unsigned int k = 0; k < 5; k++) in >> dist[k];
56 in >> intrinsicParams;
61 in >> __distortionParams;
89 const char* fields[] = {
"K",
"dist",
"f",
"ncols",
"nrows"};
90 mexplus::MxArray params_struct(
91 mexplus::MxArray::Struct(
sizeof(fields) /
sizeof(fields[0]), fields));
94 params_struct.set(
"f", this->focalLengthMeters);
95 params_struct.set(
"ncols", this->ncols);
96 params_struct.set(
"nrows", this->nrows);
97 return params_struct.release();
119 section,
"resolution",
120 format(
"[%u %u]", (
unsigned int)ncols, (
unsigned int)nrows));
128 "[%e %e %e %e %e]", dist[0], dist[1], dist[2], dist[3], dist[4]));
129 if (focalLengthMeters != 0)
130 cfg.
write(section,
"focal_length", focalLengthMeters);
139 vector<uint64_t> out_res;
140 cfg.
read_vector(section,
"resolution", vector<uint64_t>(), out_res,
true);
141 if (out_res.size() != 2)
146 double fx, fy, cx, cy;
152 if (fx < 2.0) fx *= ncols;
153 if (fy < 2.0) fy *= nrows;
154 if (cx < 2.0) cx *= ncols;
155 if (cy < 2.0) cy *= nrows;
157 setIntrinsicParamsFromValues(fx, fy, cx, cy);
161 if (dists.
size() != 4 && dists.
size() != 5)
168 cfg.
read_double(section,
"focal_length", 0,
false );
176 if (ncols == new_ncols && nrows == new_nrows)
return;
178 ASSERT_(new_nrows > 0 && new_ncols > 0);
180 const double prev_aspect_ratio = ncols / double(nrows);
181 const double new_aspect_ratio = new_ncols / double(new_nrows);
184 std::abs(prev_aspect_ratio - new_aspect_ratio) < 1e-3,
185 "TCamera: Trying to scale camera parameters for a resolution of " 186 "different aspect ratio.");
188 const double K = new_ncols / double(ncols);
194 intrinsicParams(0, 0) *= K;
195 intrinsicParams(1, 1) *= K;
196 intrinsicParams(0, 2) *= K;
197 intrinsicParams(1, 2) *= K;
205 return a.ncols ==
b.ncols &&
a.nrows ==
b.nrows &&
206 a.intrinsicParams ==
b.intrinsicParams &&
a.dist ==
b.dist &&
207 a.focalLengthMeters ==
b.focalLengthMeters;
This class implements a config file-like interface over a memory-stored string list.
A compile-time fixed-size numeric matrix container.
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...
#define THROW_EXCEPTION(msg)
mxArray * convertToMatlab(const Eigen::EigenBase< Derived > &mat)
Convert vectors, arrays and matrices into Matlab vectors/matrices.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
void loadFromConfigFile(const std::string §ion, const mrpt::config::CConfigFileBase &cfg)
Load all the params from a config source, in the format used in saveToConfigFile(), that is:
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define ASSERT_(f)
Defines an assertion mechanism.
This class allows loading and storing values and vectors of different types from a configuration text...
This base provides a set of functions for maths stuff.
CVectorDynamic< double > CVectorDouble
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
Structure to hold the parameters of a pinhole camera model.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
GLsizei const GLchar ** string
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
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())
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Virtual base class for "archives": classes abstracting I/O streams.
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.
void saveToConfigFile(const std::string §ion, mrpt::config::CConfigFileBase &cfg) const
Save as a config block:
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
This file implements matrix/vector text and binary serialization.
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
bool operator!=(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
GLubyte GLubyte GLubyte a
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 ...