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);