Main MRPT website > C++ reference for MRPT 1.9.9
CObservationImage.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "obs-precomp.h" // Precompiled headers
11 
13 #include <mrpt/utils/CStream.h>
14 #include <mrpt/math/ops_vectors.h> // << of std::vector()
15 #include <iostream>
16 #if MRPT_HAS_MATLAB
17 #include <mexplus/mxarray.h>
18 #endif
19 
20 using namespace mrpt::obs;
21 using namespace mrpt::utils;
22 using namespace mrpt::math;
23 using namespace mrpt::poses;
24 
25 // This must be added to any CSerializable class implementation file.
27 
28 /** Constructor
29  */
31  : cameraPose(), image(iplImage)
32 {
33 }
34 
35 /*---------------------------------------------------------------
36  Implements the writing to a CStream capability of CSerializable objects
37  ---------------------------------------------------------------*/
39  mrpt::utils::CStream& out, int* version) const
40 {
41  if (version)
42  *version = 4;
43  else
44  {
45  // The data
46  out << cameraPose << cameraParams << image << timestamp << sensorLabel;
47  }
48 }
49 
50 /*---------------------------------------------------------------
51  Implements the reading from a CStream capability of CSerializable objects
52  ---------------------------------------------------------------*/
54 {
55  switch (version)
56  {
57  case 0:
58  case 1:
59  case 2:
60  case 3:
61  case 4:
62  {
63  in >> cameraPose;
64 
65  if (version >= 4)
66  {
67  in >> cameraParams;
68  }
69  else
70  {
71  CMatrix intrinsicParams, distortionParams;
72  in >> distortionParams >> intrinsicParams;
73 
74  if (size(distortionParams, 1) == 1 &&
75  size(distortionParams, 2) == 5)
76  {
77  const CMatrixDouble15 p = distortionParams.cast<double>();
78  cameraParams.setDistortionParamsVector(p);
79  }
80  else
81  cameraParams.dist.assign(0);
82 
83  cameraParams.intrinsicParams =
84  intrinsicParams.block(0, 0, 3, 3).cast<double>();
85  }
86 
87  in >> image;
88 
89  if (version >= 1) in >> timestamp;
90 
91  if (version >= 2)
92  {
93  if (version < 4) in >> cameraParams.focalLengthMeters;
94  }
95  else
96  cameraParams.focalLengthMeters = 0.002;
97 
98  if (version >= 3)
99  in >> sensorLabel;
100  else
101  sensorLabel = "";
102  }
103  break;
104  default:
106  };
107 }
108 
109 /*---------------------------------------------------------------
110  Implements the writing to a mxArray for Matlab
111  ---------------------------------------------------------------*/
112 #if MRPT_HAS_MATLAB
113 // Add to implement mexplus::from template specialization
115 
117 {
118  const char* fields[] = {"class", "ts", "sensorLabel",
119  "image", "pose", "params"};
120  mexplus::MxArray obs_struct(
121  mexplus::MxArray::Struct(sizeof(fields) / sizeof(fields[0]), fields));
122 
123  obs_struct.set("class", this->GetRuntimeClass()->className);
124  obs_struct.set("ts", this->timestamp);
125  obs_struct.set("sensorLabel", this->sensorLabel);
126  obs_struct.set("image", this->image);
127  obs_struct.set("pose", this->cameraPose);
128  obs_struct.set("params", this->cameraParams);
129  return obs_struct.release();
130 }
131 #endif
132 
133 /*---------------------------------------------------------------
134  getRectifiedImage
135  ---------------------------------------------------------------*/
137 {
138  image.rectifyImage(out_img, cameraParams);
139 }
140 
141 void CObservationImage::getDescriptionAsText(std::ostream& o) const
142 {
143  using namespace std;
145 
146  o << "Homogeneous matrix for the sensor's 3D pose, relative to robot "
147  "base:\n";
148  o << cameraPose.getHomogeneousMatrixVal() << cameraPose << endl;
149 
150  o << format(
151  "Focal length: %.03f mm\n", cameraParams.focalLengthMeters * 1000);
152 
153  o << "Intrinsic parameters matrix for the camera:" << endl
154  << cameraParams.intrinsicParams.inMatlabFormat() << endl
155  << cameraParams.intrinsicParams << endl;
156 
157  o << "Distorsion parameters for the camera: "
158  << cameraParams.getDistortionParamsAsVector() << endl;
159 
160  if (image.isExternallyStored())
161  o << " Image is stored externally in file: "
162  << image.getExternalStorageFile() << endl;
163 
164  o << format(
165  " Image size: %ux%u pixels\n", (unsigned int)image.getWidth(),
166  (unsigned int)image.getHeight());
167 
168  o << " Channels order: " << image.getChannelsOrder() << endl;
169 
170  o << format(
171  " Rows are stored in top-bottom order: %s\n",
172  image.isOriginTopLeft() ? "YES" : "NO");
173 }
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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...
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3551
STL namespace.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
void getRectifiedImage(mrpt::utils::CImage &out_img) const
Computes the rectified (un-distorted) image, using the embeded distortion parameters.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This namespace contains representation of robot actions and observations.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
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.
Definition: CSerializable.h:89
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
GLuint in
Definition: glext.h:7274
GLsizeiptr size
Definition: glext.h:3923
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:25
GLfloat GLfloat p
Definition: glext.h:6305
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
Definition: CSerializable.h:19
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019