Skip to content
Snippets Groups Projects
Commit ca41f142 authored by Sergi Pujol's avatar Sergi Pujol
Browse files

refactoring loop_closure_falko functions

parent 8beaf6cf
No related branches found
No related tags found
1 merge request!4Resolve "Implementation of Falko lib"
......@@ -90,7 +90,6 @@ SET(SRCS
point_set.cpp
polyline.cpp
scan_segment.cpp
loop_closure_base.cpp
)
IF(csm_FOUND)
SET(SRCS ${SRCS}
......@@ -99,8 +98,7 @@ SET(SRCS
IF(falkolib_FOUND)
SET(SRCS ${SRCS}
corner_falko_2d.cpp
loop_closure_falko.cpp)
corner_falko_2d.cpp)
ENDIF(falkolib_FOUND)
......
......@@ -17,21 +17,8 @@
**************************/
#include "laser_scan.h"
#include "scene_base.h"
#include "scene_falko.h"
#include "match_loop_closure.h"
/**************************
* Falko includes *
**************************/
#include <falkolib/Feature/BSC.h>
#include <falkolib/Feature/CGH.h>
#include <falkolib/Feature/FALKO.h>
#include <falkolib/Feature/FALKOExtractor.h>
#include <falkolib/Feature/BSCExtractor.h>
#include <falkolib/Feature/CGHExtractor.h>
#include <falkolib/Matching/AHTMatcher.h>
#include <falkolib/Matching/NNMatcher.h>
namespace laserscanutils {
......@@ -42,23 +29,30 @@ private:
public:
/** \brief Constructor
**/
loopClosureBase2d();
loopClosureBase2d(){};
/** \brief Destructor
**/
~loopClosureBase2d();
~loopClosureBase2d(){};
/** \brief compare new scans against the trained set in order to find loop
*closures
**/
// virtual void findLoopClosure(std::list<cornerScene>& scenes, const
// cornerScene newScene){}
// virtual void findLoopClosure(){}
/** \brief update the scene struct with keypoints and descriptors
**/
virtual std::shared_ptr<sceneFalko<falkolib::BSC>>
extractScene(LaserScan &scan, LaserScanParams &scanParams) {}
virtual sceneBasePtr
extractScene(LaserScan &scan, LaserScanParams &scanParams) =0;
/** \brief Create and update a matchLoopClosure struct with the info that is
*produced when matching two given scenes
**/
virtual matchLoopClosurePtr matchScene(sceneBasePtr _scene1,
sceneBasePtr _scene2) =0;
/** \brief compare new scans against the trained set in order to find loop
*closures
**/
virtual std::map<double,matchLoopClosurePtr>
findLoopClosure(std::list<sceneBasePtr> _l_scenes,
const sceneBasePtr _new_scene)=0;
};
} /* namespace laserscanutils */
......
/**
* \file loop_closure_base_2d.h
*
* Created on: Feb 9, 2021
* \author: spujol
*/
#include "loop_closure_falko.h"
namespace laserscanutils {
// CONSTRUCTOR
/*
template <typename D, typename Extr, typename M>
loopClosureFalko<D, Extr, M>::loopClosureFalko(int _circularSectorNumber,
int _radialRingNumber)
: loopClosureBase2d(), falkolib::FALKOExtractor(),
extractor_(_circularSectorNumber, _radialRingNumber), matcher_() {
// FALKO Extractor Parameters
setMinExtractionRange(0.1);
setMaxExtractionRange(25);
enableSubbeam(true);
setNMSRadius(0.1);
setNeighB(0.01);
setBRatio(4);
setGridSectors(16);
// Matcher Extractor Parameters
matcher_.setDistanceThreshold(0.1);
}
*/
/*
// DESTRUCTOR
template <typename D,typename Extr, typename M>
loopClosureFalko<D,Extr,M>::~loopClosureFalko(){}
*/
/*
template <typename D, typename Extr, typename M>
std::shared_ptr<falkolib::LaserScan>
loopClosureFalko<D, Extr, M>::convert2LaserScanFALKO(
LaserScan &scan, LaserScanParams &scanParams) {
auto scanFALKO = std::make_shared<falkolib::LaserScan>(
scanParams.angle_min_, scanParams.angle_max_, scan.ranges_raw_.size());
std::vector<double> doubleRanges(scan.ranges_raw_.begin(),
scan.ranges_raw_.end());
((*scanFALKO).fromRanges)(doubleRanges);
return scanFALKO;
}
*/
/*
template <typename D,typename Extr, typename M>
typename loopClosureFalko<D,Extr, M>::sceneFalkoBSCPtr
loopClosureFalko<D,Extr, M>::extractScene(LaserScan &scan,LaserScanParams
&scanParams){
auto newScene=std::make_shared<sceneFalko<D>>();
auto scanFALKO =loopClosureFalko<D,Extr,M>::convert2LaserScanFALKO(scan,
scanParams);
// Extract keypoints
extract((*scanFALKO), (newScene->keypointsList));
// Compute descriptors
extractor_.compute(*scanFALKO,newScene->keypointsList,
newScene->descriptorsList);
return newScene;
}
*/
/*
template <typename D,typename Extr, typename M>
typename loopClosureFalko<D,Extr, M>::matchLoopClosurePtr
matchScene(std::shared_ptr<sceneFalko<D>>
scene1,std::shared_ptr<sceneFalko<D>> scene2){
std::vector<std::pair<int, int> > assoNN;
int matching_number = match(scene1->keypointsList,scene2->keypointsList,
assoNN);
auto new_match=std::make_shared<matchLoopClosure<D>>();
new_match-> keypointsNumberMatch = matching_number;
int keypoints_number_th=5;
if (matching_number>keypoints_number_th){
new_match-> match = true;
} else {
new_match-> match = false;
}
new_match -> sceneTuple[0] = scene1;
new_match -> sceneTuple[1] = scene2;
return new_match;
}
*/
// void findLoopClosure(std::list<sceneFalko>& scenes, const cornerScene
// newScene){}
// Explicitly compile all the templates
//template class loopClosureFalko<bsc, bscExtractor, NNMatcher>;
}
......@@ -74,7 +74,6 @@ class loopClosureFalko : public loopClosureBase2d,
private:
public:
typedef std::shared_ptr<sceneFalko<D>> sceneFalkoBSCPtr;
typedef std::shared_ptr<matchLoopClosure<D>> matchLoopClosurePtr;
typedef std::shared_ptr<falkolib::LaserScan> laserScanPtr;
Extr extractor_;
......@@ -105,7 +104,7 @@ public:
/** \brief Create and update the scene struct with keypoints and descriptors
**/
sceneFalkoBSCPtr extractScene(LaserScan &_scan, LaserScanParams &_scan_params) {
sceneBasePtr extractScene(LaserScan &_scan, LaserScanParams &_scan_params) override{
auto new_scene = std::make_shared<sceneFalko<D>>();
auto scan_falko =
convert2LaserScanFALKO(_scan, _scan_params);
......@@ -132,35 +131,42 @@ public:
/** \brief Create and update a matchLoopClosure struct with the info that is
*produced when matching two given scenes
**/
matchLoopClosurePtr matchScene(sceneFalkoBSCPtr _scene1,
sceneFalkoBSCPtr _scene2) {
matchLoopClosurePtr matchScene(sceneBasePtr _scene1,
sceneBasePtr _scene2) override{
std::vector<std::pair<int, int>> asso_nn;
auto scene_1_falko =std::static_pointer_cast<sceneFalko<D>>(_scene1);
auto scene_2_falko =std::static_pointer_cast<sceneFalko<D>>(_scene2);
int matching_number =
matcher_.match(_scene1->keypoints_list_, _scene2->keypoints_list_, asso_nn);
auto new_match = std::make_shared<matchLoopClosure<D>>();
new_match->keypointsNumberMatch = matching_number;
matcher_.match(scene_1_falko->keypoints_list_,
scene_2_falko->keypoints_list_, asso_nn);
auto new_match = std::make_shared<matchLoopClosure>();
new_match->keypoints_number_match = matching_number;
if (matching_number > keypoints_number_th_) {
new_match->match = true;
} else {
new_match->match = false;
}
new_match->sceneTuple = std::make_tuple(_scene1, _scene2);
new_match->scene_1 =_scene1;
new_match->scene_2 =_scene2;
new_match->score = (double) matching_number / (double) std::min(scene_1_falko->keypoints_list_.size(),
scene_2_falko->keypoints_list_.size());
return new_match;
}
/** \brief compare new scans against the trained set in order to find loop
*closures
**/
std::list<matchLoopClosurePtr>
findLoopClosure(std::list<sceneFalkoBSCPtr> &_l_scenes,
const sceneFalkoBSCPtr &_new_scene) {
int number_ref_sc = _l_scenes.size();
std::list<matchLoopClosurePtr> matchings;
for (int i = 0; i < number_ref_sc; i++) {
auto l_front = _l_scenes.begin();
std::advance(l_front, i);
auto new_match = matchScene(*l_front, _new_scene);
matchings.push_back(new_match);
std::map<double,matchLoopClosurePtr>
findLoopClosure(std::list<sceneBasePtr> _l_scenes,
const sceneBasePtr _new_scene) override{
auto new_scene_falko = std::static_pointer_cast<sceneFalko<D>>(_new_scene);
std::map<double,matchLoopClosurePtr> matchings;
for (auto scene : _l_scenes)
{
auto ref_scene = std::static_pointer_cast<sceneFalko<D>>(scene);
auto match = matchScene(ref_scene, new_scene_falko);
matchings.emplace(match->score, match);
}
return matchings;
}
......
......@@ -20,16 +20,17 @@
namespace laserscanutils {
template <typename D> struct matchLoopClosure {
struct matchLoopClosure {
// tuple that stores the pointers of two matched scenes
std::tuple<std::shared_ptr<sceneFalko<D>>, std::shared_ptr<sceneFalko<D>>>
sceneTuple;
sceneBasePtr scene_1;
sceneBasePtr scene_2;
bool match;
int keypointsNumberMatch;
int keypoints_number_match;
double score;
};
typedef std::shared_ptr<matchLoopClosure> matchLoopClosurePtr;
} /* namespace laserscanutils */
#endif /* MATCH_LOOP_CLOSURE_H_ */
......@@ -13,10 +13,10 @@
namespace laserscanutils {
struct sceneBase {
// std::vector<falkolib::FALKO> keypointsList;
// std::vector<D> descriptorsList;
};
typedef std::shared_ptr<sceneBase> sceneBasePtr;
} /* namespace laserscanutils */
......
......@@ -8,13 +8,15 @@ using namespace laserscanutils;
TEST(loop_closure_falko, TestLoopClosureFalkoAllFunctions) {
// Initialization
int scan_size = 1440;
LaserScan scan;
LaserScan scan, scan2;
LaserScanParams laser_params;
laser_params.angle_min_ = 0;
laser_params.angle_max_ = 2.0 * M_PI;
for (int i = 0; i < scan_size; i++) {
scan.ranges_raw_.push_back(testRanges1[i]);
scan2.ranges_raw_.push_back(testRanges2[i]);
}
parameterLoopClosureFalko param;
loopClosureFalko<bsc, bscExtractor, NNMatcher> loop_cl_falko(param);
......@@ -26,7 +28,8 @@ TEST(loop_closure_falko, TestLoopClosureFalkoAllFunctions) {
ASSERT_EQ(firstPoint, 250);
// Test extractScene
auto new_scene = loop_cl_falko.extractScene(scan, laser_params);
auto new_scene = std::static_pointer_cast<sceneFalko<bsc>>(loop_cl_falko.extractScene(scan, laser_params));
auto new_scene2 = std::static_pointer_cast<sceneFalko<bsc>>(loop_cl_falko.extractScene(scan2, laser_params));
int detectedKeypoints = new_scene->keypoints_list_.size();
int detectedDescriptors = new_scene->descriptors_list_.size();
ASSERT_EQ(detectedKeypoints, 18);
......@@ -34,20 +37,25 @@ TEST(loop_closure_falko, TestLoopClosureFalkoAllFunctions) {
// Test matcheScene
auto new_match = loop_cl_falko.matchScene(new_scene, new_scene);
int keypoints_matched = new_match->keypointsNumberMatch;
ASSERT_EQ(keypoints_matched, 18);
ASSERT_EQ(new_match->keypoints_number_match, 18);
// TEST findLoopClosure
std::list<std::shared_ptr<sceneFalko<bsc>>> ref_scenes;
ref_scenes.push_back(new_scene);
ref_scenes.push_back(new_scene);
auto matchings = loop_cl_falko.findLoopClosure(ref_scenes, new_scene);
int matchings_number = matchings.size();
ASSERT_EQ(matchings_number, 2);
auto l_front = matchings.begin();
auto there_is_match = l_front->get()->match;
ASSERT_EQ(there_is_match, true);
ref_scenes.push_back(new_scene2);
//auto matchings = loop_cl_falko.findLoopClosure(ref_scenes, new_scene);
/*
ASSERT_EQ(matchings.size(), 2);
auto best_match = matchings.rbegin()->second;
ASSERT_EQ(best_match->match, true);
ASSERT_EQ(best_match->scene_1, new_scene);
ASSERT_EQ(best_match->scene_2, new_scene);
ASSERT_EQ(best_match->score, 1);
*/
// PRINTF("All good at TestTest::DummyTestExample !\n");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment