Skip to content

Commit 2010efc

Browse files
committed
Finish Descriptor Matching
1 parent b94b913 commit 2010efc

36 files changed

+13538
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(PROJECT_NAME StringSLAM)
22
cmake_minimum_required(VERSION 3.16)
33

4-
project(${PROJECT_NAME} LANGUAGES CXX)
4+
project(${PROJECT_NAME})
55

66
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
77
if (NOT CMAKE_BUILD_TYPE)
@@ -26,7 +26,6 @@ IF (NOT ENABLE_COMPILE_FLAGS_FOR_TARGET)
2626
execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
2727
OUTPUT_VARIABLE ENABLE_COMPILE_FLAGS_FOR_TARGET OUTPUT_STRIP_TRAILING_WHITESPACE)
2828
endif()
29-
3029
message(STATUS "Platform: ${ENABLE_COMPILE_FLAGS_FOR_TARGET}")
3130
if ("${ENABLE_COMPILE_FLAGS_FOR_TARGET}" STREQUAL "arm64")
3231
add_definitions(-ftree-vectorize)
@@ -90,4 +89,4 @@ install(TARGETS lib${PROJECT_NAME}
9089
)
9190
install(
9291
FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
93-
)
92+
)

examples/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(StringSLAM_Examples)
3+
4+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
set(CMAKE_CXX_STANDARD 17)
6+
7+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
8+
add_compile_options(-Wall -Wextra -Wpedantic)
9+
elseif(MSVC)
10+
add_compile_options(/W4)
11+
endif()
12+
13+
# -------- Dependencies --------
14+
find_package(PkgConfig REQUIRED)
15+
pkg_check_modules(OPENCV REQUIRED opencv4)
16+
pkg_check_modules(EIGEN3 REQUIRED eigen3)
17+
find_package(OpenEXR QUIET)
18+
19+
include(GNUInstallDirs)
20+
21+
# -------- Sources --------
22+
file(GLOB_RECURSE EXAMPLE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
23+
24+
# -------- Include dirs --------
25+
include_directories(
26+
${CMAKE_SOURCE_DIR}/../include # assuming examples/ is sibling to main project
27+
${OPENCV_INCLUDE_DIRS}
28+
${EIGEN3_INCLUDE_DIRS}
29+
)
30+
31+
# -------- Create executables --------
32+
foreach(example_file ${EXAMPLE_SOURCES})
33+
get_filename_component(example_name ${example_file} NAME_WE)
34+
add_executable(${example_name} ${example_file})
35+
36+
target_link_libraries(${example_name}
37+
PRIVATE
38+
"${CMAKE_SOURCE_DIR}/../build/libStringSLAM.so"
39+
${OPENCV_LIBRARIES} # OpenCV
40+
${EIGEN3_LIBRARIES} # Eigen
41+
pthread
42+
)
43+
endforeach()

examples/DescriptorMatching.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <opencv2/core/types.hpp>
2+
#include <StringSLAM/Tracker/MonoTracker.hpp>
3+
#include <StringSLAM/Features/KeypointExtractor.hpp>
4+
#include <StringSLAM/Features/DescriptorMatcher.hpp>
5+
#include <StringSLAM/core.hpp>
6+
#include <opencv2/highgui.hpp>
7+
#include <opencv4/opencv2/features2d.hpp>
8+
#include <deque>
9+
10+
using namespace StringSLAM;
11+
12+
int main() {
13+
std::shared_ptr<Tracker::MonoTracker> mt1 = Tracker::MonoTracker::create(0, CameraModel());
14+
15+
std::shared_ptr<Accelerator> accelerator = Accelerator::create();
16+
accelerator->createGPU(true, 10);
17+
18+
std::shared_ptr<OrbWrapper> orb = OrbWrapper::create(800, 1.2f, 4, 30, 0, 2, cv::ORB::HARRIS_SCORE, 32, 30);
19+
std::shared_ptr<Features::KeypointExtractor> kpExtractor = Features::KeypointExtractor::create(orb);
20+
std::shared_ptr<Features::DescriptorMatcher> descMatcher = Features::DescriptorMatcher::create(orb);
21+
22+
mt1->open();
23+
24+
std::vector<cv::DMatch> matches;
25+
std::deque<Frame> frames;
26+
Frame tempFrame, prevFrame;
27+
cv::Mat out;
28+
29+
for (;;) {
30+
// If the frame list isn't empty then get prev frame.
31+
if (!frames.empty()) prevFrame = frames.back();
32+
33+
// Read frame from camera
34+
mt1->read(tempFrame);
35+
out = tempFrame.frame;
36+
37+
// Get keypoints
38+
kpExtractor->getKeypoints(tempFrame);
39+
if (!prevFrame.kp.empty()) {
40+
// Get matches for keypoints and generator descriptor
41+
matches = descMatcher->matchFramesLK(tempFrame, prevFrame);
42+
43+
// Draw matches
44+
if (!matches.empty()) descMatcher->drawMatches(tempFrame, prevFrame, matches, out);
45+
}
46+
47+
cv::imshow("Viewer", out);
48+
cv::waitKey(mt1->getFPS());
49+
50+
// Only add frame if it has keypoints
51+
if (!tempFrame.kp.empty())
52+
frames.push_back(tempFrame);
53+
54+
// If more than 45 frame remove the first one
55+
if (frames.size() > 45)
56+
frames.pop_front();
57+
}
58+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"requests":[{"kind":"cache","version":2},{"kind":"codemodel","version":2},{"kind":"toolchains","version":1},{"kind":"cmakeFiles","version":1}]}

0 commit comments

Comments
 (0)