33 ofstream f(filName.c_str());
36 if (!skipFirstCommentLine)
37 f <<
"% FRAME_ID FEAT_ID X Y \n" 38 "%-------------------------------------\n";
41 f << setw(7) << it->id_frame << setw(7) << it->id_feature << setw(13) << it->px.x << setw(11) << it->px.y << endl;
53 ifstream f(filName.c_str());
56 unsigned int linNum = 0;
63 if (lin.empty() || lin[0]==
'%')
continue;
72 if (!(
s >> camID >> featID >> px.
x >> px.
y))
81 bool TSequenceFeatureObservations::saveAsSBAFiles(
89 std::map<TLandmarkID, std::map<TCameraPoseID, TPixelCoordf> > obs_by_point;
94 std::map<TCameraPoseID, TPixelCoordf> & m = obs_by_point[ o.
id_feature ];
99 ofstream f(pts_file.c_str());
103 f <<
"# X Y Z nframes frame0 x0 y0 frame1 x1 y1 ...\n";
104 for (std::map<
TLandmarkID, std::map<TCameraPoseID, TPixelCoordf> >::
const_iterator it=obs_by_point.begin();it!=obs_by_point.end();++it)
106 const std::map<TCameraPoseID, TPixelCoordf> & m = it->second;
107 f << pts[it->first].
x <<
" " 108 << pts[it->first].y <<
" " 109 << pts[it->first].z <<
" " 112 f << itO->first <<
" " << itO->second.x <<
" "<< itO->second.y <<
" ";
116 ofstream fc(cams_file.c_str());
120 for (
size_t i=0;i<cams.size();i++)
124 fc <<
p.m_quat[0] <<
" " 125 <<
p.m_quat[1] <<
" " 126 <<
p.m_quat[2] <<
" " 127 <<
p.m_quat[3] <<
" " 139 size_t TSequenceFeatureObservations::removeFewObservedFeatures(
size_t minNumObservations )
146 map<TLandmarkID,size_t> numViews;
148 numViews[it->id_feature]++;
153 if (numViews[(*
this)[idx].id_feature]<minNumObservations)
166 void TSequenceFeatureObservations::decimateCameraFrames(
const size_t decimate_ratio)
169 if (decimate_ratio==1)
173 set<TCameraPoseID> frameIDs;
175 frameIDs.insert(it->id_frame);
183 for (
size_t d=0;d<decimate_ratio-1 && it!=frameIDs.end();d++)
189 newLst.reserve(
BASE::size() / decimate_ratio);
191 if (frameIDs.find(it->id_frame)!=frameIDs.end())
192 newLst.push_back(*it);
199 void TSequenceFeatureObservations::compressIDs(
200 std::map<TCameraPoseID,TCameraPoseID> *old2new_camIDs,
201 std::map<TLandmarkID,TLandmarkID> *old2new_lmIDs )
204 std::map<TCameraPoseID,TCameraPoseID> camIDs;
205 std::map<TLandmarkID,TLandmarkID> lmIDs;
212 if (lmIDs.find(f_ID)==lmIDs.end())
217 if (camIDs.find(c_ID)==camIDs.end())
227 for (
size_t i=0;i<N;++i)
229 newLst[i].id_feature = lmIDs [ (*this)[i].id_feature ];
230 newLst[i].id_frame = camIDs[ (*this)[i].id_frame ];
231 newLst[i].px = (*this)[i].px;
238 if (old2new_camIDs) old2new_camIDs->swap(camIDs);
239 if (old2new_lmIDs) old2new_lmIDs->swap(lmIDs);
A pair (x,y) of pixel coordinates (subpixel resolution).
TLandmarkID id_feature
A unique ID of this feature.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
#define THROW_EXCEPTION(msg)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
EIGEN_STRONG_INLINE iterator begin()
One feature observation entry, used within sequences with TSequenceFeatureObservations.
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
void saveToTextFile(const std::string &file, mrpt::math::TMatrixTextFileFormat fileFormat=mrpt::math::MATRIX_FORMAT_ENG, bool appendMRPTHeader=false, const std::string &userHeader=std::string()) const
Save matrix to a text file, compatible with MATLAB text format (see also the methods of matrix classe...
const Scalar * const_iterator
mrpt::utils::TPixelCoordf px
The pixel coordinates of the observed feature.
void clear()
Clear the contents of this container.
A complete sequence of observations of features from different camera frames (poses).
std::list< T >::iterator erase_return_next(std::list< T > &cont, typename std::list< T >::iterator &it)
Calls the standard "erase" method of a STL container, but also returns an iterator to the next elemen...
mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t TFramePosesVec
A list of camera frames (6D poses), which assumes indexes are unique, consecutive IDs...
Classes for computer vision, detectors, features, etc.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
uint64_t TFeatureID
Definition of a feature ID.
GLsizei const GLchar ** string
void loadFromTextFile(const std::string &file)
Load matrix from a text file, compatible with MATLAB text format.
uint64_t TCameraPoseID
Unique IDs for camera frames (poses)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
uint64_t TLandmarkID
Unique IDs for landmarks.
#define ASSERT_ABOVEEQ_(__A, __B)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
std::vector< mrpt::math::TPoint3D > TLandmarkLocationsVec
A list of landmarks (3D points), which assumes indexes are unique, consecutive IDs.
std::string BASE_IMPEXP trim(const std::string &str)
Removes leading and trailing spaces.
TCameraPoseID id_frame
A unique ID of a "frame" (camera position) from where the feature was observed.
GLenum GLsizei GLenum format