Main MRPT website > C++ reference for MRPT 1.5.7
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(),
32  image( iplImage )
33 {
34 }
35 
36 /*---------------------------------------------------------------
37  Implements the writing to a CStream capability of CSerializable objects
38  ---------------------------------------------------------------*/
40 {
41  if (version)
42  *version = 4;
43  else
44  {
45  // The data
46  out << cameraPose << cameraParams << image
47  << timestamp
48  << sensorLabel;
49  }
50 }
51 
52 /*---------------------------------------------------------------
53  Implements the reading from a CStream capability of CSerializable objects
54  ---------------------------------------------------------------*/
56 {
57  switch(version)
58  {
59  case 0:
60  case 1:
61  case 2:
62  case 3:
63  case 4:
64  {
65  in >> cameraPose;
66 
67  if (version>=4)
68  {
69  in >> cameraParams;
70  }
71  else
72  {
73  CMatrix intrinsicParams, distortionParams;
74  in >> distortionParams >> intrinsicParams;
75 
76  if (size(distortionParams,1)==1 && size(distortionParams,2)==5)
77  {
78  const CMatrixDouble15 p = distortionParams.cast<double>();
79  cameraParams.setDistortionParamsVector(p);
80  }
81  else cameraParams.dist.assign(0);
82 
83  cameraParams.intrinsicParams = intrinsicParams.block(0,0,3,3).cast<double>();
84  }
85 
86  in >> image;
87 
88  if (version>=1)
89  in >> timestamp;
90 
91  if (version>=2)
92  {
93  if (version<4)
94  in >> cameraParams.focalLengthMeters ;
95  }
96  else
97  cameraParams.focalLengthMeters = 0.002;
98 
99  if (version>=3)
100  in >> sensorLabel;
101  else sensorLabel = "";
102 
103  } break;
104  default:
106 
107  };
108 
109 }
110 
111 /*---------------------------------------------------------------
112  Implements the writing to a mxArray for Matlab
113  ---------------------------------------------------------------*/
114 #if MRPT_HAS_MATLAB
115 // Add to implement mexplus::from template specialization
117 
119 {
120  const char* fields[] = {"class","ts","sensorLabel","image","pose","params"};
121  mexplus::MxArray obs_struct( 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 base:\n";
147  o << cameraPose.getHomogeneousMatrixVal()
148  << cameraPose << endl;
149 
150  o << format("Focal length: %.03f mm\n",cameraParams.focalLengthMeters*1000);
151 
152  o << "Intrinsic parameters matrix for the camera:"<< endl
153  << cameraParams.intrinsicParams.inMatlabFormat() << endl << cameraParams.intrinsicParams << endl;
154 
155  o << "Distorsion parameters for the camera: " << cameraParams.getDistortionParamsAsVector() << endl;
156 
157  if (image.isExternallyStored())
158  o << " Image is stored externally in file: " << image.getExternalStorageFile() << endl;
159 
160  o << format(" Image size: %ux%u pixels\n", (unsigned int)image.getWidth(), (unsigned int)image.getHeight() );
161 
162  o << " Channels order: " << image.getChannelsOrder() << endl;
163 
164  o << format(" Rows are stored in top-bottom order: %s\n",
165  image.isOriginTopLeft() ? "YES" : "NO");
166 
167 }
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.
Definition: zip.h:16
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:101
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3522
STL namespace.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
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...
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 BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:21
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
int version
Definition: mrpt_jpeglib.h:898
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
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:79
Declares a class that represents any robot&#39;s observation.
GLuint in
Definition: glext.h:6301
GLsizeiptr size
Definition: glext.h:3779
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:30
GLfloat GLfloat p
Definition: glext.h:5587
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
Definition: CSerializable.h:17
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.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019