Main MRPT website > C++ reference for MRPT 1.9.9
CObservationStereoImagesFeatures.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
12 
14 #include <mrpt/utils/CStream.h>
15 
16 using namespace mrpt::obs;
17 using namespace mrpt::utils;
18 using namespace mrpt::poses;
19 using namespace mrpt::math;
20 using namespace std;
21 
22 // This must be added to any CSerializable class implementation file.
25 
27  : cameraLeft(), cameraRight(), rightCameraPose(), cameraPoseOnRobot()
28 {
29 }
30 
31 CObservationStereoImagesFeatures::CObservationStereoImagesFeatures(
32  const CMatrixDouble33& iPLeft, const CMatrixDouble33& iPRight,
33  const CArrayDouble<5>& dPLeft, const CArrayDouble<5>& dPRight,
34  const CPose3DQuat& rCPose, const CPose3DQuat& cPORobot)
35 {
36  cameraLeft.intrinsicParams = iPLeft;
37  cameraLeft.dist = dPLeft;
38 
39  cameraRight.intrinsicParams = iPRight;
40  cameraRight.dist = dPRight;
41 
42  rightCameraPose = rCPose;
43  cameraPoseOnRobot = cPORobot;
44 }
45 
47  const TCamera& cLeft, const TCamera& cRight, const CPose3DQuat& rCPose,
48  const CPose3DQuat& cPORobot)
49 {
50  cameraLeft = cLeft;
51  cameraRight = cRight;
52 
53  rightCameraPose = rCPose;
54  cameraPoseOnRobot = cPORobot;
55 }
56 
59  const std::string& filename)
60 {
61  CFileOutputStream file(filename);
62 
64  for (it = theFeatures.begin(); it != theFeatures.end(); ++it)
65  file << format(
66  "%u %.2f %.2f %.2f %.2f\n", it->ID, it->pixels.first.x,
67  it->pixels.first.y, it->pixels.second.x, it->pixels.second.y);
68 
69  file.close();
70 }
71 
72 /*---------------------------------------------------------------
73  Implements the writing to a CStream capability of CSerializable objects
74  ---------------------------------------------------------------*/
76  mrpt::utils::CStream& out, int* version) const
77 {
78  if (version)
79  *version = 0;
80  else
81  {
82  // The data
83  out << cameraLeft;
84  out << cameraRight;
86  out << (uint32_t)theFeatures.size(); // Write the number of items
87  // within the feature list
88  for (unsigned int i = 0; i < theFeatures.size(); ++i)
89  {
90  out << theFeatures[i].pixels.first.x
91  << theFeatures[i].pixels.first.y;
92  out << theFeatures[i].pixels.second.x
93  << theFeatures[i].pixels.second.y;
94  out << (uint32_t)theFeatures[i].ID;
95  }
96  out << sensorLabel << timestamp;
97  }
98 }
99 
100 /*---------------------------------------------------------------
101  Implements the reading from a CStream capability of CSerializable objects
102  ---------------------------------------------------------------*/
104  mrpt::utils::CStream& in, int version)
105 {
106  switch (version)
107  {
108  case 0:
109  {
110  uint32_t nL, nR;
111  in >> cameraLeft;
112  in >> cameraRight;
114  in >> nL;
115  theFeatures.resize(nL);
116  for (unsigned int i = 0; i < theFeatures.size(); ++i)
117  {
118  in >> theFeatures[i].pixels.first.x >>
119  theFeatures[i].pixels.first.y;
120  in >> theFeatures[i].pixels.second.x >>
121  theFeatures[i].pixels.second.y;
122  in >> nR;
123  theFeatures[i].ID = (unsigned int)nR;
124  }
125  in >> sensorLabel >> timestamp;
126  }
127  break;
128  default:
130  };
131 }
132 
134  std::ostream& o) const
135 {
137 
138  o << "Homogeneous matrix for the sensor's 3D pose, relative to robot "
139  "base:\n";
141  << endl;
142 
143  o << "Homogeneous matrix for the RIGHT camera's 3D pose, relative to LEFT "
144  "camera reference system:\n";
146 
147  o << "Intrinsic parameters matrix for the LEFT camera:" << endl;
149  o << aux.inMatlabFormat() << endl << aux << endl;
150 
151  o << "Distortion parameters vector for the LEFT camera:" << endl << "[ ";
152  for (unsigned int i = 0; i < 5; ++i) o << cameraLeft.dist[i] << " ";
153  o << "]" << endl;
154 
155  o << "Intrinsic parameters matrix for the RIGHT camera:" << endl;
157  o << aux.inMatlabFormat() << endl << aux << endl;
158 
159  o << "Distortion parameters vector for the RIGHT camera:" << endl << "[ ";
160  for (unsigned int i = 0; i < 5; ++i) o << cameraRight.dist[i] << " ";
161  o << "]" << endl;
162 
163  o << endl
164  << format(
165  " Image size: %ux%u pixels\n", (unsigned int)cameraLeft.ncols,
166  (unsigned int)cameraLeft.nrows);
167  o << endl
168  << format(
169  " Number of features in images: %u\n",
170  (unsigned int)theFeatures.size());
171 }
void close()
Close the stream.
void saveFeaturesToTextFile(const std::string &filename)
A method for storing the set of observed features in a text file in the format: ID ul vl ur vr be...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Declares a class derived from "CObservation" that encapsules a pair of cameras and a set of matched i...
std::vector< TStereoImageFeatures > theFeatures
Vectors of image feature pairs (with ID).
IMPLEMENTS_SERIALIZABLE(CObservationStereoImagesFeatures, CObservation, mrpt::obs) CObservationStereoImagesFeatures
Scalar * iterator
Definition: eigen_plugins.h:26
STL namespace.
mrpt::math::CMatrixDouble44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
Definition: CPoseOrPoint.h:276
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
This CStream derived class allow using a file as a write-only, binary stream.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This namespace contains representation of robot actions and observations.
uint32_t ncols
Camera resolution.
Definition: TCamera.h:54
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:48
GLsizei const GLchar ** string
Definition: glext.h:4101
CObservationStereoImagesFeatures()
Default Constructor.
mrpt::poses::CPose3DQuat cameraPoseOnRobot
The pose of the LEFT camera, relative to the robot.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
Definition: TCamera.h:57
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
Definition: CObservation.h:60
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
Definition: CObservation.h:58
mrpt::poses::CPose3DQuat rightCameraPose
The pose of the right camera, relative to the left one: Note that for the Bumblebee stereo camera and...
mrpt::math::CArrayDouble< 5 > dist
[k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (d...
Definition: TCamera.h:60
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
uint32_t nrows
Definition: TCamera.h:54
GLuint in
Definition: glext.h:7274
GLenum GLsizei GLenum format
Definition: glext.h:3531
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...
unsigned __int32 uint32_t
Definition: rptypes.h:47
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:32
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