Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,25 @@ For more details about the parameters, please use `python run_matching_from_*.py
For more details about the underlying method and the interpretation of the results, please have a look at [paper](http://www.ipb.uni-bonn.de/pdfs/vysotska16ral-icra.pdf).
Here is a sketch of what roughly is happening for those who don't like to read much ![](doc/cost_matrix_view.png)

## Parent project
### Adaptive thresholding

This repository is a continuation of my previous works [vpr_relocalization](https://github.com/PRBonn/vpr_relocalization) and [online_place_recognition](https://github.com/PRBonn/online_place_recognition).
This algorithm requires user to provide a value for matching threshold, a value that defines starting with which similarity two images are no longer showing the same place. Selecting a correct value for this is not straightforward and depends on the degree of challenge two image sequences exhibit. For example, when matching summer sequence with respect to winter sequence one threshold value would be fitting, however, the same value may not be good when matching day and night sequences. Moreover, the environment can be gradually changing within one image sequence, for example, it becomes gradually darker when the sun goes down.

Here we provide an option to dynamically adapt the initial threshold. The code will check the current similarity values and adapt the matching threshold accordingly.
To use **adaptive thresholding** add `--adaptThreshold` parameter in the matching call, as shown here:

```bash
python run_matching_from_images.py \
--query_images <path_to_images> \
--reference_images <path_to_images> \
--dataset_name <dataset_name> \
--output_dir <path_to_folder>
--write_image_matches
--adaptThreshold
```

The plan is to gradually modernize and improve the code by preserving the essential capabilities of the system.
For more details, please refer to the [paper](https://www.research-collection.ethz.ch/server/api/core/bitstreams/39b0396e-4743-4bf1-97c6-4cbcf97b0270/content).

**Essential capabilities**:
## Parent project

1. Given two sequences of images compute the matching image pairs.
2. Scripts to visualize the results.
This repository is a continuation of my previous works [vpr_relocalization](https://github.com/PRBonn/vpr_relocalization) and [online_place_recognition](https://github.com/PRBonn/online_place_recognition).
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ int main(int argc, char *argv[]) {
std::make_unique<loc::successor_manager::SuccessorManager>(
database.get(), relocalizer.get(), parser.fanOut);
loc::online_localizer::OnlineLocalizer localizer{
successorManager.get(), parser.expansionRate, parser.matchingThreshold};
successorManager.get(), parser.expansionRate, parser.matchingThreshold, parser.adaptThreshold};
const loc::online_localizer::Matches imageMatches =
localizer.findMatchesTill(parser.querySize);
localizer.findMatchesTill(parser.querySize, parser.debugProto);
loc::online_localizer::storeMatchesAsProto(imageMatches,
parser.matchingResult);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* By O. Vysotska in 2023 */

#include "database/similarity_matrix_database.h"
#include "database/idatabase.h"
#include "database/similarity_matrix_database.h"
#include "online_localizer/online_localizer.h"
#include "online_localizer/path_element.h"
#include "relocalizers/default_relocalizer.h"
Expand Down Expand Up @@ -31,7 +31,8 @@ int main(int argc, char *argv[]) {
parser.print();

const auto database =
std::make_unique<loc::database::SimilarityMatrixDatabase>(parser.similarityMatrix);
std::make_unique<loc::database::SimilarityMatrixDatabase>(
parser.similarityMatrix);

const auto relocalizer =
std::make_unique<loc::relocalizers::DefaultRelocalizer>(
Expand All @@ -41,9 +42,10 @@ int main(int argc, char *argv[]) {
std::make_unique<loc::successor_manager::SuccessorManager>(
database.get(), relocalizer.get(), parser.fanOut);
loc::online_localizer::OnlineLocalizer localizer{
successorManager.get(), parser.expansionRate, parser.matchingThreshold};
successorManager.get(), parser.expansionRate, parser.matchingThreshold,
parser.adaptThreshold};
const loc::online_localizer::Matches imageMatches =
localizer.findMatchesTill(parser.querySize);
localizer.findMatchesTill(parser.querySize, parser.debugProto);
loc::online_localizer::storeMatchesAsProto(imageMatches,
parser.matchingResult);

Expand Down
6 changes: 5 additions & 1 deletion src/localization/database/idatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
#ifndef SRC_DATABASE_IDATABASE_H_
#define SRC_DATABASE_IDATABASE_H_

#include <optional>

namespace localization::database {

/**
* @brief Interface class for a database.
*/
class iDatabase {
public:
virtual int refSize() = 0;
virtual int refSize() const = 0;
/**
* @brief Gets the cost. This cost goes directly in the graph structure.
* Smaller costs correspond to bigger similarities.
Expand All @@ -42,6 +44,8 @@ class iDatabase {
* @return The cost.
*/
virtual double getCost(int quId, int refId) = 0;
virtual std::optional<double> getCostIfComputed(int quId,
int refId) const = 0;

iDatabase() = default;
iDatabase(const iDatabase &) = delete;
Expand Down
18 changes: 18 additions & 0 deletions src/localization/database/online_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ double OnlineDatabase::getCost(int quId, int refId) {
return cost;
}

std::optional<double> OnlineDatabase::getCostIfComputed(int quId,
int refId) const {
if (precomputedScores_) {
if (refId >= refSize()) {
return {};
}
return precomputedScores_->at(quId, refId);
}
auto rowIter = costs_.find(quId);
if (rowIter != costs_.end()) {
auto elementIter = rowIter->second.find(refId);
if (elementIter != rowIter->second.end()) {
return 1. / elementIter->second;
}
}
return {};
}

const features::iFeature &OnlineDatabase::getQueryFeature(int quId) {
return addFeatureIfNeeded(*queryBuffer_, quFeaturesNames_, featureType_,
quId);
Expand Down
5 changes: 3 additions & 2 deletions src/localization/database/online_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#ifndef SRC_DATABASE_ONLINE_DATABASE_H_
#define SRC_DATABASE_ONLINE_DATABASE_H_

#include "database/similarity_matrix.h"
#include "database/idatabase.h"
#include "database/similarity_matrix.h"
#include "features/feature_buffer.h"
#include "features/feature_factory.h"

Expand All @@ -48,8 +48,9 @@ class OnlineDatabase : public iDatabase {
const std::string &refFeaturesDir, features::FeatureType type,
int bufferSize, const std::string &similarityMatrixFile = "");

inline int refSize() override { return refFeaturesNames_.size(); }
inline int refSize() const override { return refFeaturesNames_.size(); }
double getCost(int quId, int refId) override;
std::optional<double> getCostIfComputed(int quId, int refId) const override;

double computeMatchingCost(int quId, int refId);

Expand Down
8 changes: 8 additions & 0 deletions src/localization/database/similarity_matrix_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ double SimilarityMatrixDatabase::getCost(int quId, int refId) {
return similarityMatrix_.getCost(quId, refId);
}

std::optional<double> SimilarityMatrixDatabase::getCostIfComputed(int quId,
int refId) const {
if (refId >= refSize()) {
return {};
}
return similarityMatrix_.at(quId, refId);
}

} // namespace localization::database
3 changes: 2 additions & 1 deletion src/localization/database/similarity_matrix_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class SimilarityMatrixDatabase : public iDatabase {
public:
explicit SimilarityMatrixDatabase(const std::string &costMatrixFile);

int refSize() override { return similarityMatrix_.cols(); }
int refSize() const override { return similarityMatrix_.cols(); }
double getCost(int quId, int refId) override;
std::optional<double> getCostIfComputed(int quId, int refId) const override;

private:
SimilarityMatrix similarityMatrix_;
Expand Down
4 changes: 4 additions & 0 deletions src/localization/online_localizer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(math_tools)

add_library(path_element path_element.cpp)
target_link_libraries(path_element
cxx_flags
Expand All @@ -14,6 +16,8 @@ target_link_libraries(online_localizer
successor_manager
node
timer
gmm
statistical_test
protos
glog::glog
)
19 changes: 19 additions & 0 deletions src/localization/online_localizer/math_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_library(math_tools math_tools.cpp)
target_link_libraries(math_tools
cxx_flags
glog::glog
)

add_library(gmm gmm.cpp)
target_link_libraries(gmm
math_tools
cxx_flags
glog::glog
)

add_library(statistical_test statistical_test.cpp constants.h)
target_link_libraries(statistical_test
math_tools
cxx_flags
glog::glog
)
Loading
Loading