Skip to content

Commit 3ab4cd2

Browse files
committed
Merge branch 'config' into dev
2 parents b47372a + 204eed4 commit 3ab4cd2

File tree

12 files changed

+1908
-40
lines changed

12 files changed

+1908
-40
lines changed

cmake/depends/cereal.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if(NOT TARGET depends::cereal)
2+
if(NOT TARGET options::cpp17)
3+
message(FATAL_ERROR "depends::cereal expects options::cpp17")
4+
endif()
5+
FetchContent_Declare(
6+
depends-cereal
7+
GIT_REPOSITORY https://github.com/USCiLab/cereal.git
8+
GIT_TAG v1.3.2
9+
)
10+
FetchContent_GetProperties(depends-cereal)
11+
if(NOT depends-cereal_POPULATED)
12+
message(STATUS "Fetching cereal sources")
13+
FetchContent_Populate(depends-cereal)
14+
message(STATUS "Fetching cereal sources - done")
15+
endif()
16+
17+
add_library(depends::cereal INTERFACE IMPORTED GLOBAL)
18+
target_include_directories(depends::cereal INTERFACE ${depends-cereal_SOURCE_DIR}/include)
19+
target_link_libraries(depends::cereal INTERFACE options::cpp17)
20+
21+
set(depends-cereal-source-dir ${depends-cereal_SOURCE_DIR} CACHE INTERNAL "" FORCE)
22+
mark_as_advanced(depends-cereal-source-dir)
23+
endif()

configs/euroc_slam.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ parsac:
4141
threshold: 1.0
4242
norm_scale: 1.0
4343
keyframe_check_size: 1
44+
45+
backend:
46+
backend_flag: true
47+
voc_file: Vocabulary/ORBvoc.txt
48+
orb_n_features: 1000
49+
orb_scale_factor: 1.2
50+
orb_n_levels: 8
51+
orb_init_threshold_fast: 20
52+
orb_min_threshold_fast: 7

xrslam-extra/include/xrslam/extra/yaml_config.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ class YamlConfig : public Config {
8888
double rotation_misalignment_threshold() const override;
8989
double rotation_ransac_threshold() const override;
9090

91+
bool backend_flag() const override;
92+
std::string backend_voc_file() const override;
93+
size_t backend_orb_n_features() const override;
94+
double backend_orb_scale_factor() const override;
95+
size_t backend_orb_n_levels() const override;
96+
size_t backend_orb_init_threshold_fast() const override;
97+
size_t backend_orb_min_threshold_fast() const override;
98+
99+
91100
private:
92101
vector<2> m_camera_resolution;
93102
matrix<3> m_camera_intrinsic;
@@ -144,6 +153,15 @@ class YamlConfig : public Config {
144153

145154
double m_rotation_misalignment_threshold;
146155
double m_rotation_ransac_threshold;
156+
157+
bool m_backend_flag;
158+
std::string m_backend_voc_file;
159+
size_t m_backend_orb_n_features;
160+
double m_backend_orb_scale_factor;
161+
size_t m_backend_orb_n_levels;
162+
size_t m_backend_orb_init_threshold_fast;
163+
size_t m_backend_orb_min_threshold_fast;
164+
147165
};
148166

149167
} // namespace xrslam::extra

xrslam-extra/src/xrslam/extra/yaml_config.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ YamlConfig::YamlConfig(const std::string &slam_config_filename,
124124
m_visual_localization_ip = Config::visual_localization_config_ip();
125125
m_visual_localization_port = Config::visual_localization_config_port();
126126

127+
m_backend_flag = Config::backend_flag();
128+
m_backend_voc_file = Config::backend_voc_file();
129+
m_backend_orb_n_features = Config::backend_orb_n_features();
130+
m_backend_orb_scale_factor = Config::backend_orb_scale_factor();
131+
m_backend_orb_n_levels = Config::backend_orb_n_levels();
132+
m_backend_orb_init_threshold_fast = Config::backend_orb_init_threshold_fast();
133+
m_backend_orb_min_threshold_fast = Config::backend_orb_min_threshold_fast();
134+
127135
YAML::Node slam_config;
128136
YAML::Node device_config;
129137
try {
@@ -360,6 +368,35 @@ YamlConfig::YamlConfig(const std::string &slam_config_filename,
360368
find_node(slam_config, "rotation.ransac_threshold", false)) {
361369
assign(m_rotation_ransac_threshold, node);
362370
}
371+
372+
if (auto node = find_node(slam_config, "backend.backend_flag", false)) {
373+
assign(m_backend_flag, node);
374+
}
375+
376+
if (auto node = find_node(slam_config, "backend.voc_file", false)) {
377+
assign(m_backend_voc_file, node);
378+
}
379+
380+
if (auto node = find_node(slam_config, "backend.orb_n_features", false)) {
381+
assign(m_backend_orb_n_features, node);
382+
}
383+
384+
if (auto node = find_node(slam_config, "backend.orb_scale_factor", false)) {
385+
assign(m_backend_orb_scale_factor, node);
386+
}
387+
388+
if (auto node = find_node(slam_config, "backend.orb_n_levels", false)) {
389+
assign(m_backend_orb_n_levels, node);
390+
}
391+
392+
if (auto node = find_node(slam_config, "backend.orb_init_threshold_fast", false)) {
393+
assign(m_backend_orb_init_threshold_fast, node);
394+
}
395+
396+
if (auto node = find_node(slam_config, "backend.orb_min_threshold_fast", false)) {
397+
assign(m_backend_orb_min_threshold_fast, node);
398+
}
399+
363400
}
364401

365402
YamlConfig::~YamlConfig() = default;
@@ -534,4 +571,18 @@ double YamlConfig::rotation_ransac_threshold() const {
534571
return m_rotation_ransac_threshold;
535572
}
536573

574+
bool YamlConfig::backend_flag() const { return m_backend_flag; }
575+
576+
std::string YamlConfig::backend_voc_file() const { return m_backend_voc_file; }
577+
578+
size_t YamlConfig::backend_orb_n_features() const { return m_backend_orb_n_features; }
579+
580+
double YamlConfig::backend_orb_scale_factor() const { return m_backend_orb_scale_factor; }
581+
582+
size_t YamlConfig::backend_orb_n_levels() const { return m_backend_orb_n_levels; }
583+
584+
size_t YamlConfig::backend_orb_init_threshold_fast() const { return m_backend_orb_init_threshold_fast; }
585+
586+
size_t YamlConfig::backend_orb_min_threshold_fast() const { return m_backend_orb_min_threshold_fast; }
587+
537588
} // namespace xrslam::extra

xrslam/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include(SuperBuildDepends)
66
superbuild_depend(eigen)
77
superbuild_depend(ceres-solver)
88
superbuild_depend(spdlog)
9+
superbuild_depend(cereal)
910

1011
configure_file(cmake/version.h.in include/xrslam/version.h)
1112

@@ -63,7 +64,11 @@ set(PRIVATE_HEADERS
6364
${XRSLAM_SOURCE_DIR}/xrslam/utility/worker.h
6465
${XRSLAM_SOURCE_DIR}/xrslam/utility/logger.h
6566
${XRSLAM_SOURCE_DIR}/xrslam/utility/parsac.h
67+
${XRSLAM_SOURCE_DIR}/xrslam/utility/serialize.h
68+
${XRSLAM_SOURCE_DIR}/xrslam/utility/potocal.h
6669
${XRSLAM_SOURCE_DIR}/xrslam/utility/imu_parsac.h
70+
${XRSLAM_SOURCE_DIR}/xrslam/utility/orb_extractor.h
71+
${XRSLAM_SOURCE_DIR}/xrslam/utility/client.h
6772
${XRSLAM_SOURCE_DIR}/xrslam/ar/virtual_object_manager.h
6873
${XRSLAM_SOURCE_DIR}/xrslam/localizer/base64.h
6974
${XRSLAM_SOURCE_DIR}/xrslam/localizer/base64_convert.h
@@ -92,6 +97,7 @@ set(PRIVATE_SOURCES
9297
${XRSLAM_SOURCE_DIR}/xrslam/xrslam.cpp
9398
${XRSLAM_SOURCE_DIR}/xrslam/utility/debug.cpp
9499
${XRSLAM_SOURCE_DIR}/xrslam/utility/worker.cpp
100+
${XRSLAM_SOURCE_DIR}/xrslam/utility/orb_extractor.cpp
95101
${XRSLAM_SOURCE_DIR}/xrslam/localizer/localizer.cpp
96102
${XRSLAM_SOURCE_DIR}/xrslam/ar/virtual_object_manager.cpp
97103
)
@@ -139,6 +145,7 @@ PUBLIC
139145
depends::spdlog
140146
depends::ceres-solver
141147
depends::opencv
148+
depends::cereal
142149
)
143150

144151
set(XRSLAM_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")

xrslam/include/xrslam/xrslam.h

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,47 @@
77
#include <opencv2/opencv.hpp>
88
#include <vector>
99
#include <xrslam/version.h>
10-
#include <chrono>
11-
#include <thread>
1210

1311
namespace xrslam {
1412

15-
template <int Rows = Eigen::Dynamic, int Cols = Rows, bool UseRowMajor = false, typename T = double>
13+
template <int Rows = Eigen::Dynamic, int Cols = Rows, bool UseRowMajor = false,
14+
typename T = double>
1615
using matrix = typename std::conditional<
1716
Rows != 1 && Cols != 1,
18-
Eigen::Matrix<T, Rows, Cols, UseRowMajor ? Eigen::RowMajor : Eigen::ColMajor>,
17+
Eigen::Matrix<T, Rows, Cols,
18+
UseRowMajor ? Eigen::RowMajor : Eigen::ColMajor>,
1919
Eigen::Matrix<T, Rows, Cols>>::type;
2020

21-
template <int Dimension = Eigen::Dynamic, bool RowVector = false, typename T = double>
21+
template <int Dimension = Eigen::Dynamic, bool RowVector = false,
22+
typename T = double>
2223
using vector =
2324
typename std::conditional<RowVector, matrix<1, Dimension, false, T>,
2425
matrix<Dimension, 1, false, T>>::type;
2526

2627
using quaternion = Eigen::Quaternion<double>;
2728

28-
using matrix6 = matrix<6, 6>;
29-
using matrix3 = matrix<3, 3>;
30-
using matrix2 = matrix<2, 2>;
31-
using matrix1 = matrix<1, 1>;
32-
using matrix6x3 = matrix<6, 3>;
33-
using matrix6x1 = matrix<6, 1>;
34-
using matrixX = matrix<-1, -1>;
35-
36-
using vector6 = vector<6>;
37-
using vector5 = vector<5>;
38-
using vector4 = vector<4>;
39-
using vector3 = vector<3>;
40-
using vector2 = vector<2>;
41-
using vector1 = vector<1>;
42-
using vectorX = vector<-1>;
43-
4429
struct Pose {
4530
Pose() {
4631
q.setIdentity();
4732
p.setZero();
4833
}
4934
quaternion q;
5035
vector<3> p;
36+
37+
matrix<4> to_matrix(){
38+
matrix<4> T;
39+
T.setIdentity();
40+
T.block<3, 3>(0, 0) = q.toRotationMatrix();
41+
T.block<3, 1>(0, 3) = p;
42+
return T;
43+
}
44+
45+
static Pose from_matrix(matrix<4> T){
46+
Pose pose;
47+
pose.q = quaternion(T.block<3, 3>(0, 0));
48+
pose.p = T.block<3, 1>(0, 3);
49+
return pose;
50+
}
5151
};
5252

5353
using OutputPose = Pose;
@@ -68,6 +68,7 @@ struct OutputObject {
6868
int isolated;
6969
};
7070

71+
7172
class Config {
7273
public:
7374
virtual ~Config();
@@ -131,6 +132,14 @@ class Config {
131132
virtual double parsac_norm_scale() const;
132133
virtual size_t parsac_keyframe_check_size() const;
133134

135+
virtual bool backend_flag() const;
136+
virtual std::string backend_voc_file() const;
137+
virtual size_t backend_orb_n_features() const;
138+
virtual double backend_orb_scale_factor() const;
139+
virtual size_t backend_orb_n_levels() const;
140+
virtual size_t backend_orb_init_threshold_fast() const;
141+
virtual size_t backend_orb_min_threshold_fast() const;
142+
134143
void log_config() const;
135144
};
136145

@@ -189,25 +198,6 @@ class XRSLAM {
189198
std::unique_ptr<Detail> detail;
190199
};
191200

192-
struct Timer{
193-
Timer(){reset();}
194-
195-
void reset(){
196-
t1 = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
197-
}
198-
199-
double get_time(){
200-
double t2 = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
201-
return t2 - t1;
202-
}
203-
204-
void sleep(double seconds){
205-
std::this_thread::sleep_for(std::chrono::milliseconds((int)(seconds * 1000)));
206-
}
207-
208-
double t1;
209-
};
210-
211201
} // namespace xrslam
212202

213203
#endif // XRSLAM_XRSLAM_H

xrslam/src/xrslam/config.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ size_t Config::parsac_keyframe_check_size() const { return 3; }
7777

7878
size_t Config::sliding_window_tracker_frequent() const { return 1; }
7979

80+
bool Config::backend_flag() const { return false; }
81+
82+
std::string Config::backend_voc_file() const { return "Vocabulary/ORBvoc.txt"; }
83+
84+
size_t Config::backend_orb_n_features() const { return 1000; }
85+
86+
double Config::backend_orb_scale_factor() const { return 1.2; }
87+
88+
size_t Config::backend_orb_n_levels() const { return 8; }
89+
90+
size_t Config::backend_orb_init_threshold_fast() const { return 20; }
91+
92+
size_t Config::backend_orb_min_threshold_fast() const { return 7; }
93+
8094
void Config::log_config() const {
8195
std::stringstream ss;
8296
ss << std::scientific << std::boolalpha << std::setprecision(5);
@@ -215,6 +229,20 @@ void Config::log_config() const {
215229
ss << "Config::rotation_ransac_threshold: " << rotation_ransac_threshold()
216230
<< std::endl;
217231

232+
ss << "Config::backend_flag: " << backend_flag() << std::endl;
233+
234+
ss << "Config::backend_voc_file: " << backend_voc_file() << std::endl;
235+
236+
ss << "Config::backend_orb_n_features: " << backend_orb_n_features() << std::endl;
237+
238+
ss << "Config::backend_orb_scale_factor: " << backend_orb_scale_factor() << std::endl;
239+
240+
ss << "Config::backend_orb_n_levels: " << backend_orb_n_levels() << std::endl;
241+
242+
ss << "Config::backend_orb_init_threshold_fast: " << backend_orb_init_threshold_fast() << std::endl;
243+
244+
ss << "Config::backend_orb_min_threshold_fast: " << backend_orb_min_threshold_fast() << std::endl;
245+
218246
#if defined(XRSLAM_ENABLE_THREADING)
219247
ss << std::endl;
220248
ss << "THREADING ENABLE" << std::endl;

0 commit comments

Comments
 (0)