29 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++)
63 in >> intrinsicParams;
68 in >> __distortionParams;
94 const char* fields[] = {
"K",
"dist",
"f",
"ncols",
"nrows"};
95 mexplus::MxArray params_struct( 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();
119 cfg.
write(section,
"resolution",
format(
"[%u %u]",(
unsigned int)ncols,(
unsigned int)nrows));
124 cfg.
write(section,
"dist",
format(
"[%e %e %e %e %e]", dist[0],dist[1],dist[2],dist[3],dist[4] ) );
125 if (focalLengthMeters!=0) cfg.
write(section,
"focal_length", focalLengthMeters );
132 vector<uint64_t> out_res;
133 cfg.
read_vector(section,
"resolution",vector<uint64_t>(),out_res,
true);
134 if (out_res.size()!=2)
THROW_EXCEPTION(
"Expected 2-length vector in field 'resolution'");
138 double fx, fy, cx, cy;
144 if( fx < 2.0 ) fx *= ncols;
145 if( fy < 2.0 ) fy *= nrows;
146 if( cx < 2.0 ) cx *= ncols;
147 if( cy < 2.0 ) cy *= nrows;
149 setIntrinsicParamsFromValues( fx, fy, cx, cy );
153 if (dists.size()!=4 && dists.size()!=5)
THROW_EXCEPTION(
"Expected 4 or 5-length vector in field 'dist'");
156 for (CVectorDouble::Index i=0;i<dists.size();i++)
159 focalLengthMeters = cfg.
read_double(section,
"focal_length",0,
false );
167 if (ncols == new_ncols && nrows == new_nrows)
170 ASSERT_(new_nrows>0 && new_ncols>0)
172 const double prev_aspect_ratio = ncols/double(nrows);
173 const double new_aspect_ratio = new_ncols/double(new_nrows);
175 ASSERTMSG_(std::abs(prev_aspect_ratio-new_aspect_ratio)<1e-3,
"TCamera: Trying to scale camera parameters for a resolution of different aspect ratio." )
177 const double K = new_ncols / double(ncols);
183 intrinsicParams(0,0)*=K;
184 intrinsicParams(1,1)*=K;
185 intrinsicParams(0,2)*=K;
186 intrinsicParams(1,2)*=K;
196 a.intrinsicParams==
b.intrinsicParams &&
198 a.focalLengthMeters==
b.focalLengthMeters;
bool operator!=(const CArray< T, N > &x, const CArray< T, N > &y)
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 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...
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
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".
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
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.
#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 ...
std::string BASE_IMPEXP 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
Introduces a pure virtual method responsible for writing to a CStream.
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 write(const std::string §ion, const std::string &name, const data_t &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
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.
bool operator==(const CArray< T, N > &x, const CArray< T, N > &y)
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: