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-2018, 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 
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::math;
22 using namespace mrpt::poses;
23 using namespace mrpt::img;
24 
25 // This must be added to any CSerializable class implementation file.
27 
28 /** Constructor
29  */
31  : cameraPose(), image(iplImage)
32 {
33 }
34 
37 {
38  out << cameraPose << cameraParams << image << timestamp << sensorLabel;
39 }
40 
43 {
44  switch (version)
45  {
46  case 0:
47  case 1:
48  case 2:
49  case 3:
50  case 4:
51  {
52  in >> cameraPose;
53 
54  if (version >= 4)
55  {
56  in >> cameraParams;
57  }
58  else
59  {
60  CMatrix intrinsicParams, distortionParams;
61  in >> distortionParams >> intrinsicParams;
62 
63  if (distortionParams.rows() == 1 &&
64  distortionParams.cols() == 5)
65  {
66  const CMatrixDouble15 p = distortionParams.cast<double>();
67  cameraParams.setDistortionParamsVector(p);
68  }
69  else
70  cameraParams.dist.fill(0);
71 
72  cameraParams.intrinsicParams =
73  intrinsicParams.block(0, 0, 3, 3).cast<double>();
74  }
75 
76  in >> image;
77 
78  if (version >= 1) in >> timestamp;
79 
80  if (version >= 2)
81  {
82  if (version < 4) in >> cameraParams.focalLengthMeters;
83  }
84  else
85  cameraParams.focalLengthMeters = 0.002;
86 
87  if (version >= 3)
88  in >> sensorLabel;
89  else
90  sensorLabel = "";
91  }
92  break;
93  default:
95  };
96 }
97 
98 /*---------------------------------------------------------------
99  Implements the writing to a mxArray for Matlab
100  ---------------------------------------------------------------*/
101 #if MRPT_HAS_MATLAB
102 // Add to implement mexplus::from template specialization
104 #endif
105 
107 {
108 #if MRPT_HAS_MATLAB
109  const char* fields[] = {"class", "ts", "sensorLabel",
110  "image", "pose", "params"};
111  mexplus::MxArray obs_struct(
112  mexplus::MxArray::Struct(sizeof(fields) / sizeof(fields[0]), fields));
113 
114  obs_struct.set("class", this->GetRuntimeClass()->className);
115  obs_struct.set("ts", this->timestamp);
116  obs_struct.set("sensorLabel", this->sensorLabel);
117  obs_struct.set("image", this->image);
118  obs_struct.set("pose", this->cameraPose);
119  obs_struct.set("params", this->cameraParams);
120  return obs_struct.release();
121 #else
122  THROW_EXCEPTION("MRPT built without MATLAB/Mex support");
123 #endif
124 }
125 
127 {
128  image.rectifyImage(out_img, cameraParams);
129 }
130 
131 void CObservationImage::getDescriptionAsText(std::ostream& o) const
132 {
133  using namespace std;
135 
136  o << "Homogeneous matrix for the sensor's 3D pose, relative to robot "
137  "base:\n";
138  o << cameraPose.getHomogeneousMatrixVal<CMatrixDouble44>() << cameraPose
139  << endl;
140 
141  o << format(
142  "Focal length: %.03f mm\n", cameraParams.focalLengthMeters * 1000);
143 
144  o << "Intrinsic parameters matrix for the camera:" << endl
145  << cameraParams.intrinsicParams.inMatlabFormat() << endl
146  << cameraParams.intrinsicParams << endl;
147 
148  o << "Distorsion parameters for the camera: "
149  << cameraParams.getDistortionParamsAsVector() << endl;
150 
151  if (image.isExternallyStored())
152  o << " Image is stored externally in file: "
153  << image.getExternalStorageFile() << endl;
154 
155  o << format(
156  " Image size: %ux%u pixels\n", (unsigned int)image.getWidth(),
157  (unsigned int)image.getHeight());
158 
159  o << " Channels order: " << image.getChannelsOrder() << endl;
160 
161  o << format(
162  " Rows are stored in top-bottom order: %s\n",
163  image.isOriginTopLeft() ? "YES" : "NO");
164 }
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
#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...
void getRectifiedImage(mrpt::img::CImage &out_img) const
Computes the rectified (un-distorted) image, using the embeded distortion parameters.
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3551
STL namespace.
unsigned char uint8_t
Definition: rptypes.h:41
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
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:16
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
Definition: CSerializable.h:18
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
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:70
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
GLuint in
Definition: glext.h:7274
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
GLfloat GLfloat p
Definition: glext.h:6305
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
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: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019