segmentation fault close obs solved

This commit is contained in:
gfuse
2021-09-02 01:01:32 +02:00
parent 4d857d790c
commit 68cd6d9b48
6 changed files with 41 additions and 24 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ public:
Feature* findFrameRef(Frame* frame); Feature* findFrameRef(Frame* frame);
/// Get Frame with similar viewpoint. /// Get Frame with similar viewpoint.
bool getCloseViewObs(const Vector2d& pos, Feature*& obs) const; bool getCloseViewObs(const Vector2d& pos, Feature*& obs, int id=0) const;
/// Get number of observations. /// Get number of observations.
inline size_t nRefs() const { return obs_.size(); } inline size_t nRefs() const { return obs_.size(); }
+1 -1
View File
@@ -299,7 +299,7 @@ namespace vio {
lock_t lock(seeds_mut_); lock_t lock(seeds_mut_);
for(std::list<Seed>::iterator it=seeds_.begin(); it!=seeds_.end(); ++it) for(std::list<Seed>::iterator it=seeds_.begin(); it!=seeds_.end(); ++it)
{ {
if (it->ftr->frame == frame.get()) if (it->ftr->frame->id_ == frame->id_)
seeds.push_back(*it); seeds.push_back(*it);
} }
} }
+2 -2
View File
@@ -44,7 +44,7 @@ bool Map::safeDeleteFrame(FramePtr frame)
bool found = false; bool found = false;
for(auto it=keyframes_.begin(), ite=keyframes_.end(); it!=ite; ++it) for(auto it=keyframes_.begin(), ite=keyframes_.end(); it!=ite; ++it)
{ {
if(*it == frame) if(it->get()->id_ == frame->id_)
{ {
std::for_each((*it)->fts_.begin(), (*it)->fts_.end(), [&](Feature* ftr){ std::for_each((*it)->fts_.begin(), (*it)->fts_.end(), [&](Feature* ftr){
removePtFrameRef(it->get(), ftr); removePtFrameRef(it->get(), ftr);
@@ -268,7 +268,7 @@ void MapPointCandidates::removeFrameCandidates(FramePtr frame)
auto it=candidates_.begin(); auto it=candidates_.begin();
while(it!=candidates_.end()) while(it!=candidates_.end())
{ {
if(it->second->frame == frame.get()) if(it->second->frame->id_ == frame->id_)
{ {
deleteCandidate(*it); deleteCandidate(*it);
it = candidates_.erase(it); it = candidates_.erase(it);
+3 -1
View File
@@ -140,7 +140,9 @@ bool Matcher::findMatchDirect(
const Frame& cur_frame, const Frame& cur_frame,
Vector2d& px_cur) Vector2d& px_cur)
{ {
if(!pt.getCloseViewObs(cur_frame.pos(), ref_ftr_))return false; if(pt.last_frame_overlap_id_ !=cur_frame.id_)return true;
if(pt.obs_.size()<2)return false;
if(!pt.getCloseViewObs(cur_frame.pos(), ref_ftr_,cur_frame.id_))return false;
if(ref_ftr_== nullptr)return false; if(ref_ftr_== nullptr)return false;
if(ref_ftr_->frame== nullptr)return false; if(ref_ftr_->frame== nullptr)return false;
if(ref_ftr_->frame->cam_== nullptr)return false; if(ref_ftr_->frame->cam_== nullptr)return false;
+6 -2
View File
@@ -59,6 +59,7 @@ Point::~Point()
void Point::addFrameRef(Feature* ftr) void Point::addFrameRef(Feature* ftr)
{ {
obs_.push_front(ftr); obs_.push_front(ftr);
++n_obs_; ++n_obs_;
} }
@@ -95,7 +96,7 @@ void Point::initNormal()
normal_set_ = true; normal_set_ = true;
} }
bool Point::getCloseViewObs(const Vector2d& framepos, Feature*& ftr) const bool Point::getCloseViewObs(const Vector2d& framepos, Feature*& ftr,int id) const
{ {
// TODO: get frame with same point of view AND same pyramid level! // TODO: get frame with same point of view AND same pyramid level!
ftr= nullptr; ftr= nullptr;
@@ -103,7 +104,10 @@ bool Point::getCloseViewObs(const Vector2d& framepos, Feature*& ftr) const
double max_cos_angle = 1.0; double max_cos_angle = 1.0;
if(obs_.empty())return false; if(obs_.empty())return false;
for(auto&& ob:obs_){ for(auto&& ob:obs_){
if(ob == nullptr)continue; if(ob->frame->id_==id){
ftr = ob;
return true;
}
Vector2d t=ob->frame->pos(); Vector2d t=ob->frame->pos();
Vector3d dir(Vector3d(t.x(),1e-9,t.y()) + pos_); Vector3d dir(Vector3d(t.x(),1e-9,t.y()) + pos_);
double cos_angle = obs_dir.dot(dir.normalized()); double cos_angle = obs_dir.dot(dir.normalized());
+16 -5
View File
@@ -155,9 +155,19 @@ namespace vio {
for (auto &&match:matches) { for (auto &&match:matches) {
if (match.queryIdx != f.index)continue; if (match.queryIdx != f.index)continue;
if (f.item->point == NULL){ if (f.item->point == NULL){
f.item->point = new Point(it_frame.item.first->cam_->cam2world(f.item->px.x(), f.item->px.y())); const int k = static_cast<int>(keypoints_cur.at(match.trainIdx).pt.y / grid_.cell_size) *
// assert(!f.item->point->obs_.empty()); grid_.grid_n_cols
} + static_cast<int>(keypoints_cur.at(match.trainIdx).pt.x / grid_.cell_size);
Vector2d px((int) keypoints_cur.at(match.trainIdx).pt.x,
(int) keypoints_cur.at(match.trainIdx).pt.y);
frame->fts_.push_back(new Feature(it_frame.item.first.get(),
new Point(it_frame.item.first->cam_->cam2world(f.item->px.x(), f.item->px.y()),f.item),
px,it_frame.item.first->cam_->cam2world(f.item->px),0));
frame->fts_.back()->point->last_frame_overlap_id_=it_frame.item.first->id_;
grid_.cells.at(k)->push_back(Candidate(frame->fts_.back()->point, px));
overlap_kfs.back().second++;
break;
}else{
if (f.item->point->last_frame_overlap_id_ == frame->id_)continue; if (f.item->point->last_frame_overlap_id_ == frame->id_)continue;
f.item->point->last_frame_overlap_id_ = frame->id_; f.item->point->last_frame_overlap_id_ = frame->id_;
assert(keypoints_cur.size() > match.trainIdx); assert(keypoints_cur.size() > match.trainIdx);
@@ -167,7 +177,6 @@ namespace vio {
assert(grid_.cells.at(k) != nullptr); assert(grid_.cells.at(k) != nullptr);
Vector2d px((int) keypoints_cur.at(match.trainIdx).pt.x, Vector2d px((int) keypoints_cur.at(match.trainIdx).pt.x,
(int) keypoints_cur.at(match.trainIdx).pt.y); (int) keypoints_cur.at(match.trainIdx).pt.y);
f.item->point->addFrameRef(new Feature(it_frame.item.first.get(),f.item->px,0));
//f.item->point->addFrameRef(f.item); //f.item->point->addFrameRef(f.item);
grid_.cells.at(k)->push_back(Candidate(f.item->point, px)); grid_.cells.at(k)->push_back(Candidate(f.item->point, px));
overlap_kfs.back().second++; overlap_kfs.back().second++;
@@ -175,6 +184,7 @@ namespace vio {
} }
} }
} }
}
{ {
for (auto&& cell : grid_.cells) { for (auto&& cell : grid_.cells) {
if (reprojectCell(*cell, frame)) if (reprojectCell(*cell, frame))
@@ -193,12 +203,13 @@ namespace vio {
} }
bool Reprojector::reprojectCell(Cell &cell, FramePtr frame) { bool Reprojector::reprojectCell(Cell &cell, FramePtr frame) {
if(cell.size()<1)return false;
cell.sort(boost::bind(&Reprojector::pointQualityComparator, _1, _2)); cell.sort(boost::bind(&Reprojector::pointQualityComparator, _1, _2));
Cell::iterator it=cell.begin(); Cell::iterator it=cell.begin();
while(it!=cell.end()) while(it!=cell.end())
{ {
++n_trials_; ++n_trials_;
if(it->pt->type_ == Point::TYPE_DELETED) if(it->pt->type_ == Point::TYPE_DELETED || it->pt ==NULL)
{ {
it = cell.erase(it); it = cell.erase(it);
continue; continue;