31 const std::string& filName,
bool skipFirstCommentLine)
const
35 ofstream f(filName.c_str());
39 if (!skipFirstCommentLine)
40 f <<
"% FRAME_ID FEAT_ID X Y \n"
41 "%-------------------------------------\n";
44 f << setw(7) << it->id_frame << setw(7) << it->id_feature << setw(13)
45 << it->px.x << setw(11) << it->px.y << endl;
57 ifstream f(filName.c_str());
61 unsigned int linNum = 0;
68 if (lin.empty() || lin[0] ==
'%')
continue;
77 if (!(
s >> camID >> featID >> px.
x >> px.
y))
80 "%s:%u: Error parsing line: '%s'", filName.c_str(), linNum,
89 bool TSequenceFeatureObservations::saveAsSBAFiles(
95 std::map<TLandmarkID, std::map<TCameraPoseID, TPixelCoordf>> obs_by_point;
100 std::map<TCameraPoseID, TPixelCoordf>& m = obs_by_point[o.
id_feature];
105 ofstream f(pts_file.c_str());
106 if (!f.is_open())
return false;
108 f <<
"# X Y Z nframes frame0 x0 y0 frame1 x1 y1 ...\n";
111 obs_by_point.begin();
112 it != obs_by_point.end(); ++it)
114 const std::map<TCameraPoseID, TPixelCoordf>& m = it->second;
115 f << pts[it->first].x <<
" " << pts[it->first].y <<
" "
116 << pts[it->first].z <<
" " << m.size() <<
" ";
119 itO != m.end(); ++itO)
120 f << itO->first <<
" " << itO->second.x <<
" " << itO->second.y
125 ofstream fc(cams_file.c_str());
126 if (!fc.is_open())
return false;
128 for (
size_t i = 0; i < cams.size(); i++)
132 fc <<
p.m_quat[0] <<
" " <<
p.m_quat[1] <<
" " <<
p.m_quat[2] <<
" "
133 <<
p.m_quat[3] <<
" " <<
p.x() <<
" " <<
p.y() <<
" " <<
p.z()
143 size_t TSequenceFeatureObservations::removeFewObservedFeatures(
144 size_t minNumObservations)
151 map<TLandmarkID, size_t> numViews;
153 numViews[it->id_feature]++;
158 if (numViews[(*
this)[idx].id_feature] < minNumObservations)
172 void TSequenceFeatureObservations::decimateCameraFrames(
173 const size_t decimate_ratio)
176 if (decimate_ratio == 1)
return;
179 set<TCameraPoseID> frameIDs;
181 frameIDs.insert(it->id_frame);
185 it != frameIDs.end();)
190 for (
size_t d = 0; d < decimate_ratio - 1 && it != frameIDs.end(); d++)
196 newLst.reserve(
BASE::size() / decimate_ratio);
198 if (frameIDs.find(it->id_frame) != frameIDs.end())
199 newLst.push_back(*it);
207 void TSequenceFeatureObservations::compressIDs(
208 std::map<TCameraPoseID, TCameraPoseID>* old2new_camIDs,
209 std::map<TLandmarkID, TLandmarkID>* old2new_lmIDs)
212 std::map<TCameraPoseID, TCameraPoseID> camIDs;
213 std::map<TLandmarkID, TLandmarkID> lmIDs;
220 if (lmIDs.find(f_ID) == lmIDs.end())
225 lmIDs[f_ID] = nextID;
227 if (camIDs.find(c_ID) == camIDs.end())
232 camIDs[c_ID] = nextID;
239 for (
size_t i = 0; i < N; ++i)
241 newLst[i].id_feature = lmIDs[(*this)[i].id_feature];
242 newLst[i].id_frame = camIDs[(*this)[i].id_frame];
243 newLst[i].px = (*this)[i].px;
250 if (old2new_camIDs) old2new_camIDs->swap(camIDs);
251 if (old2new_lmIDs) old2new_lmIDs->swap(lmIDs);
static std::string & trim(std::string &s)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,...
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...
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
EIGEN_STRONG_INLINE iterator begin()
const Scalar * const_iterator
void loadFromTextFile(const std::string &file)
Load matrix from a text file, compatible with MATLAB text format.
#define THROW_EXCEPTION(msg)
#define ASSERT_ABOVEEQ_(__A, __B)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
GLenum GLsizei GLenum format
GLsizei const GLchar ** string
uint64_t TFeatureID
Definition of a feature ID.
uint64_t TCameraPoseID
Unique IDs for camera frames (poses)
mrpt::aligned_std_vector< mrpt::poses::CPose3D > TFramePosesVec
A list of camera frames (6D poses), which assumes indexes are unique, consecutive IDs.
uint64_t TLandmarkID
Unique IDs for landmarks.
std::vector< mrpt::math::TPoint3D > TLandmarkLocationsVec
A list of landmarks (3D points), which assumes indexes are unique, consecutive IDs.
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...
void clear()
Clear the contents of this container.
Classes for computer vision, detectors, features, etc.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A pair (x,y) of pixel coordinates (subpixel resolution).
One feature observation entry, used within sequences with TSequenceFeatureObservations.
TLandmarkID id_feature
A unique ID of this feature.
mrpt::img::TPixelCoordf px
The pixel coordinates of the observed feature.
TCameraPoseID id_frame
A unique ID of a "frame" (camera position) from where the feature was observed.
A complete sequence of observations of features from different camera frames (poses).