Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vision
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
plugins
vision
Commits
7dbe24f3
Commit
7dbe24f3
authored
3 years ago
by
Joan Solà Ortega
Browse files
Options
Downloads
Patches
Plain Diff
Fix some segfaults happening with empty sets of keypoints
parent
78bebf5d
No related branches found
No related tags found
2 merge requests
!36
After cmake and const refactor
,
!28
Resolve "Building a new visual odometry system"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/processor/processor_visual_odometry.cpp
+25
-3
25 additions, 3 deletions
src/processor/processor_visual_odometry.cpp
with
25 additions
and
3 deletions
src/processor/processor_visual_odometry.cpp
+
25
−
3
View file @
7dbe24f3
...
@@ -68,6 +68,7 @@ TracksMap ProcessorVisualOdometry::mergeTracks(TracksMap tracks_prev_curr, Track
...
@@ -68,6 +68,7 @@ TracksMap ProcessorVisualOdometry::mergeTracks(TracksMap tracks_prev_curr, Track
void
ProcessorVisualOdometry
::
preProcess
()
void
ProcessorVisualOdometry
::
preProcess
()
{
{
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
// Get Capture
// Get Capture
...
@@ -127,8 +128,9 @@ void ProcessorVisualOdometry::preProcess()
...
@@ -127,8 +128,9 @@ void ProcessorVisualOdometry::preProcess()
// TracksMap between last and incoming
// TracksMap between last and incoming
// Input: ID of Wkp in last. Output: ID of the tracked Wkp in incoming.
// Input: ID of Wkp in last. Output: ID of the tracked Wkp in incoming.
WOLF_INFO
(
"Tracking "
,
mwkps_last
.
size
(),
" keypoints in last"
);
TracksMap
tracks_last_incoming
=
kltTrack
(
img_last
,
img_incoming
,
mwkps_last
,
mwkps_incoming
);
TracksMap
tracks_last_incoming
=
kltTrack
(
img_last
,
img_incoming
,
mwkps_last
,
mwkps_incoming
);
WOLF_INFO
(
"Tracked "
,
mwkps_incoming
.
size
(),
" keypoints
...
"
);
WOLF_INFO
(
"Tracked "
,
mwkps_incoming
.
size
(),
" keypoints
to incoming
"
);
// TracksMap between origin and last
// TracksMap between origin and last
// Input: ID of Wkp in origin. Output: ID of the tracked Wkp in last.
// Input: ID of Wkp in origin. Output: ID of the tracked Wkp in last.
...
@@ -223,11 +225,13 @@ void ProcessorVisualOdometry::preProcess()
...
@@ -223,11 +225,13 @@ void ProcessorVisualOdometry::preProcess()
auto
dt_preprocess
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
()
-
t1
).
count
();
auto
dt_preprocess
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
()
-
t1
).
count
();
WOLF_INFO
(
"dt_preprocess (ms): "
,
dt_preprocess
);
WOLF_INFO
(
"dt_preprocess (ms): "
,
dt_preprocess
);
}
}
unsigned
int
ProcessorVisualOdometry
::
processKnown
()
unsigned
int
ProcessorVisualOdometry
::
processKnown
()
{
{
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
auto
t1
=
std
::
chrono
::
system_clock
::
now
();
// Extend the process track matrix by using information stored in the incoming capture
// Extend the process track matrix by using information stored in the incoming capture
...
@@ -319,12 +323,21 @@ void ProcessorVisualOdometry::establishFactors()
...
@@ -319,12 +323,21 @@ void ProcessorVisualOdometry::establishFactors()
// For bookkeeping, define the landmark id as the track id.
// For bookkeeping, define the landmark id as the track id.
std
::
list
<
FeatureBasePtr
>
tracks_snapshot_last
=
track_matrix_
.
snapshotAsList
(
last_ptr_
);
std
::
list
<
FeatureBasePtr
>
tracks_snapshot_last
=
track_matrix_
.
snapshotAsList
(
last_ptr_
);
for
(
auto
feat
:
tracks_snapshot_last
){
if
(
tracks_snapshot_last
.
empty
())
{
WOLF_WARN
(
"Trying to establish factors but no features exist in last Capture!"
);
return
;
}
for
(
auto
feat
:
tracks_snapshot_last
)
{
auto
feat_pi
=
std
::
static_pointer_cast
<
FeaturePointImage
>
(
feat
);
auto
feat_pi
=
std
::
static_pointer_cast
<
FeaturePointImage
>
(
feat
);
// verify if a landmark is associated to this track (BAD implementation)
// verify if a landmark is associated to this track (BAD implementation)
LandmarkBasePtr
associated_lmk
=
nullptr
;
LandmarkBasePtr
associated_lmk
=
nullptr
;
for
(
auto
lmk
:
getProblem
()
->
getMap
()
->
getLandmarkList
()){
for
(
auto
lmk
:
getProblem
()
->
getMap
()
->
getLandmarkList
())
{
if
(
lmk
->
id
()
==
feat_pi
->
trackId
()){
if
(
lmk
->
id
()
==
feat_pi
->
trackId
()){
associated_lmk
=
lmk
;
associated_lmk
=
lmk
;
}
}
...
@@ -350,6 +363,7 @@ void ProcessorVisualOdometry::establishFactors()
...
@@ -350,6 +363,7 @@ void ProcessorVisualOdometry::establishFactors()
}
}
}
}
return
;
}
}
LandmarkBasePtr
ProcessorVisualOdometry
::
emplaceLandmark
(
FeatureBasePtr
_feat
)
LandmarkBasePtr
ProcessorVisualOdometry
::
emplaceLandmark
(
FeatureBasePtr
_feat
)
...
@@ -403,6 +417,7 @@ void ProcessorVisualOdometry::postProcess()
...
@@ -403,6 +417,7 @@ void ProcessorVisualOdometry::postProcess()
bool
ProcessorVisualOdometry
::
voteForKeyFrame
()
const
bool
ProcessorVisualOdometry
::
voteForKeyFrame
()
const
{
{
// If the last capture was repopulated in preProcess, it means that the number of tracks fell
// If the last capture was repopulated in preProcess, it means that the number of tracks fell
// below a threshold in the current incoming track and that, as a consequence, last capture keypoints
// below a threshold in the current incoming track and that, as a consequence, last capture keypoints
// was repopulated. In this case, the processor needs to create a new Keyframe whatever happens.
// was repopulated. In this case, the processor needs to create a new Keyframe whatever happens.
...
@@ -415,6 +430,7 @@ bool ProcessorVisualOdometry::voteForKeyFrame() const
...
@@ -415,6 +430,7 @@ bool ProcessorVisualOdometry::voteForKeyFrame() const
vote
=
vote
||
incoming_ptr_
->
getFeatureList
().
size
()
<
params_visual_odometry_
->
min_features_for_keyframe
;
vote
=
vote
||
incoming_ptr_
->
getFeatureList
().
size
()
<
params_visual_odometry_
->
min_features_for_keyframe
;
std
::
cout
<<
"vote "
<<
vote
<<
std
::
endl
;
std
::
cout
<<
"vote "
<<
vote
<<
std
::
endl
;
return
vote
;
return
vote
;
}
}
...
@@ -440,6 +456,8 @@ void ProcessorVisualOdometry::setParams(const ParamsProcessorVisualOdometryPtr _
...
@@ -440,6 +456,8 @@ void ProcessorVisualOdometry::setParams(const ParamsProcessorVisualOdometryPtr _
TracksMap
ProcessorVisualOdometry
::
kltTrack
(
const
cv
::
Mat
_img_prev
,
const
cv
::
Mat
_img_curr
,
const
KeyPointsMap
&
_mwkps_prev
,
KeyPointsMap
&
_mwkps_curr
)
TracksMap
ProcessorVisualOdometry
::
kltTrack
(
const
cv
::
Mat
_img_prev
,
const
cv
::
Mat
_img_curr
,
const
KeyPointsMap
&
_mwkps_prev
,
KeyPointsMap
&
_mwkps_curr
)
{
{
if
(
_mwkps_prev
.
empty
())
return
TracksMap
();
TracksMap
tracks_prev_curr
;
TracksMap
tracks_prev_curr
;
// Create cv point list for tracking, we initialize optical flow with previous keypoints
// Create cv point list for tracking, we initialize optical flow with previous keypoints
...
@@ -456,6 +474,8 @@ TracksMap ProcessorVisualOdometry::kltTrack(const cv::Mat _img_prev, const cv::M
...
@@ -456,6 +474,8 @@ TracksMap ProcessorVisualOdometry::kltTrack(const cv::Mat _img_prev, const cv::M
std
::
vector
<
uchar
>
status
;
std
::
vector
<
uchar
>
status
;
std
::
vector
<
float
>
err
;
std
::
vector
<
float
>
err
;
// Process one way: previous->current with current init with previous
// Process one way: previous->current with current init with previous
ParamsProcessorVisualOdometry
::
KltParams
prms
=
params_visual_odometry_
->
klt_params_
;
ParamsProcessorVisualOdometry
::
KltParams
prms
=
params_visual_odometry_
->
klt_params_
;
cv
::
calcOpticalFlowPyrLK
(
cv
::
calcOpticalFlowPyrLK
(
...
@@ -506,6 +526,7 @@ TracksMap ProcessorVisualOdometry::kltTrack(const cv::Mat _img_prev, const cv::M
...
@@ -506,6 +526,7 @@ TracksMap ProcessorVisualOdometry::kltTrack(const cv::Mat _img_prev, const cv::M
bool
ProcessorVisualOdometry
::
filterWithEssential
(
const
KeyPointsMap
_mwkps_prev
,
const
KeyPointsMap
_mwkps_curr
,
TracksMap
&
_tracks_prev_curr
,
cv
::
Mat
&
_E
)
bool
ProcessorVisualOdometry
::
filterWithEssential
(
const
KeyPointsMap
_mwkps_prev
,
const
KeyPointsMap
_mwkps_curr
,
TracksMap
&
_tracks_prev_curr
,
cv
::
Mat
&
_E
)
{
{
// We need to build lists of pt2f for openCV function
// We need to build lists of pt2f for openCV function
std
::
vector
<
cv
::
Point2f
>
p2f_prev
,
p2f_curr
;
std
::
vector
<
cv
::
Point2f
>
p2f_prev
,
p2f_curr
;
std
::
vector
<
size_t
>
all_indices
;
std
::
vector
<
size_t
>
all_indices
;
...
@@ -533,6 +554,7 @@ bool ProcessorVisualOdometry::filterWithEssential(const KeyPointsMap _mwkps_prev
...
@@ -533,6 +554,7 @@ bool ProcessorVisualOdometry::filterWithEssential(const KeyPointsMap _mwkps_prev
_tracks_prev_curr
.
erase
(
all_indices
.
at
(
k
));
_tracks_prev_curr
.
erase
(
all_indices
.
at
(
k
));
}
}
}
}
return
true
;
return
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment