Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "3rdparty/imgui"]
path = 3rdparty/imgui
url = git@github.com:ocornut/imgui.git
[submodule "3rdparty/DBow3"]
path = 3rdparty/DBow3
url = git@github.com:rmsalinas/DBow3.git
1 change: 1 addition & 0 deletions 3rdparty/DBow3
Submodule DBow3 added at c5ae53
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ else()
add_compile_options()
endif()

option(BUILD_TOOLS "Build Edrak Tools" ON)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

Expand Down Expand Up @@ -52,6 +54,15 @@ ${IMGGUI_PATH}/backends/imgui_impl_opengl3.cpp
add_library(ImgGui ${IMGUI_SRCS})
target_link_libraries(ImgGui ${CONAN_LIBS})

#DBOW3
find_package(DBoW3)
if(${DBoW3_FOUND})
message(STATUS "Found DBoW3")
else()
add_subdirectory(3rdparty/DBow3)
find_package(DBoW3 REQUIRED)
endif()


# Src files
set(EDRAK_SRC_FILES Edrak/src/IO/MonoReader.cpp
Expand All @@ -72,6 +83,7 @@ target_include_directories(Edrak PUBLIC Edrak/include)
target_link_libraries(Edrak ${CONAN_LIBS})
target_link_libraries(Edrak ${Pangolin_LIBRARIES})
target_link_libraries(Edrak ${G2O_CORE_LIBRARY} ${G2O_STUFF_LIBRARY})
target_link_libraries(Edrak DBoW3)



Expand All @@ -89,6 +101,10 @@ if(EDRAK_BUILD_EXAMPLES)
add_subdirectory(Examples/ Examples)
endif(EDRAK_BUILD_EXAMPLES)

# Build Tools
if(BUILD_TOOLS)
add_subdirectory(tools)
endif()

enable_testing()

Expand Down
3 changes: 3 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

add_executable(TrainDBow3 train_DBow.cpp)
target_link_libraries(TrainDBow3 Edrak)
47 changes: 47 additions & 0 deletions tools/train_DBow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "DBoW3.h"
#include "Edrak/IO/MonoReader.hpp"
#include "Edrak/Images/Features.hpp"
#include <iostream>

void PrintUsage() {
std::cout << "How to use: ./TrainDBow3 ImagesFolderPath/*.png OutputDBPath"
<< std::endl;
}

vector<cv::Mat> ExtractFeatures(const Edrak::IO::Reader &imgsReader) {
vector<cv::Mat> features;
Edrak::Images::Features::KeyPoints::KeyPoints kps;
cv::Mat image;
while (imgsReader.NextFrame(image)) {
cv::Mat descriptors;
Edrak::Images::Features::ORB(image, kps, descriptors);
features.push_back(descriptors);
}
std::cout << "Processed " << features.size() << " Images" << std::endl;
return features;
}

void CreateVocab(const vector<cv::Mat> &features, const std::string &filePath) {
// branching factor and depth levels
const int k = 9;
const int L = 3;
const WeightingType weight = TF_IDF;
const ScoringType score = L1_NORM;
DBoW3::Vocabulary voc(k, L, weight, score);
voc.create(features);
std::cout << "Vocabulary information: " << std::endl << voc << std::endl;
// save the vocabulary to disk
voc.save(filePath);
std::cout << "Vocabulary saved to " << filePath << std::endl;
}

int main(int argc, char const *argv[]) {
if (argc < 3) {
PrintUsage();
return -1;
}
Edrak::IO::Reader imgsReader(argv[1]);
auto orbFeatures = ExtractFeatures(imgsReader);
CreateVocab(orbFeatures, argv[2]);
return 0;
}