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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@
[submodule "3rdparty/libE57Format"]
path = 3rdparty/libE57Format
url = https://github.com/asmaloney/libE57Format.git
[submodule "3rdparty/fbow"]
path = 3rdparty/fbow
url = https://github.com/rmsalinas/fbow.git
1 change: 1 addition & 0 deletions 3rdparty/fbow
Submodule fbow added at e148db
89 changes: 89 additions & 0 deletions 3rdparty/patches/fbow_non_x86.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
diff --git a/src/cpu.h b/src/cpu.h
index 7dcb7e3..7b73e7e 100644
--- a/src/cpu.h
+++ b/src/cpu.h
@@ -4,7 +4,11 @@
#include <cstdint>
#include <cstring>
#include <string>
-#ifdef __ANDROID__
+// No x86 SIMD/cpuid off x86 (Android, arm64 e.g. Apple Silicon): portable code paths only.
+#if defined(__ANDROID__) || !(defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86))
+#define FBOW_NO_X86 1
+#endif
+#ifdef FBOW_NO_X86

#else
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
@@ -48,7 +52,7 @@ private:
static bool inline detect_OS_AVX512();
static inline uint64_t xgetbv(unsigned int x);
};
-#ifdef __ANDROID__
+#ifdef FBOW_NO_X86

void cpu::cpuid(int32_t out[4], int32_t x){}
#else
@@ -91,7 +95,7 @@ bool cpu::detect_OS_x64(){ return true;}
////////////////////////////////////////////////////////////////////////////////
bool cpu::detect_OS_AVX(){
// Copied from: http://stackoverflow.com/a/22521619/922184
-#ifndef __ANDROID__
+#ifndef FBOW_NO_X86

bool avxSupported = false;
int cpuInfo[4]; cpuid(cpuInfo, 1);
@@ -105,7 +109,7 @@ bool cpu::detect_OS_AVX(){
}
bool cpu::detect_OS_AVX512(){

-#ifndef __ANDROID__
+#ifndef FBOW_NO_X86
if (!detect_OS_AVX())
return false;
uint64_t xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
@@ -118,7 +122,7 @@ bool cpu::detect_OS_AVX512(){
std::string cpu::get_vendor_string(){ int32_t CPUInfo[4]; char name[13];cpuid(CPUInfo, 0); memcpy(name + 0, &CPUInfo[1], 4);memcpy(name + 4, &CPUInfo[3], 4); memcpy(name + 8, &CPUInfo[2], 4); name[12] = '\0'; return name;}
void cpu::detect_host(){

-#ifndef __ANDROID__
+#ifndef FBOW_NO_X86

OS_x64 = detect_OS_x64();
OS_AVX = detect_OS_AVX();
@@ -136,6 +140,9 @@ void cpu::detect_host(){
if (nIds >= 0x00000001){ cpuid(info, 0x00000001); HW_MMX = (info[3] & ((int)1 << 23)) != 0; HW_SSE = (info[3] & ((int)1 << 25)) != 0; HW_SSE2 = (info[3] & ((int)1 << 26)) != 0; HW_SSE3 = (info[2] & ((int)1 << 0)) != 0; HW_SSSE3 = (info[2] & ((int)1 << 9)) != 0; HW_SSE41 = (info[2] & ((int)1 << 19)) != 0; HW_SSE42 = (info[2] & ((int)1 << 20)) != 0; HW_AES = (info[2] & ((int)1 << 25)) != 0; HW_AVX = (info[2] & ((int)1 << 28)) != 0; HW_FMA3 = (info[2] & ((int)1 << 12)) != 0; HW_RDRAND = (info[2] & ((int)1 << 30)) != 0; }
if (nIds >= 0x00000007){ cpuid(info, 0x00000007); HW_AVX2 = (info[1] & ((int)1 << 5)) != 0; HW_BMI1 = (info[1] & ((int)1 << 3)) != 0; HW_BMI2 = (info[1] & ((int)1 << 8)) != 0; HW_ADX = (info[1] & ((int)1 << 19)) != 0; HW_MPX = (info[1] & ((int)1 << 14)) != 0; HW_SHA = (info[1] & ((int)1 << 29)) != 0; HW_PREFETCHWT1 = (info[2] & ((int)1 << 0)) != 0; HW_AVX512_F = (info[1] & ((int)1 << 16)) != 0; HW_AVX512_CD = (info[1] & ((int)1 << 28)) != 0; HW_AVX512_PF = (info[1] & ((int)1 << 26)) != 0; HW_AVX512_ER = (info[1] & ((int)1 << 27)) != 0; HW_AVX512_VL = (info[1] & ((int)1 << 31)) != 0; HW_AVX512_BW = (info[1] & ((int)1 << 30)) != 0; HW_AVX512_DQ = (info[1] & ((int)1 << 17)) != 0; HW_AVX512_IFMA = (info[1] & ((int)1 << 21)) != 0; HW_AVX512_VBMI = (info[2] & ((int)1 << 1)) != 0; }
if (nExIds >= 0x80000001){ cpuid(info, 0x80000001); HW_x64 = (info[3] & ((int)1 << 29)) != 0; HW_ABM = (info[2] & ((int)1 << 5)) != 0; HW_SSE4a = (info[2] & ((int)1 << 6)) != 0; HW_FMA4 = (info[2] & ((int)1 << 16)) != 0; HW_XOP = (info[2] & ((int)1 << 11)) != 0; }
+#else
+ // 64-bit words for the hamming distance (ORB) on 64-bit non-x86 CPUs.
+ HW_x64 = sizeof(void*) == 8;
#endif
}

diff --git a/src/fbow.h b/src/fbow.h
index 02d9c2d..cd8bf41 100644
--- a/src/fbow.h
+++ b/src/fbow.h
@@ -6,10 +6,10 @@
#include <map>
#include <memory>
#include <bitset>
-#ifndef __ANDROID__
+#include "cpu.h"
+#ifndef FBOW_NO_X86
#include <immintrin.h>
#endif
-#include "cpu.h"
namespace fbow{

//float initialized to zero.
@@ -241,7 +241,7 @@ private:
return d;
}
};
-#ifdef __ANDROID__
+#ifdef FBOW_NO_X86
//fake elements to allow compilation
struct L2_avx_generic:public Lx<uint64_t,float,32>{inline float computeDist(uint64_t *ptr){return std::numeric_limits<float>::max();}};
struct L2_se3_generic:public Lx<uint64_t,float,32>{inline float computeDist(uint64_t *ptr){return std::numeric_limits<float>::max();}};
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ option(BUILD_TESTING "Build HDMapping unit tests" OFF)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(shared/tests)
add_subdirectory(core/tests)
add_subdirectory(calib_core/tests)
add_subdirectory(apps/lidar_odometry_step_1/tests)
add_subdirectory(rosbags/tests)
Expand Down
15 changes: 5 additions & 10 deletions apps/camera_lidar_calibration/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ void AppState::rebuildImageTexture()
// directly to the raw image (see Renderer.cpp/RendererShaders.h).
if (intrinsicsLoaded && intrinsics.model == CameraModel::Pinhole)
{
cv::Mat K = (cv::Mat_<double>(3, 3) << intrinsics.fx, 0, intrinsics.cx, 0, intrinsics.fy, intrinsics.cy, 0, 0, 1);
// cv::Matx rather than the Mat_ comma initializer, which OpenCV 5 rejects for float values.
cv::Mat K(cv::Matx33d(intrinsics.fx, 0, intrinsics.cx, 0, intrinsics.fy, intrinsics.cy, 0, 0, 1));
// OpenCV distCoeffs order: k1 k2 p1 p2 k3 k4 k5 k6 (rational model)
cv::Mat D =
(cv::Mat_<double>(1, 8) << intrinsics.k1,
intrinsics.k2,
intrinsics.p1,
intrinsics.p2,
intrinsics.k3,
intrinsics.k4,
intrinsics.k5,
intrinsics.k6);
cv::Mat D(
cv::Matx<double, 1, 8>(
intrinsics.k1, intrinsics.k2, intrinsics.p1, intrinsics.p2, intrinsics.k3, intrinsics.k4, intrinsics.k5, intrinsics.k6));

cv::Mat map1, map2;
cv::initUndistortRectifyMap(K, D, cv::Mat(), K, originalImage.size(), CV_16SC2, map1, map2);
Expand Down
72 changes: 72 additions & 0 deletions apps/console_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,48 @@ if (MSVC)
target_compile_options(laz_to_mcap PRIVATE /bigobj)
endif()

# bow_loop_closure_detect: headless verification tool for the automatic
# image-based (fbow) loop closure detector shared with step 2's GUI --
# loads a step-2 session + a CAMERA_0 folder and prints candidate pairs as
# CSV, without needing the interactive GUI. Links core_no_gui (WITH_GUI=0)
# since it only needs PointClouds/Session, not the ImGui-dependent
# ManualPoseGraphLoopClosure/observation_picking pieces core (WITH_GUI=1)
# adds.
add_executable(
bow_loop_closure_detect bow_loop_closure_detect.cpp
${REPOSITORY_DIRECTORY}/apps/multi_view_tls_registration/bow_loop_closure_detector.h
${REPOSITORY_DIRECTORY}/apps/multi_view_tls_registration/bow_loop_closure_detector.cpp
)

target_compile_definitions(bow_loop_closure_detect PRIVATE
WITH_GUI=0
-DFBOW_VOCABULARY_PATH="${THIRDPARTY_DIRECTORY}/fbow/vocabularies/orb_mur.fbow")

target_include_directories(
bow_loop_closure_detect PRIVATE
${REPOSITORY_DIRECTORY}/core/include
${REPOSITORY_DIRECTORY}/apps/multi_view_tls_registration
${EIGEN3_INCLUDE_DIR}
${LASZIP_INCLUDE_DIR}/LASzip/include
${THIRDPARTY_DIRECTORY}/json/include
${THIRDPARTY_DIRECTORY}/observation_equations/codes
${THIRDPARTY_DIRECTORY}/vqf/vqf/cpp
${THIRDPARTY_DIRECTORY}/Fusion/Fusion
${EXTERNAL_LIBRARIES_DIRECTORY}/include
${FBOW_INCLUDE_DIR}
${OpenCV_INCLUDE_DIRS})

target_link_libraries(
bow_loop_closure_detect PRIVATE
core_no_gui
fbow
${OpenCV_LIBS}
${PLATFORM_LASZIP_LIB}
vqf
Fusion
${PLATFORM_MISCELLANEOUS_LIBS}
spdlog::spdlog)

# session_to_mcap: a processed lidar_odometry_step_1 session (session.json)
# -> MCAP exporter (undistorted lidar in the map frame + /tf map->lidar,
# optionally /imu re-read from the original recording via --raw-dir). Unlike
Expand Down Expand Up @@ -251,6 +293,35 @@ if (MSVC)
target_compile_options(session_to_mcap PRIVATE /bigobj)
endif()

# session_intensity_panoramas: a session's lidar intensity rendered as 360-degree
# panoramas seen from the lidar, one every N seconds, named like camera frames
# (intensity_<ns>.jpg) so the BoW loop closure can use them. Reads Core::Session,
# so it links core_no_gui (WITH_GUI=0) like session_to_mcap.
add_executable(session_intensity_panoramas session_intensity_panoramas.cpp)

target_compile_definitions(session_intensity_panoramas PRIVATE WITH_GUI=0)

target_include_directories(
session_intensity_panoramas PRIVATE
${REPOSITORY_DIRECTORY}/core/include
${EIGEN3_INCLUDE_DIR}
${LASZIP_INCLUDE_DIR}/LASzip/include
${THIRDPARTY_DIRECTORY}/json/include
${THIRDPARTY_DIRECTORY}/observation_equations/codes
${OpenCV_INCLUDE_DIRS})

target_link_libraries(
session_intensity_panoramas PRIVATE
core_no_gui
${OpenCV_LIBS}
${PLATFORM_LASZIP_LIB}
${PLATFORM_MISCELLANEOUS_LIBS}
spdlog::spdlog)

if (MSVC)
target_compile_definitions(session_intensity_panoramas PRIVATE _USE_MATH_DEFINES)
endif()

# These are built whenever BUILD_WITH_CLI_TOOLS is ON (the default), so they
# ship in the DEB package alongside the GUI apps.
hdmapping_install_app(
Expand All @@ -264,4 +335,5 @@ hdmapping_install_app(
laz_to_mcap
mcap_to_laz
ouster_pcap_to_laz
session_intensity_panoramas
session_to_mcap)
109 changes: 109 additions & 0 deletions apps/console_tools/bow_loop_closure_detect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Headless verification tool for the automatic image-based (fbow) loop
// closure detector: loads a step-2 session + one or more camera folders, runs
// the pose-gate -> appearance -> geometric-verification pipeline, and prints
// candidate loop-closure pairs as CSV. See
// apps/multi_view_tls_registration/bow_loop_closure_detector.h for the
// pipeline itself (shared with the GUI) and BOW_PLACE_RECOGNITION_HANDOFF.md
// for why it's shaped this way.
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <memory>

#include <spdlog/spdlog.h>

#include <Core/session.h>

#include "../multi_view_tls_registration/bow_loop_closure_detector.h"

int main(int argc, char* argv[])
{
if (argc < 3)
{
std::cout << "USAGE: " << argv[0] << " session_file(.mjs/.json) camera_dir [camera_dir...] [output.csv]" << std::endl;
std::cout << " session_file : step 2 session file (e.g. .../lio_result_100/session.mjs)" << std::endl;
std::cout << " camera_dir : folder of <prefix>_<timestamp_ns>.jpg frames, e.g. mandeye CAMERA_0 or an" << std::endl;
std::cout << " Insta360's cam_front and cam_back; several folders are matched together" << std::endl;
std::cout << " output.csv : optional (last argument, ending in .csv); if omitted, prints CSV to stdout" << std::endl;
return 1;
}

std::string session_file = argv[1];
std::vector<std::string> camera_dirs(argv + 2, argv + argc);
std::string output_csv;
if (camera_dirs.size() > 1 && std::filesystem::path(camera_dirs.back()).extension() == ".csv")
{
output_csv = camera_dirs.back();
camera_dirs.pop_back();
}

Session session;
if (!session.load(session_file, false, 0.0, 0.0, 0.0, false))
{
spdlog::error("Failed to load session '{}'", session_file);
return 2;
}
spdlog::info("Loaded session with {} chunks", session.point_clouds_container.point_clouds.size());

bow_loop_closure::DetectorParams params;

auto frames = bow_loop_closure::loadCameraFrames(camera_dirs);
if (frames.empty())
{
spdlog::error("No camera frames found");
return 3;
}

auto chunk_frames = bow_loop_closure::associateFramesToChunks(session.point_clouds_container, frames, params.max_frame_time_gap_ns);

std::string vocab_path = bow_loop_closure::defaultVocabularyPath();
std::unique_ptr<fbow::Vocabulary> vocabulary;
try
{
vocabulary = std::make_unique<fbow::Vocabulary>(bow_loop_closure::loadVocabulary(vocab_path));
} catch (const std::exception& e)
{
spdlog::error("{}", e.what());
return 4;
}

auto candidates = bow_loop_closure::detectCandidates(session.point_clouds_container, frames, chunk_frames, params, *vocabulary);

std::ostream* out = &std::cout;
std::ofstream file_out;
if (!output_csv.empty())
{
file_out.open(output_csv);
if (!file_out.good())
{
spdlog::error("Could not open output file '{}'", output_csv);
return 5;
}
out = &file_out;
}

*out << "index_i,index_j,xy_dist_m,arc_gap_m,bow_score,inliers,image_i,image_j" << std::endl;
for (const auto& c : candidates)
{
*out << c.index_i << "," << c.index_j << "," << c.xy_dist_m << "," << c.arc_gap_m << "," << c.bow_score << "," << c.inliers << ","
<< frames[c.frame_i].file_path << "," << frames[c.frame_j].file_path << std::endl;
}

spdlog::info(
"{} candidates ({} chunks pose-gated by arc_gap>={}, xy_dist<={}; {}/{} chunks had an associated camera frame)",
candidates.size(),
session.point_clouds_container.point_clouds.size(),
params.min_arc_gap_m,
params.max_xy_dist_m,
static_cast<int>(std::count_if(
chunk_frames.begin(),
chunk_frames.end(),
[](const auto& f)
{
return !f.empty();
})),
chunk_frames.size());

return 0;
}
Loading
Loading