1 From d72cb42f5147f7648c462ee1b211070c1691a887 Mon Sep 17 00:00:00 2001
2 From: Ramadan <ramadan.ahmedr93@gmail.com>
3 Date: Thu, 15 Aug 2019 12:27:19 +0200
4 Subject: [PATCH 1/2] Fix CMakeLists.txt and installation
7 .gitignore | 249 ++++++++++
8 CMakeLists.txt | 275 +----------
9 Lib/CMakeLists.txt | 99 ++++
10 Lib/DBow3Config.cmake | 4 +
11 {src => Lib/include/DBow3}/BowVector.h | 1 +
12 {src => Lib/include/DBow3}/DBoW3.h | 0
13 {src => Lib/include/DBow3}/Database.h | 0
14 {src => Lib/include/DBow3}/DescManip.h | 0
15 {src => Lib/include/DBow3}/FeatureVector.h | 0
16 {src => Lib/include/DBow3}/QueryResults.h | 0
17 {src => Lib/include/DBow3}/ScoringObject.h | 0
18 {src => Lib/include/DBow3}/Vocabulary.h | 0
19 {src => Lib/include/DBow3}/exports.h | 16 +-
20 {src => Lib/include/DBow3}/quicklz.h | 0
21 {src => Lib/include/DBow3}/timers.h | 0
22 {src => Lib/src}/BowVector.cpp | 2 +-
23 {src => Lib/src}/Database.cpp | 2 +-
24 {src => Lib/src}/DescManip.cpp | 546 ++++++++++-----------
25 {src => Lib/src}/FeatureVector.cpp | 2 +-
26 {src => Lib/src}/QueryResults.cpp | 2 +-
27 {src => Lib/src}/ScoringObject.cpp | 4 +-
28 {src => Lib/src}/Vocabulary.cpp | 8 +-
29 {src => Lib/src}/quicklz.c | 2 +-
30 cmake/instructionSet.cmake | 13 +
31 cmake_uninstall.cmake.in | 28 --
32 config.cmake.in | 36 --
33 {utils => examples}/CMakeLists.txt | 0
34 {utils => examples}/create_voc_step0.cpp | 252 +++++-----
35 {utils => examples}/create_voc_step1.cpp | 142 +++---
36 {utils => examples}/demo_general.cpp | 404 +++++++--------
37 {utils => examples}/images/image0.png | Bin
38 {utils => examples}/images/image1.png | Bin
39 {utils => examples}/images/image2.png | Bin
40 {utils => examples}/images/image3.png | Bin
41 src/CMakeLists.txt | 35 --
42 orbvoc.dbow3 => voc/orbvoc.dbow3 | Bin
43 36 files changed, 1072 insertions(+), 1050 deletions(-)
44 create mode 100644 .gitignore
45 create mode 100644 Lib/CMakeLists.txt
46 create mode 100644 Lib/DBow3Config.cmake
47 rename {src => Lib/include/DBow3}/BowVector.h (99%)
48 rename {src => Lib/include/DBow3}/DBoW3.h (100%)
49 rename {src => Lib/include/DBow3}/Database.h (100%)
50 rename {src => Lib/include/DBow3}/DescManip.h (100%)
51 rename {src => Lib/include/DBow3}/FeatureVector.h (100%)
52 rename {src => Lib/include/DBow3}/QueryResults.h (100%)
53 rename {src => Lib/include/DBow3}/ScoringObject.h (100%)
54 rename {src => Lib/include/DBow3}/Vocabulary.h (100%)
55 rename {src => Lib/include/DBow3}/exports.h (78%)
56 rename {src => Lib/include/DBow3}/quicklz.h (100%)
57 rename {src => Lib/include/DBow3}/timers.h (100%)
58 rename {src => Lib/src}/BowVector.cpp (99%)
59 rename {src => Lib/src}/Database.cpp (99%)
60 rename {src => Lib/src}/DescManip.cpp (96%)
61 rename {src => Lib/src}/FeatureVector.cpp (98%)
62 rename {src => Lib/src}/QueryResults.cpp (97%)
63 rename {src => Lib/src}/ScoringObject.cpp (99%)
64 rename {src => Lib/src}/Vocabulary.cpp (99%)
65 rename {src => Lib/src}/quicklz.c (99%)
66 create mode 100644 cmake/instructionSet.cmake
67 delete mode 100644 cmake_uninstall.cmake.in
68 delete mode 100644 config.cmake.in
69 rename {utils => examples}/CMakeLists.txt (100%)
70 rename {utils => examples}/create_voc_step0.cpp (97%)
71 rename {utils => examples}/create_voc_step1.cpp (97%)
72 rename {utils => examples}/demo_general.cpp (96%)
73 rename {utils => examples}/images/image0.png (100%)
74 rename {utils => examples}/images/image1.png (100%)
75 rename {utils => examples}/images/image2.png (100%)
76 rename {utils => examples}/images/image3.png (100%)
77 delete mode 100644 src/CMakeLists.txt
78 rename orbvoc.dbow3 => voc/orbvoc.dbow3 (100%)
80 diff --git a/.gitignore b/.gitignore
82 index 0000000..8c4285e
86 +## Ignore Visual Studio temporary files, build results, and
87 +## files generated by popular Visual Studio add-ons.
89 +# User-specific files
95 +# User-specific files (MonoDevelop/Xamarin Studio)
110 +# Visual Studio 2015 cache/options directory
113 +# Uncomment if you have tasks that create the project's static files in wwwroot
116 +# MSTest test Results
124 +# Build Results of an ATL Project
159 +# Chutzpah Test files
162 +# Visual C++ cache files
172 +# Visual Studio profiler
178 +# TFS 2012 Local Workspace
181 +# Guidance Automation Toolkit
184 +# ReSharper is a .NET coding add-in
189 +# JustCode is a .NET coding add-in
192 +# TeamCity is a build add-in
195 +# DotCover is a Code Coverage Tool
207 +# Web workbench (sass)
210 +# Installshield output folder
213 +# DocProject is a documentation generator add-in
214 +DocProject/buildhelp/
215 +DocProject/Help/*.HxT
216 +DocProject/Help/*.HxC
217 +DocProject/Help/*.hhc
218 +DocProject/Help/*.hhk
219 +DocProject/Help/*.hhp
220 +DocProject/Help/Html2
221 +DocProject/Help/html
223 +# Click-Once directory
226 +# Publish Web Output
230 +# TODO: Un-comment the next line if you do not want to checkin
231 +# your web deploy settings because they may include unencrypted
238 +# The packages folder can be ignored because of Package Restore
240 +# except build/, which is used as an MSBuild target.
242 +# Uncomment if necessary however generally it will be regenerated when needed
243 +#!**/packages/repositories.config
244 +# NuGet v3's project.json files produces more ignoreable files
248 +# Microsoft Azure Build Output
252 +# Microsoft Azure Emulator
256 +# Microsoft Azure ApplicationInsights config file
257 +ApplicationInsights.config
259 +# Windows Store app package directory
263 +# Visual Studio cache files
264 +# files ending in .cache can be ignored
266 +# but keep track of directories ending in .cache
281 +# RIA/Silverlight projects
284 +# Backup & report files from converting an old project file
285 +# to a newer Visual Studio version. Backup files are not needed,
286 +# because we have git ;-)
287 +_UpgradeReport_Files/
296 +# Business Intelligence projects
304 +# GhostDoc plugin setting file
307 +# Node.js Tools for Visual Studio
310 +# Visual Studio 6 build log
313 +# Visual Studio 6 workspace options file
316 +# Visual Studio LightSwitch build output
317 +**/*.HTMLClient/GeneratedArtifacts
318 +**/*.DesktopClient/GeneratedArtifacts
319 +**/*.DesktopClient/ModelManifest.xml
320 +**/*.Server/GeneratedArtifacts
321 +**/*.Server/ModelManifest.xml
324 +# LightSwitch generated files
328 +# Paket dependency manager
335 diff --git a/CMakeLists.txt b/CMakeLists.txt
336 index 9541cd7..a2a563a 100644
340 -# ----------------------------------------------------------------------------
341 -# Basic Configuration
342 -# ----------------------------------------------------------------------------
343 -CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
344 +cmake_minimum_required(VERSION 3.10)
346 -set(CMAKE_CXX_STANDARD 11)
347 +project(DBow3 VERSION 1.0.0)
350 -set(PROJECT_VERSION "0.0.1")
351 -string(REGEX MATCHALL "[0-9]" PROJECT_VERSION_PARTS "${PROJECT_VERSION}")
352 -list(GET PROJECT_VERSION_PARTS 0 PROJECT_VERSION_MAJOR)
353 -list(GET PROJECT_VERSION_PARTS 1 PROJECT_VERSION_MINOR)
354 -list(GET PROJECT_VERSION_PARTS 2 PROJECT_VERSION_PATCH)
355 -set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
356 +option(BUILD_EXAMPLES "Set to ON to build examples" OFF)
357 +option(BUILD_TESTS "Set to ON to build tests" OFF)
358 +option(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
360 -message("LIB_INSTALL_DIR: ${LIB_INSTALL_DIR}")
362 +option(USE_OPENCV_CONTRIB "Set on to use opencv-contrib" ON)
364 -#------------------------------------------------------
366 -#------------------------------------------------------
368 +option(USE_SIMD "Set on to enabel avx optimization" ON)
370 -IF(NOT CMAKE_BUILD_TYPE )
371 - SET( CMAKE_BUILD_TYPE "Release" )
374 -#------------------------------------------------------
375 -# Lib Names and Dirs
376 -#------------------------------------------------------
377 +add_subdirectory(Lib)
381 - SET(PROJECT_DLLVERSION "${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH}")
382 - SET(RUNTIME_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Directory for dlls and binaries")
383 - SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Directory for binaries")
384 - SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Directory for dlls")
387 - set(PROJECT_DLLVERSION)
388 - set(LIB_INSTALL_DIR lib CACHE STRING "Install location of libraries (e.g. lib32 or lib64 for multilib installations)")
389 - SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/cmake/ /usr/${LIB_INSTALL_DIR}/cmake )
392 + add_subdirectory(examples)
393 +endif(BUILD_EXAMPLES)
396 + add_subdirectory(tests)
401 -OPTION(BUILD_UTILS "Set to OFF to not build utils" ON)
402 -OPTION(USE_CONTRIB "Set to ON if contrib are installed" OFF)
403 -OPTION(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
405 -# ----------------------------------------------------------------------------
407 -# ----------------------------------------------------------------------------
408 -find_package(OpenCV REQUIRED)
410 -add_definitions(-DUSE_CONTRIB)
412 -if(NOT OpenCV_VERSION VERSION_LESS "3.0")
413 - ADD_DEFINITIONS(-DOPENCV_VERSION_3)
414 - SET(OPENCV_VERSION_3 ON)
416 - SET(OPENCV_VERSION_3 OFF)
419 -include_directories(${OpenCV_INCLUDE_DIRS})
421 -SET(REQUIRED_LIBRARIES ${REQUIRED_LIBRARIES} ${OpenCV_LIBS})
423 -# ----------------------------------------------------------------------------
424 -# PROJECT CONFIGURATION
425 -# force some variables that could be defined in the command line to be written to cache
426 -# ----------------------------------------------------------------------------
427 -OPTION(INSTALL_DOC "Set to ON to build/install Documentation" OFF)
429 - FIND_PACKAGE(Doxygen REQUIRED)
430 - MESSAGE( STATUS "INSTALL_DOC: ${INSTALL_DOC} ")
431 - INCLUDE("${PROJECT_SOURCE_DIR}/generateDoc.cmake")
432 - GENERATE_DOCUMENTATION(${PROJECT_SOURCE_DIR}/dox.in)
435 -# ----------------------------------------------------------------------------
436 -# Uninstall target, for "make uninstall"
437 -# ----------------------------------------------------------------------------
438 -CONFIGURE_FILE( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
439 -ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
441 -# ----------------------------------------------------------------------------
442 -# create configuration file from .in file (If you use windows take care with paths)
443 -# ----------------------------------------------------------------------------
445 -CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/config.cmake.in" "${PROJECT_BINARY_DIR}/Find${PROJECT_NAME}.cmake")
446 -CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
447 -INSTALL(FILES "${PROJECT_BINARY_DIR}/Find${PROJECT_NAME}.cmake" DESTINATION ${LIB_INSTALL_DIR}/cmake/ )
448 -INSTALL(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION ${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME} )
453 -# ----------------------------------------------------------------------------
454 -# Program Optimization and debug (Extracted from OpenCV)
455 -# ----------------------------------------------------------------------------
456 -set(WARNINGS_ARE_ERRORS OFF CACHE BOOL "Treat warnings as errors")
457 -set(WHOLE_PROGRAM_OPTIMIZATION OFF CACHE BOOL "Flags for whole program optimization.")
459 -set(EXTRA_C_FLAGS "")
460 -set(EXTRA_C_FLAGS_RELEASE "")
461 -set(EXTRA_C_FLAGS_DEBUG "")
462 -set(EXTRA_EXE_LINKER_FLAGS "")
463 -set(EXTRA_EXE_LINKER_FLAGS_RELEASE "")
464 -set(EXTRA_EXE_LINKER_FLAGS_DEBUG "")
466 -IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
467 - set(ENABLE_PROFILING OFF CACHE BOOL "Enable profiling in the GCC compiler (Add flags: -g -pg)")
468 - set(USE_OMIT_FRAME_POINTER ON CACHE BOOL "Enable -fomit-frame-pointer for GCC")
469 - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES arm*) # We can use only -O2 because the -O3 causes gcc crash
470 - set(USE_O2 ON CACHE BOOL "Enable -O2 for GCC")
471 - set(USE_FAST_MATH OFF CACHE BOOL "Enable -ffast-math for GCC")
473 - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES powerpc*)
474 - set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC")
475 - set(USE_POWERPC ON CACHE BOOL "Enable PowerPC for GCC")
477 - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64*)
478 - set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC")
479 - set(USE_FAST_MATH OFF CACHE BOOL "Enable -ffast-math for GCC")
480 - set(USE_MMX ON CACHE BOOL "Enable MMX for GCC")
481 - set(USE_SSE ON CACHE BOOL "Enable SSE for GCC")
482 - set(USE_SSE2 ON CACHE BOOL "Enable SSE2 for GCC")
483 - set(USE_SSE3 ON CACHE BOOL "Enable SSE3 for GCC")
485 - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86)
486 - set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC")
487 - set(USE_FAST_MATH OFF CACHE BOOL "Enable -ffast-math for GCC")
488 - set(USE_MMX ON CACHE BOOL "Enable MMX for GCC")
489 - set(USE_SSE OFF CACHE BOOL "Enable SSE for GCC")
490 - set(USE_SSE2 OFF CACHE BOOL "Enable SSE2 for GCC")
491 - set(USE_SSE3 OFF CACHE BOOL "Enable SSE3 for GCC")
494 - set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall")
496 - if(WARNINGS_ARE_ERRORS)
497 - set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
500 - # The -Wno-long-long is required in 64bit systems when including sytem headers.
501 - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64*)
502 - set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-long-long")
505 - # Whole program optimization
506 - if(WHOLE_PROGRAM_OPTIMIZATION)
507 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fwhole-program --combine")
510 - # Other optimizations
511 - if(USE_OMIT_FRAME_POINTER)
512 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer")
515 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O2")
518 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O3")
521 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -ffast-math")
524 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5")
527 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mmmx")
530 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse")
533 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse2")
535 - if(USE_SSE3 AND NOT MINGW) # SSE3 should be disabled under MingW because it generates compiler errors
536 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse3")
539 - if(ENABLE_PROFILING)
540 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -pg -g")
543 - set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -ffunction-sections")
548 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -DNDEBUG ")
549 - set(EXTRA_C_FLAGS_DEBUG "-g3 -O0 -DDEBUG -D_DEBUG -W -Wextra -Wno-return-type ")
551 - MESSAGE( STATUS "-------------------------------------------------------------------------------" )
552 - message( STATUS "GNU COMPILER")
553 - MESSAGE( STATUS "-------------------------------------------------------------------------------" )
561 -ENDIF()#END OF COMPILER SPECIFIC OPTIONS
562 -SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS_RELEASE}")
563 -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS_DEBUG}")
564 -SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=c++11")
565 -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=c++11")
566 -set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_DEBUG}")
567 -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG}")
568 -SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS}")
569 -SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${EXTRA_EXE_LINKER_FLAGS_RELEASE}")
570 -SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${EXTRA_EXE_LINKER_FLAGS_DEBUG}")
574 -#------------------------------------------------
576 -#------------------------------------------------
577 -ADD_SUBDIRECTORY(src)
579 -ADD_SUBDIRECTORY(utils)
583 -ADD_SUBDIRECTORY(tests)
587 -# ----------------------------------------------------------------------------
588 -# display status message for important variables
589 -# ----------------------------------------------------------------------------
591 -MESSAGE( STATUS "-------------------------------------------------------------------------------" )
592 -message( STATUS "General configuration for ${PROJECT_NAME} ${PROJECT_VERSION}")
593 -MESSAGE( STATUS "-------------------------------------------------------------------------------" )
594 -message(" Built as dynamic libs?:" ${BUILD_SHARED_LIBS})
595 -message(" Compiler:" "${CMAKE_COMPILER}" "${CMAKE_CXX_COMPILER}")
597 -message( STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
598 -message( STATUS "C++ flags (Release): ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
599 -message( STATUS "C++ flags (Debug): ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
600 -message( STATUS "C++ flags (Relase+Debug): ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
602 -message( STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
603 -message( STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
606 -MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}" )
607 -MESSAGE( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
608 -MESSAGE( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" )
609 -MESSAGE( STATUS "CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}" )
610 -MESSAGE( STATUS "BUILD_UTILS= ${BUILD_UTILS}" )
611 -MESSAGE( STATUS "BUILD_TESTS= ${BUILD_TESTS}" )
612 -MESSAGE( STATUS "OPENCV_DIR= ${OpenCV_DIR} VERSION=${OpenCV_VERSION}" )
614 -MESSAGE( STATUS "USE_CONTRIB= ${USE_CONTRIB}" )
617 -MESSAGE( STATUS "OpenCV_LIB_DIR=${OpenCV_LIB_DIR}")
618 -MESSAGE( STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}")
622 -MESSAGE( STATUS "Change a value with: cmake -D<Variable>=<Value>" )
624 diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt
626 index 0000000..e56077b
628 +++ b/Lib/CMakeLists.txt
630 +cmake_minimum_required(VERSION 3.10)
632 +find_package(OpenCV REQUIRED)
634 +find_package(OpenMP REQUIRED)
636 +include(${CMAKE_SOURCE_DIR}/cmake/instructionSet.cmake)
638 +if(BUILD_SHARED_LIBS)
639 + add_library(DBow3 SHARED)
641 + target_compile_definitions(DBow3
647 + add_library(DBow3 STATIC)
650 +add_library(DBow3::DBow3 ALIAS DBow3)
652 +target_sources(DBow3
657 + src/FeatureVector.cpp
658 + src/QueryResults.cpp
659 + src/ScoringObject.cpp
664 +target_include_directories(DBow3
666 + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
667 + $<INSTALL_INTERFACE:include>
670 +target_link_libraries(DBow3
675 +if(USE_OPENCV_CONTRIB)
676 +target_link_libraries(DBow3
681 +target_include_directories(DBow3
683 + ${OpenCV_INCLUDE_DIR}
688 + target_link_libraries(DBow3
694 +target_compile_definitions(DBow3
700 +target_compile_features(DBow3
706 +install(TARGETS DBow3 EXPORT DBow3Targets
707 + LIBRARY DESTINATION lib
708 + ARCHIVE DESTINATION lib
709 + RUNTIME DESTINATION bin
710 + INCLUDES DESTINATION include
713 +install (DIRECTORY include/ DESTINATION include)
715 +install(EXPORT DBow3Targets
716 + FILE DBow3Targets.cmake
718 + DESTINATION cmake/DBow3
721 +include(CMakePackageConfigHelpers)
723 +write_basic_package_version_file(DBow3ConfigVersion.cmake
724 + COMPATIBILITY SameMajorVersion
727 +install(FILES DBow3Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/DBow3ConfigVersion.cmake
728 + DESTINATION cmake/DBow3)
729 \ No newline at end of file
730 diff --git a/Lib/DBow3Config.cmake b/Lib/DBow3Config.cmake
732 index 0000000..9720a14
734 +++ b/Lib/DBow3Config.cmake
736 +include(CMakeFindDependencyMacro)
737 +find_dependency(OpenCV)
738 +find_dependency(OpenMP)
739 +include("${CMAKE_CURRENT_LIST_DIR}/FbowTargets.cmake")
740 \ No newline at end of file
741 diff --git a/src/BowVector.h b/Lib/include/DBow3/BowVector.h
743 rename from src/BowVector.h
744 rename to Lib/include/DBow3/BowVector.h
745 index d8c17e0..cdbf517 100644
746 --- a/src/BowVector.h
747 +++ b/Lib/include/DBow3/BowVector.h
756 diff --git a/src/DBoW3.h b/Lib/include/DBow3/DBoW3.h
757 similarity index 100%
758 rename from src/DBoW3.h
759 rename to Lib/include/DBow3/DBoW3.h
760 diff --git a/src/Database.h b/Lib/include/DBow3/Database.h
761 similarity index 100%
762 rename from src/Database.h
763 rename to Lib/include/DBow3/Database.h
764 diff --git a/src/DescManip.h b/Lib/include/DBow3/DescManip.h
765 similarity index 100%
766 rename from src/DescManip.h
767 rename to Lib/include/DBow3/DescManip.h
768 diff --git a/src/FeatureVector.h b/Lib/include/DBow3/FeatureVector.h
769 similarity index 100%
770 rename from src/FeatureVector.h
771 rename to Lib/include/DBow3/FeatureVector.h
772 diff --git a/src/QueryResults.h b/Lib/include/DBow3/QueryResults.h
773 similarity index 100%
774 rename from src/QueryResults.h
775 rename to Lib/include/DBow3/QueryResults.h
776 diff --git a/src/ScoringObject.h b/Lib/include/DBow3/ScoringObject.h
777 similarity index 100%
778 rename from src/ScoringObject.h
779 rename to Lib/include/DBow3/ScoringObject.h
780 diff --git a/src/Vocabulary.h b/Lib/include/DBow3/Vocabulary.h
781 similarity index 100%
782 rename from src/Vocabulary.h
783 rename to Lib/include/DBow3/Vocabulary.h
784 diff --git a/src/exports.h b/Lib/include/DBow3/exports.h
786 rename from src/exports.h
787 rename to Lib/include/DBow3/exports.h
788 index c324953..a31b317 100644
790 +++ b/Lib/include/DBow3/exports.h
791 @@ -35,17 +35,15 @@ or implied, of Rafael Muñoz Salinas.
792 #define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
795 -#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined DBOW_DSO_EXPORTS
796 - #define DBOW_API __declspec(dllexport)
797 - #pragma warning ( disable : 4251 ) //disable warning to templates with dll linkage.
798 - #pragma warning ( disable : 4290 ) //disable warning due to exception specifications.
799 - #pragma warning ( disable : 4996 ) //disable warning regarding unsafe vsprintf.
800 - #pragma warning ( disable : 4244 ) //disable warning convesions with lost of data.
804 +# define DBOW_API __declspec(dllexport)
806 +# define DBOW_API __declspec(dllimport)
814 #define DBOW_VERSION "3.0.0"
816 diff --git a/src/quicklz.h b/Lib/include/DBow3/quicklz.h
817 similarity index 100%
818 rename from src/quicklz.h
819 rename to Lib/include/DBow3/quicklz.h
820 diff --git a/src/timers.h b/Lib/include/DBow3/timers.h
821 similarity index 100%
822 rename from src/timers.h
823 rename to Lib/include/DBow3/timers.h
824 diff --git a/src/BowVector.cpp b/Lib/src/BowVector.cpp
826 rename from src/BowVector.cpp
827 rename to Lib/src/BowVector.cpp
828 index d132213..f61d421 100644
829 --- a/src/BowVector.cpp
830 +++ b/Lib/src/BowVector.cpp
835 -#include "BowVector.h"
836 +#include "DBow3/BowVector.h"
840 diff --git a/src/Database.cpp b/Lib/src/Database.cpp
842 rename from src/Database.cpp
843 rename to Lib/src/Database.cpp
844 index d8a1b81..25610a0 100644
845 --- a/src/Database.cpp
846 +++ b/Lib/src/Database.cpp
848 -#include "Database.h"
849 +#include "DBow3/Database.h"
853 diff --git a/src/DescManip.cpp b/Lib/src/DescManip.cpp
855 rename from src/DescManip.cpp
856 rename to Lib/src/DescManip.cpp
857 index d6331af..430ce2b 100644
858 --- a/src/DescManip.cpp
859 +++ b/Lib/src/DescManip.cpp
862 - * File: DescManip.cpp
864 - * Author: Dorian Galvez-Lopez
865 - * Description: functions for ORB descriptors
866 - * License: see the LICENSE.txt file
877 -#include "DescManip.h"
879 -using namespace std;
883 -// --------------------------------------------------------------------------
885 -void DescManip::meanValue(const std::vector<cv::Mat> &descriptors,
889 - if(descriptors.empty()) return;
891 - if(descriptors.size() == 1)
893 - mean = descriptors[0].clone();
896 - //binary descriptor
897 - if (descriptors[0].type()==CV_8U ){
898 - //determine number of bytes of the binary descriptor
899 - int L= getDescSizeBytes( descriptors[0]);
900 - vector<int> sum( L * 8, 0);
902 - for(size_t i = 0; i < descriptors.size(); ++i)
904 - const cv::Mat &d = descriptors[i];
905 - const unsigned char *p = d.ptr<unsigned char>();
907 - for(int j = 0; j < d.cols; ++j, ++p)
909 - if(*p & (1 << 7)) ++sum[ j*8 ];
910 - if(*p & (1 << 6)) ++sum[ j*8 + 1 ];
911 - if(*p & (1 << 5)) ++sum[ j*8 + 2 ];
912 - if(*p & (1 << 4)) ++sum[ j*8 + 3 ];
913 - if(*p & (1 << 3)) ++sum[ j*8 + 4 ];
914 - if(*p & (1 << 2)) ++sum[ j*8 + 5 ];
915 - if(*p & (1 << 1)) ++sum[ j*8 + 6 ];
916 - if(*p & (1)) ++sum[ j*8 + 7 ];
920 - mean = cv::Mat::zeros(1, L, CV_8U);
921 - unsigned char *p = mean.ptr<unsigned char>();
923 - const int N2 = (int)descriptors.size() / 2 + descriptors.size() % 2;
924 - for(size_t i = 0; i < sum.size(); ++i)
929 - *p |= 1 << (7 - (i % 8));
932 - if(i % 8 == 7) ++p;
935 - //non binary descriptor
937 - assert(descriptors[0].type()==CV_32F );//ensure it is float
939 - mean.create(1, descriptors[0].cols,descriptors[0].type());
940 - mean.setTo(cv::Scalar::all(0));
941 - float inv_s =1./double( descriptors.size());
942 - for(size_t i=0;i<descriptors.size();i++)
943 - mean += descriptors[i] * inv_s;
949 -// --------------------------------------------------------------------------
950 -static inline uint32_t distance_8uc1(const cv::Mat &a, const cv::Mat &b);
952 -double DescManip::distance(const cv::Mat &a, const cv::Mat &b)
955 - //binary descriptor
956 - if (a.type()==CV_8U){
958 - // Bit count function got from:
959 - // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
960 - // This implementation assumes that a.cols (CV_8U) % sizeof(uint64_t) == 0
962 - const uint64_t *pa, *pb;
963 - pa = a.ptr<uint64_t>(); // a & b are actually CV_8U
964 - pb = b.ptr<uint64_t>();
966 - uint64_t v, ret = 0;
967 - for(size_t i = 0; i < a.cols / sizeof(uint64_t); ++i, ++pa, ++pb)
970 - v = v - ((v >> 1) & (uint64_t)~(uint64_t)0/3);
971 - v = (v & (uint64_t)~(uint64_t)0/15*3) + ((v >> 2) &
972 - (uint64_t)~(uint64_t)0/15*3);
973 - v = (v + (v >> 4)) & (uint64_t)~(uint64_t)0/255*15;
974 - ret += (uint64_t)(v * ((uint64_t)~(uint64_t)0/255)) >>
975 - (sizeof(uint64_t) - 1) * CHAR_BIT;
982 - assert(a.type()==CV_32F);
984 - const float *a_ptr=a.ptr<float>(0);
985 - const float *b_ptr=b.ptr<float>(0);
986 - for(int i = 0; i < a.cols; i ++)
987 - sqd += (a_ptr[i ] - b_ptr[i ])*(a_ptr[i ] - b_ptr[i ]);
995 -// --------------------------------------------------------------------------
997 -std::string DescManip::toString(const cv::Mat &a)
1000 - //introduce a magic value to distinguish from DBOw2
1002 - //save size and type
1005 - ss <<a.type()<<" "<<a.cols<<" ";
1007 - if (a.type()==CV_8U){
1008 - const unsigned char *p = a.ptr<unsigned char>();
1009 - for(int i = 0; i < a.cols; ++i, ++p)
1010 - ss << (int)*p << " ";
1013 - const float *p = a.ptr<float>();
1014 - for(int i = 0; i < a.cols; ++i, ++p)
1022 -// --------------------------------------------------------------------------
1024 -void DescManip::fromString(cv::Mat &a, const std::string &s)
1027 - //check if the dbow3 is present
1028 - string ss_aux;ss_aux.reserve(10);
1029 - for(size_t i=0;i<10 && i<s.size();i++)
1030 - ss_aux.push_back(s[i]);
1031 - if(ss_aux.find("dbw3")==std::string::npos){//is dbow2
1033 - stringstream ss(s);
1035 - vector<uchar> data;data.reserve(100);
1036 - while( ss>>val) data.push_back(val);
1038 - a.create(1,data.size(),CV_8UC1);
1039 - memcpy(a.ptr<char>(0),&data[0],data.size());
1044 - stringstream ss(s);
1045 - ss >> szSign >> type >> cols;
1046 - a.create(1, cols, type);
1047 - if(type==CV_8UC1){
1048 - unsigned char *p = a.ptr<unsigned char>();
1050 - for(int i = 0; i < a.cols; ++i, ++p)
1051 - if ( ss >> n) *p = (unsigned char)n;
1054 - float *p = a.ptr<float>();
1055 - for(int i = 0; i < a.cols; ++i, ++p)
1056 - if ( !(ss >> *p))cerr<<"Error reading. Unexpected EOF. DescManip::fromString"<<endl;
1063 -// --------------------------------------------------------------------------
1065 -void DescManip::toMat32F(const std::vector<cv::Mat> &descriptors,
1068 - if(descriptors.empty())
1074 - if(descriptors[0].type()==CV_8UC1){
1076 - const size_t N = descriptors.size();
1077 - int L=getDescSizeBytes(descriptors[0]);
1078 - mat.create(N, L*8, CV_32F);
1079 - float *p = mat.ptr<float>();
1081 - for(size_t i = 0; i < N; ++i)
1083 - const int C = descriptors[i].cols;
1084 - const unsigned char *desc = descriptors[i].ptr<unsigned char>();
1086 - for(int j = 0; j < C; ++j, p += 8)
1088 - p[0] = (desc[j] & (1 << 7) ? 1 : 0);
1089 - p[1] = (desc[j] & (1 << 6) ? 1 : 0);
1090 - p[2] = (desc[j] & (1 << 5) ? 1 : 0);
1091 - p[3] = (desc[j] & (1 << 4) ? 1 : 0);
1092 - p[4] = (desc[j] & (1 << 3) ? 1 : 0);
1093 - p[5] = (desc[j] & (1 << 2) ? 1 : 0);
1094 - p[6] = (desc[j] & (1 << 1) ? 1 : 0);
1095 - p[7] = desc[j] & (1);
1100 - assert(descriptors[0].type()==CV_32F);
1101 - const int N = descriptors.size();
1102 - int L=descriptors[0].cols;
1103 - mat.create(N, L, CV_32F);
1104 - for(int i = 0; i < N; ++i)
1105 - memcpy(mat.ptr<float>(i),descriptors[i].ptr<float>(0),sizeof(float)*L);
1109 -void DescManip::toStream(const cv::Mat &m,std::ostream &str){
1110 - assert(m.rows==1 || m.isContinuous());
1111 - int type=m.type();
1114 - str.write((char*)&cols,sizeof(cols));
1115 - str.write((char*)&rows,sizeof(rows));
1116 - str.write((char*)&type,sizeof(type));
1117 - str.write((char*)m.ptr<char>(0),m.elemSize()*m.cols);
1120 -void DescManip::fromStream(cv::Mat &m,std::istream &str){
1121 - int type,cols,rows;
1122 - str.read((char*)&cols,sizeof(cols));
1123 - str.read((char*)&rows,sizeof(rows));
1124 - str.read((char*)&type,sizeof(type));
1125 - m.create(rows,cols,type);
1126 - str.read((char*)m.ptr<char>(0),m.elemSize()*m.cols);
1130 -// --------------------------------------------------------------------------
1132 -} // namespace DBoW3
1135 + * File: DescManip.cpp
1137 + * Author: Dorian Galvez-Lopez
1138 + * Description: functions for ORB descriptors
1139 + * License: see the LICENSE.txt file
1146 +#include <iostream>
1147 +#include <stdint.h>
1148 +#include <limits.h>
1150 +#include "DBow3/DescManip.h"
1152 +using namespace std;
1156 +// --------------------------------------------------------------------------
1158 +void DescManip::meanValue(const std::vector<cv::Mat> &descriptors,
1162 + if(descriptors.empty()) return;
1164 + if(descriptors.size() == 1)
1166 + mean = descriptors[0].clone();
1169 + //binary descriptor
1170 + if (descriptors[0].type()==CV_8U ){
1171 + //determine number of bytes of the binary descriptor
1172 + int L= getDescSizeBytes( descriptors[0]);
1173 + vector<int> sum( L * 8, 0);
1175 + for(size_t i = 0; i < descriptors.size(); ++i)
1177 + const cv::Mat &d = descriptors[i];
1178 + const unsigned char *p = d.ptr<unsigned char>();
1180 + for(int j = 0; j < d.cols; ++j, ++p)
1182 + if(*p & (1 << 7)) ++sum[ j*8 ];
1183 + if(*p & (1 << 6)) ++sum[ j*8 + 1 ];
1184 + if(*p & (1 << 5)) ++sum[ j*8 + 2 ];
1185 + if(*p & (1 << 4)) ++sum[ j*8 + 3 ];
1186 + if(*p & (1 << 3)) ++sum[ j*8 + 4 ];
1187 + if(*p & (1 << 2)) ++sum[ j*8 + 5 ];
1188 + if(*p & (1 << 1)) ++sum[ j*8 + 6 ];
1189 + if(*p & (1)) ++sum[ j*8 + 7 ];
1193 + mean = cv::Mat::zeros(1, L, CV_8U);
1194 + unsigned char *p = mean.ptr<unsigned char>();
1196 + const int N2 = (int)descriptors.size() / 2 + descriptors.size() % 2;
1197 + for(size_t i = 0; i < sum.size(); ++i)
1202 + *p |= 1 << (7 - (i % 8));
1205 + if(i % 8 == 7) ++p;
1208 + //non binary descriptor
1210 + assert(descriptors[0].type()==CV_32F );//ensure it is float
1212 + mean.create(1, descriptors[0].cols,descriptors[0].type());
1213 + mean.setTo(cv::Scalar::all(0));
1214 + float inv_s =1./double( descriptors.size());
1215 + for(size_t i=0;i<descriptors.size();i++)
1216 + mean += descriptors[i] * inv_s;
1222 +// --------------------------------------------------------------------------
1223 +static inline uint32_t distance_8uc1(const cv::Mat &a, const cv::Mat &b);
1225 +double DescManip::distance(const cv::Mat &a, const cv::Mat &b)
1228 + //binary descriptor
1229 + if (a.type()==CV_8U){
1231 + // Bit count function got from:
1232 + // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
1233 + // This implementation assumes that a.cols (CV_8U) % sizeof(uint64_t) == 0
1235 + const uint64_t *pa, *pb;
1236 + pa = a.ptr<uint64_t>(); // a & b are actually CV_8U
1237 + pb = b.ptr<uint64_t>();
1239 + uint64_t v, ret = 0;
1240 + for(size_t i = 0; i < a.cols / sizeof(uint64_t); ++i, ++pa, ++pb)
1243 + v = v - ((v >> 1) & (uint64_t)~(uint64_t)0/3);
1244 + v = (v & (uint64_t)~(uint64_t)0/15*3) + ((v >> 2) &
1245 + (uint64_t)~(uint64_t)0/15*3);
1246 + v = (v + (v >> 4)) & (uint64_t)~(uint64_t)0/255*15;
1247 + ret += (uint64_t)(v * ((uint64_t)~(uint64_t)0/255)) >>
1248 + (sizeof(uint64_t) - 1) * CHAR_BIT;
1255 + assert(a.type()==CV_32F);
1256 + assert(a.rows==1);
1257 + const float *a_ptr=a.ptr<float>(0);
1258 + const float *b_ptr=b.ptr<float>(0);
1259 + for(int i = 0; i < a.cols; i ++)
1260 + sqd += (a_ptr[i ] - b_ptr[i ])*(a_ptr[i ] - b_ptr[i ]);
1268 +// --------------------------------------------------------------------------
1270 +std::string DescManip::toString(const cv::Mat &a)
1273 + //introduce a magic value to distinguish from DBOw2
1275 + //save size and type
1278 + ss <<a.type()<<" "<<a.cols<<" ";
1280 + if (a.type()==CV_8U){
1281 + const unsigned char *p = a.ptr<unsigned char>();
1282 + for(int i = 0; i < a.cols; ++i, ++p)
1283 + ss << (int)*p << " ";
1286 + const float *p = a.ptr<float>();
1287 + for(int i = 0; i < a.cols; ++i, ++p)
1295 +// --------------------------------------------------------------------------
1297 +void DescManip::fromString(cv::Mat &a, const std::string &s)
1300 + //check if the dbow3 is present
1301 + string ss_aux;ss_aux.reserve(10);
1302 + for(size_t i=0;i<10 && i<s.size();i++)
1303 + ss_aux.push_back(s[i]);
1304 + if(ss_aux.find("dbw3")==std::string::npos){//is dbow2
1306 + stringstream ss(s);
1308 + vector<uchar> data;data.reserve(100);
1309 + while( ss>>val) data.push_back(val);
1311 + a.create(1,data.size(),CV_8UC1);
1312 + memcpy(a.ptr<char>(0),&data[0],data.size());
1317 + stringstream ss(s);
1318 + ss >> szSign >> type >> cols;
1319 + a.create(1, cols, type);
1320 + if(type==CV_8UC1){
1321 + unsigned char *p = a.ptr<unsigned char>();
1323 + for(int i = 0; i < a.cols; ++i, ++p)
1324 + if ( ss >> n) *p = (unsigned char)n;
1327 + float *p = a.ptr<float>();
1328 + for(int i = 0; i < a.cols; ++i, ++p)
1329 + if ( !(ss >> *p))cerr<<"Error reading. Unexpected EOF. DescManip::fromString"<<endl;
1336 +// --------------------------------------------------------------------------
1338 +void DescManip::toMat32F(const std::vector<cv::Mat> &descriptors,
1341 + if(descriptors.empty())
1347 + if(descriptors[0].type()==CV_8UC1){
1349 + const size_t N = descriptors.size();
1350 + int L=getDescSizeBytes(descriptors[0]);
1351 + mat.create(N, L*8, CV_32F);
1352 + float *p = mat.ptr<float>();
1354 + for(size_t i = 0; i < N; ++i)
1356 + const int C = descriptors[i].cols;
1357 + const unsigned char *desc = descriptors[i].ptr<unsigned char>();
1359 + for(int j = 0; j < C; ++j, p += 8)
1361 + p[0] = (desc[j] & (1 << 7) ? 1 : 0);
1362 + p[1] = (desc[j] & (1 << 6) ? 1 : 0);
1363 + p[2] = (desc[j] & (1 << 5) ? 1 : 0);
1364 + p[3] = (desc[j] & (1 << 4) ? 1 : 0);
1365 + p[4] = (desc[j] & (1 << 3) ? 1 : 0);
1366 + p[5] = (desc[j] & (1 << 2) ? 1 : 0);
1367 + p[6] = (desc[j] & (1 << 1) ? 1 : 0);
1368 + p[7] = desc[j] & (1);
1373 + assert(descriptors[0].type()==CV_32F);
1374 + const int N = descriptors.size();
1375 + int L=descriptors[0].cols;
1376 + mat.create(N, L, CV_32F);
1377 + for(int i = 0; i < N; ++i)
1378 + memcpy(mat.ptr<float>(i),descriptors[i].ptr<float>(0),sizeof(float)*L);
1382 +void DescManip::toStream(const cv::Mat &m,std::ostream &str){
1383 + assert(m.rows==1 || m.isContinuous());
1384 + int type=m.type();
1387 + str.write((char*)&cols,sizeof(cols));
1388 + str.write((char*)&rows,sizeof(rows));
1389 + str.write((char*)&type,sizeof(type));
1390 + str.write((char*)m.ptr<char>(0),m.elemSize()*m.cols);
1393 +void DescManip::fromStream(cv::Mat &m,std::istream &str){
1394 + int type,cols,rows;
1395 + str.read((char*)&cols,sizeof(cols));
1396 + str.read((char*)&rows,sizeof(rows));
1397 + str.read((char*)&type,sizeof(type));
1398 + m.create(rows,cols,type);
1399 + str.read((char*)m.ptr<char>(0),m.elemSize()*m.cols);
1403 +// --------------------------------------------------------------------------
1405 +} // namespace DBoW3
1407 diff --git a/src/FeatureVector.cpp b/Lib/src/FeatureVector.cpp
1408 similarity index 98%
1409 rename from src/FeatureVector.cpp
1410 rename to Lib/src/FeatureVector.cpp
1411 index 880eab1..a9cd792 100644
1412 --- a/src/FeatureVector.cpp
1413 +++ b/Lib/src/FeatureVector.cpp
1418 -#include "FeatureVector.h"
1419 +#include "DBow3/FeatureVector.h"
1423 diff --git a/src/QueryResults.cpp b/Lib/src/QueryResults.cpp
1424 similarity index 97%
1425 rename from src/QueryResults.cpp
1426 rename to Lib/src/QueryResults.cpp
1427 index 7062400..b852979 100644
1428 --- a/src/QueryResults.cpp
1429 +++ b/Lib/src/QueryResults.cpp
1434 -#include "QueryResults.h"
1435 +#include "DBow3/QueryResults.h"
1437 using namespace std;
1439 diff --git a/src/ScoringObject.cpp b/Lib/src/ScoringObject.cpp
1440 similarity index 99%
1441 rename from src/ScoringObject.cpp
1442 rename to Lib/src/ScoringObject.cpp
1443 index 7cf0812..adde8e9 100644
1444 --- a/src/ScoringObject.cpp
1445 +++ b/Lib/src/ScoringObject.cpp
1450 -#include "Vocabulary.h"
1451 -#include "BowVector.h"
1452 +#include "DBow3/Vocabulary.h"
1453 +#include "DBow3/BowVector.h"
1455 using namespace DBoW3;
1457 diff --git a/src/Vocabulary.cpp b/Lib/src/Vocabulary.cpp
1458 similarity index 99%
1459 rename from src/Vocabulary.cpp
1460 rename to Lib/src/Vocabulary.cpp
1461 index 9f0eff3..6ccbbea 100644
1462 --- a/src/Vocabulary.cpp
1463 +++ b/Lib/src/Vocabulary.cpp
1465 -#include "Vocabulary.h"
1466 -#include "DescManip.h"
1467 -#include "quicklz.h"
1468 +#include "DBow3/Vocabulary.h"
1469 +#include "DBow3/DescManip.h"
1470 +#include "DBow3/quicklz.h"
1472 -#include "timers.h"
1473 +#include "DBow3/timers.h"
1475 // --------------------------------------------------------------------------
1477 diff --git a/src/quicklz.c b/Lib/src/quicklz.c
1478 similarity index 99%
1479 rename from src/quicklz.c
1480 rename to Lib/src/quicklz.c
1481 index 3742129..bd3cb11 100644
1483 +++ b/Lib/src/quicklz.c
1488 -#include "quicklz.h"
1489 +#include "DBow3/quicklz.h"
1491 #if QLZ_VERSION_MAJOR != 1 || QLZ_VERSION_MINOR != 5 || QLZ_VERSION_REVISION != 0
1492 #error quicklz.c and quicklz.h have different versions
1493 diff --git a/cmake/instructionSet.cmake b/cmake/instructionSet.cmake
1494 new file mode 100644
1495 index 0000000..d0febeb
1497 +++ b/cmake/instructionSet.cmake
1504 +add_library(SIMD::SSE4.1 ALIAS SSE4.1)
1506 +target_compile_options(
1509 + $<$<PLATFORM_ID:Linux>:-msse4.1;-march=native>
1510 + $<$<PLATFORM_ID:Windows>:/arch:AVX2>
1512 diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in
1513 deleted file mode 100644
1514 index 81482da..0000000
1515 --- a/cmake_uninstall.cmake.in
1518 -# -----------------------------------------------
1519 -# File that provides "make uninstall" target
1520 -# We use the file 'install_manifest.txt'
1521 -# -----------------------------------------------
1522 -IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
1523 - MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
1524 -ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
1526 -FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
1527 -STRING(REGEX REPLACE "\n" ";" files "${files}")
1528 -FOREACH(file ${files})
1529 - MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
1530 -# IF(EXISTS "$ENV{DESTDIR}${file}")
1532 -# "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
1533 -# OUTPUT_VARIABLE rm_out
1534 -# RETURN_VALUE rm_retval
1536 - EXECUTE_PROCESS(COMMAND rm $ENV{DESTDIR}${file})
1537 -# IF(NOT "${rm_retval}" STREQUAL 0)
1538 -# MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
1539 -# ENDIF(NOT "${rm_retval}" STREQUAL 0)
1540 -# ELSE(EXISTS "$ENV{DESTDIR}${file}")
1541 -# MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
1542 -# ENDIF(EXISTS "$ENV{DESTDIR}${file}")
1546 diff --git a/config.cmake.in b/config.cmake.in
1547 deleted file mode 100644
1548 index 9d15feb..0000000
1549 --- a/config.cmake.in
1552 -# ===================================================================================
1553 -# @PROJECT_NAME@ CMake configuration file
1555 -# ** File generated automatically, do not modify **
1557 -# Usage from an external project:
1558 -# In your CMakeLists.txt, add these lines:
1560 -# FIND_PACKAGE(@PROJECT_NAME@ REQUIRED )
1561 -# TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${@PROJECT_NAME@_LIBS})
1563 -# This file will define the following variables:
1564 -# - @PROJECT_NAME@_LIBS : The list of libraries to links against.
1565 -# - @PROJECT_NAME@_LIB_DIR : The directory where lib files are. Calling LINK_DIRECTORIES
1566 -# with this path is NOT needed.
1567 -# - @PROJECT_NAME@_VERSION : The version of this PROJECT_NAME build. Example: "1.2.0"
1568 -# - @PROJECT_NAME@_VERSION_MAJOR : Major version part of VERSION. Example: "1"
1569 -# - @PROJECT_NAME@_VERSION_MINOR : Minor version part of VERSION. Example: "2"
1570 -# - @PROJECT_NAME@_VERSION_PATCH : Patch version part of VERSION. Example: "0"
1572 -# ===================================================================================
1573 -INCLUDE_DIRECTORIES("@CMAKE_INSTALL_PREFIX@/include")
1574 -SET(@PROJECT_NAME@_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include")
1576 -LINK_DIRECTORIES("@CMAKE_INSTALL_PREFIX@/@LIB_INSTALL_DIR@")
1577 -SET(@PROJECT_NAME@_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@LIB_INSTALL_DIR@")
1579 -SET(@PROJECT_NAME@_LIBS @REQUIRED_LIBRARIES@ @PROJECT_NAME@@PROJECT_DLLVERSION@)
1580 -SET(@PROJECT_NAME@_LIBRARIES @REQUIRED_LIBRARIES@ @PROJECT_NAME@@PROJECT_DLLVERSION@)
1582 -SET(@PROJECT_NAME@_FOUND YES)
1583 -SET(@PROJECT_NAME@_FOUND "YES")
1584 -SET(@PROJECT_NAME@_VERSION @PROJECT_VERSION@)
1585 -SET(@PROJECT_NAME@_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
1586 -SET(@PROJECT_NAME@_VERSION_MINOR @PROJECT_VERSION_MINOR@)
1587 -SET(@PROJECT_NAME@_VERSION_PATCH @PROJECT_VERSION_PATCH@)
1588 diff --git a/utils/CMakeLists.txt b/examples/CMakeLists.txt
1589 similarity index 100%
1590 rename from utils/CMakeLists.txt
1591 rename to examples/CMakeLists.txt
1592 diff --git a/utils/create_voc_step0.cpp b/examples/create_voc_step0.cpp
1593 similarity index 97%
1594 rename from utils/create_voc_step0.cpp
1595 rename to examples/create_voc_step0.cpp
1596 index 4fd78f6..c48a3c4 100644
1597 --- a/utils/create_voc_step0.cpp
1598 +++ b/examples/create_voc_step0.cpp
1601 -//First step of creating a vocabulary is extracting features from a set of images. We save them to a file for next step
1602 -#include <iostream>
1609 -#include <opencv2/core/core.hpp>
1610 -#include <opencv2/highgui/highgui.hpp>
1611 -#include <opencv2/features2d/features2d.hpp>
1613 -#include <opencv2/xfeatures2d/nonfree.hpp>
1614 -#include <opencv2/xfeatures2d.hpp>
1616 -#include "DescManip.h"
1618 -using namespace DBoW3;
1619 -using namespace std;
1622 -//command line parser
1623 -class CmdLineParser{int argc; char **argv; public: CmdLineParser(int _argc,char **_argv):argc(_argc),argv(_argv){} bool operator[] ( string param ) {int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; return ( idx!=-1 ) ; } string operator()(string param,string defvalue="-1"){int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; if ( idx==-1 ) return defvalue; else return ( argv[ idx+1] ); }};
1626 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1628 -// extended surf gives 128-dimensional vectors
1629 -const bool EXTENDED_SURF = false;
1630 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1634 - cout << endl << "Press enter to continue" << endl;
1639 -vector<string> readImagePaths(int argc,char **argv,int start){
1640 - vector<string> paths;
1641 - for(int i=start;i<argc;i++) paths.push_back(argv[i]);
1645 -vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
1647 - cv::Ptr<cv::Feature2D> fdetector;
1648 - if (descriptor=="orb") fdetector=cv::ORB::create();
1649 - else if (descriptor=="brisk") fdetector=cv::BRISK::create();
1650 -#ifdef OPENCV_VERSION_3
1651 - else if (descriptor=="akaze") fdetector=cv::AKAZE::create();
1654 - else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
1657 - else throw std::runtime_error("Invalid descriptor");
1658 - assert(!descriptor.empty());
1659 - vector<cv::Mat> features;
1662 - cout << "Extracting features..." << endl;
1663 - for(size_t i = 0; i < path_to_images.size(); ++i)
1665 - vector<cv::KeyPoint> keypoints;
1666 - cv::Mat descriptors;
1667 - cout<<"reading image: "<<path_to_images[i]<<endl;
1668 - cv::Mat image = cv::imread(path_to_images[i], 0);
1669 - if(image.empty())throw std::runtime_error("Could not open image"+path_to_images[i]);
1670 - cout<<"extracting features"<<endl;
1671 - fdetector->detectAndCompute(image, cv::Mat(), keypoints, descriptors);
1672 - features.push_back(descriptors);
1673 - cout<<"done detecting features"<<endl;
1678 -// ----------------------------------------------------------------------------
1679 -void saveToFile(string filename,const vector<cv::Mat> &features){
1681 - //test it is not created
1682 - std::ifstream ifile(filename);
1683 - if (ifile.is_open()){cerr<<"ERROR::: Output File "<<filename<<" already exists!!!!!"<<endl;exit(0);}
1684 - std::ofstream ofile(filename);
1685 - if (!ofile.is_open()){cerr<<"could not open output file"<<endl;exit(0);}
1686 - uint32_t size=features.size();
1687 - ofile.write((char*)&size,sizeof(size));
1688 - for(auto &f:features){
1689 - if( !f.isContinuous()){
1690 - cerr<<"Matrices should be continuous"<<endl;exit(0);
1692 - uint32_t aux=f.cols; ofile.write( (char*)&aux,sizeof(aux));
1693 - aux=f.rows; ofile.write( (char*)&aux,sizeof(aux));
1694 - aux=f.type(); ofile.write( (char*)&aux,sizeof(aux));
1695 - ofile.write( (char*)f.ptr<uchar>(0),f.total()*f.elemSize());
1699 -// ----------------------------------------------------------------------------
1701 -int main(int argc,char **argv)
1705 - CmdLineParser cml(argc,argv);
1706 - if (cml["-h"] || argc==1){
1707 - cerr<<"Usage: descriptor_name output image0 image1 ... \n\t descriptors:brisk,surf,orb(default),akaze(only if using opencv 3)"<<endl;
1711 - string descriptor=argv[1];
1712 - string output=argv[2];
1714 - auto images=readImagePaths(argc,argv,3);
1715 - vector< cv::Mat > features= loadFeatures(images,descriptor);
1717 - //save features to file
1718 - saveToFile(argv[2],features);
1720 - }catch(std::exception &ex){
1721 - cerr<<ex.what()<<endl;
1727 +//First step of creating a vocabulary is extracting features from a set of images. We save them to a file for next step
1728 +#include <iostream>
1735 +#include <opencv2/core/core.hpp>
1736 +#include <opencv2/highgui/highgui.hpp>
1737 +#include <opencv2/features2d/features2d.hpp>
1739 +#include <opencv2/xfeatures2d/nonfree.hpp>
1740 +#include <opencv2/xfeatures2d.hpp>
1742 +#include "DescManip.h"
1744 +using namespace DBoW3;
1745 +using namespace std;
1748 +//command line parser
1749 +class CmdLineParser{int argc; char **argv; public: CmdLineParser(int _argc,char **_argv):argc(_argc),argv(_argv){} bool operator[] ( string param ) {int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; return ( idx!=-1 ) ; } string operator()(string param,string defvalue="-1"){int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; if ( idx==-1 ) return defvalue; else return ( argv[ idx+1] ); }};
1752 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1754 +// extended surf gives 128-dimensional vectors
1755 +const bool EXTENDED_SURF = false;
1756 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1760 + cout << endl << "Press enter to continue" << endl;
1765 +vector<string> readImagePaths(int argc,char **argv,int start){
1766 + vector<string> paths;
1767 + for(int i=start;i<argc;i++) paths.push_back(argv[i]);
1771 +vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
1773 + cv::Ptr<cv::Feature2D> fdetector;
1774 + if (descriptor=="orb") fdetector=cv::ORB::create();
1775 + else if (descriptor=="brisk") fdetector=cv::BRISK::create();
1776 +#ifdef OPENCV_VERSION_3
1777 + else if (descriptor=="akaze") fdetector=cv::AKAZE::create();
1780 + else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
1783 + else throw std::runtime_error("Invalid descriptor");
1784 + assert(!descriptor.empty());
1785 + vector<cv::Mat> features;
1788 + cout << "Extracting features..." << endl;
1789 + for(size_t i = 0; i < path_to_images.size(); ++i)
1791 + vector<cv::KeyPoint> keypoints;
1792 + cv::Mat descriptors;
1793 + cout<<"reading image: "<<path_to_images[i]<<endl;
1794 + cv::Mat image = cv::imread(path_to_images[i], 0);
1795 + if(image.empty())throw std::runtime_error("Could not open image"+path_to_images[i]);
1796 + cout<<"extracting features"<<endl;
1797 + fdetector->detectAndCompute(image, cv::Mat(), keypoints, descriptors);
1798 + features.push_back(descriptors);
1799 + cout<<"done detecting features"<<endl;
1804 +// ----------------------------------------------------------------------------
1805 +void saveToFile(string filename,const vector<cv::Mat> &features){
1807 + //test it is not created
1808 + std::ifstream ifile(filename);
1809 + if (ifile.is_open()){cerr<<"ERROR::: Output File "<<filename<<" already exists!!!!!"<<endl;exit(0);}
1810 + std::ofstream ofile(filename);
1811 + if (!ofile.is_open()){cerr<<"could not open output file"<<endl;exit(0);}
1812 + uint32_t size=features.size();
1813 + ofile.write((char*)&size,sizeof(size));
1814 + for(auto &f:features){
1815 + if( !f.isContinuous()){
1816 + cerr<<"Matrices should be continuous"<<endl;exit(0);
1818 + uint32_t aux=f.cols; ofile.write( (char*)&aux,sizeof(aux));
1819 + aux=f.rows; ofile.write( (char*)&aux,sizeof(aux));
1820 + aux=f.type(); ofile.write( (char*)&aux,sizeof(aux));
1821 + ofile.write( (char*)f.ptr<uchar>(0),f.total()*f.elemSize());
1825 +// ----------------------------------------------------------------------------
1827 +int main(int argc,char **argv)
1831 + CmdLineParser cml(argc,argv);
1832 + if (cml["-h"] || argc==1){
1833 + cerr<<"Usage: descriptor_name output image0 image1 ... \n\t descriptors:brisk,surf,orb(default),akaze(only if using opencv 3)"<<endl;
1837 + string descriptor=argv[1];
1838 + string output=argv[2];
1840 + auto images=readImagePaths(argc,argv,3);
1841 + vector< cv::Mat > features= loadFeatures(images,descriptor);
1843 + //save features to file
1844 + saveToFile(argv[2],features);
1846 + }catch(std::exception &ex){
1847 + cerr<<ex.what()<<endl;
1852 diff --git a/utils/create_voc_step1.cpp b/examples/create_voc_step1.cpp
1853 similarity index 97%
1854 rename from utils/create_voc_step1.cpp
1855 rename to examples/create_voc_step1.cpp
1856 index 8d9de7d..1f82c66 100644
1857 --- a/utils/create_voc_step1.cpp
1858 +++ b/examples/create_voc_step1.cpp
1860 -//Second step,creates the vocabulary from the set of features. It can be slow
1861 -#include <iostream>
1868 -#include <opencv2/core/core.hpp>
1869 -using namespace DBoW3;
1870 -using namespace std;
1872 -//command line parser
1873 -class CmdLineParser{int argc; char **argv; public: CmdLineParser(int _argc,char **_argv):argc(_argc),argv(_argv){} bool operator[] ( string param ) {int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; return ( idx!=-1 ) ; } string operator()(string param,string defvalue="-1"){int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; if ( idx==-1 ) return defvalue; else return ( argv[ idx+1] ); }};
1875 -// ----------------------------------------------------------------------------
1877 -// ----------------------------------------------------------------------------
1878 -vector<cv::Mat> readFeaturesFromFile(string filename){
1879 -vector<cv::Mat> features;
1880 - //test it is not created
1881 - std::ifstream ifile(filename);
1882 - if (!ifile.is_open()){cerr<<"could not open input file"<<endl;exit(0);}
1884 - ifile.read((char*)&size,sizeof(size));
1885 - features.resize(size);
1886 - for(size_t i=0;i<size;i++){
1888 - uint32_t cols,rows,type;
1889 - ifile.read( (char*)&cols,sizeof(cols));
1890 - ifile.read( (char*)&rows,sizeof(rows));
1891 - ifile.read( (char*)&type,sizeof(type));
1892 - features[i].create(rows,cols,type);
1893 - ifile.read( (char*)features[i].ptr<uchar>(0),features[i].total()*features[i].elemSize());
1898 -// ----------------------------------------------------------------------------
1900 -int main(int argc,char **argv)
1904 - CmdLineParser cml(argc,argv);
1905 - if (cml["-h"] || argc!=3){
1906 - cerr<<"Usage: features output_voc.yml[.gz]"<<endl;
1911 - auto features=readFeaturesFromFile(argv[1]);
1915 - const WeightingType weight = TF_IDF;
1916 - const ScoringType score = L1_NORM;
1917 - DBoW3::Vocabulary voc (k, L, weight, score);
1919 - cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
1920 - voc.create(features);
1921 - cerr<<"Saving "<<argv[2]<<endl;
1922 - voc.save(argv[2]);
1925 - }catch(std::exception &ex){
1926 - cerr<<ex.what()<<endl;
1931 +//Second step,creates the vocabulary from the set of features. It can be slow
1932 +#include <iostream>
1939 +#include <opencv2/core/core.hpp>
1940 +using namespace DBoW3;
1941 +using namespace std;
1943 +//command line parser
1944 +class CmdLineParser{int argc; char **argv; public: CmdLineParser(int _argc,char **_argv):argc(_argc),argv(_argv){} bool operator[] ( string param ) {int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; return ( idx!=-1 ) ; } string operator()(string param,string defvalue="-1"){int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; if ( idx==-1 ) return defvalue; else return ( argv[ idx+1] ); }};
1946 +// ----------------------------------------------------------------------------
1948 +// ----------------------------------------------------------------------------
1949 +vector<cv::Mat> readFeaturesFromFile(string filename){
1950 +vector<cv::Mat> features;
1951 + //test it is not created
1952 + std::ifstream ifile(filename);
1953 + if (!ifile.is_open()){cerr<<"could not open input file"<<endl;exit(0);}
1955 + ifile.read((char*)&size,sizeof(size));
1956 + features.resize(size);
1957 + for(size_t i=0;i<size;i++){
1959 + uint32_t cols,rows,type;
1960 + ifile.read( (char*)&cols,sizeof(cols));
1961 + ifile.read( (char*)&rows,sizeof(rows));
1962 + ifile.read( (char*)&type,sizeof(type));
1963 + features[i].create(rows,cols,type);
1964 + ifile.read( (char*)features[i].ptr<uchar>(0),features[i].total()*features[i].elemSize());
1969 +// ----------------------------------------------------------------------------
1971 +int main(int argc,char **argv)
1975 + CmdLineParser cml(argc,argv);
1976 + if (cml["-h"] || argc!=3){
1977 + cerr<<"Usage: features output_voc.yml[.gz]"<<endl;
1982 + auto features=readFeaturesFromFile(argv[1]);
1986 + const WeightingType weight = TF_IDF;
1987 + const ScoringType score = L1_NORM;
1988 + DBoW3::Vocabulary voc (k, L, weight, score);
1990 + cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
1991 + voc.create(features);
1992 + cerr<<"Saving "<<argv[2]<<endl;
1993 + voc.save(argv[2]);
1996 + }catch(std::exception &ex){
1997 + cerr<<ex.what()<<endl;
2002 diff --git a/utils/demo_general.cpp b/examples/demo_general.cpp
2003 similarity index 96%
2004 rename from utils/demo_general.cpp
2005 rename to examples/demo_general.cpp
2006 index 63db40b..b4bc391 100644
2007 --- a/utils/demo_general.cpp
2008 +++ b/examples/demo_general.cpp
2012 - * Author: Rafael Muñoz Salinas
2013 - * Description: demo application of DBoW3
2014 - * License: see the LICENSE.txt file
2017 -#include <iostream>
2024 -#include <opencv2/core/core.hpp>
2025 -#include <opencv2/highgui/highgui.hpp>
2026 -#include <opencv2/features2d/features2d.hpp>
2028 -#include <opencv2/xfeatures2d/nonfree.hpp>
2029 -#include <opencv2/xfeatures2d.hpp>
2031 -#include "DescManip.h"
2033 -using namespace DBoW3;
2034 -using namespace std;
2037 -//command line parser
2038 -class CmdLineParser{int argc; char **argv; public: CmdLineParser(int _argc,char **_argv):argc(_argc),argv(_argv){} bool operator[] ( string param ) {int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; return ( idx!=-1 ) ; } string operator()(string param,string defvalue="-1"){int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; if ( idx==-1 ) return defvalue; else return ( argv[ idx+1] ); }};
2041 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2043 -// extended surf gives 128-dimensional vectors
2044 -const bool EXTENDED_SURF = false;
2045 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2049 - cout << endl << "Press enter to continue" << endl;
2054 -vector<string> readImagePaths(int argc,char **argv,int start){
2055 - vector<string> paths;
2056 - for(int i=start;i<argc;i++) paths.push_back(argv[i]);
2060 -vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
2062 - cv::Ptr<cv::Feature2D> fdetector;
2063 - if (descriptor=="orb") fdetector=cv::ORB::create();
2064 - else if (descriptor=="brisk") fdetector=cv::BRISK::create();
2065 -#ifdef OPENCV_VERSION_3
2066 - else if (descriptor=="akaze") fdetector=cv::AKAZE::create();
2069 - else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
2072 - else throw std::runtime_error("Invalid descriptor");
2073 - assert(!descriptor.empty());
2074 - vector<cv::Mat> features;
2077 - cout << "Extracting features..." << endl;
2078 - for(size_t i = 0; i < path_to_images.size(); ++i)
2080 - vector<cv::KeyPoint> keypoints;
2081 - cv::Mat descriptors;
2082 - cout<<"reading image: "<<path_to_images[i]<<endl;
2083 - cv::Mat image = cv::imread(path_to_images[i], 0);
2084 - if(image.empty())throw std::runtime_error("Could not open image"+path_to_images[i]);
2085 - cout<<"extracting features"<<endl;
2086 - fdetector->detectAndCompute(image, cv::Mat(), keypoints, descriptors);
2087 - features.push_back(descriptors);
2088 - cout<<"done detecting features"<<endl;
2093 -// ----------------------------------------------------------------------------
2095 -void testVocCreation(const vector<cv::Mat> &features)
2097 - // branching factor and depth levels
2100 - const WeightingType weight = TF_IDF;
2101 - const ScoringType score = L1_NORM;
2103 - DBoW3::Vocabulary voc(k, L, weight, score);
2105 - cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
2106 - voc.create(features);
2107 - cout << "... done!" << endl;
2109 - cout << "Vocabulary information: " << endl
2110 - << voc << endl << endl;
2112 - // lets do something with this vocabulary
2113 - cout << "Matching images against themselves (0 low, 1 high): " << endl;
2115 - for(size_t i = 0; i < features.size(); i++)
2117 - voc.transform(features[i], v1);
2118 - for(size_t j = 0; j < features.size(); j++)
2120 - voc.transform(features[j], v2);
2122 - double score = voc.score(v1, v2);
2123 - cout << "Image " << i << " vs Image " << j << ": " << score << endl;
2127 - // save the vocabulary to disk
2128 - cout << endl << "Saving vocabulary..." << endl;
2129 - voc.save("small_voc.yml.gz");
2130 - cout << "Done" << endl;
2133 -////// ----------------------------------------------------------------------------
2135 -void testDatabase(const vector<cv::Mat > &features)
2137 - cout << "Creating a small database..." << endl;
2139 - // load the vocabulary from disk
2140 - Vocabulary voc("small_voc.yml.gz");
2142 - Database db(voc, false, 0); // false = do not use direct index
2143 - // (so ignore the last param)
2144 - // The direct index is useful if we want to retrieve the features that
2145 - // belong to some vocabulary node.
2146 - // db creates a copy of the vocabulary, we may get rid of "voc" now
2148 - // add images to the database
2149 - for(size_t i = 0; i < features.size(); i++)
2150 - db.add(features[i]);
2152 - cout << "... done!" << endl;
2154 - cout << "Database information: " << endl << db << endl;
2156 - // and query the database
2157 - cout << "Querying the database: " << endl;
2160 - for(size_t i = 0; i < features.size(); i++)
2162 - db.query(features[i], ret, 4);
2164 - // ret[0] is always the same image in this case, because we added it to the
2165 - // database. ret[1] is the second best match.
2167 - cout << "Searching for Image " << i << ". " << ret << endl;
2172 - // we can save the database. The created file includes the vocabulary
2173 - // and the entries added
2174 - cout << "Saving database..." << endl;
2175 - db.save("small_db.yml.gz");
2176 - cout << "... done!" << endl;
2178 - // once saved, we can load it again
2179 - cout << "Retrieving database once again..." << endl;
2180 - Database db2("small_db.yml.gz");
2181 - cout << "... done! This is: " << endl << db2 << endl;
2185 -// ----------------------------------------------------------------------------
2187 -int main(int argc,char **argv)
2191 - CmdLineParser cml(argc,argv);
2192 - if (cml["-h"] || argc<=2){
2193 - cerr<<"Usage: descriptor_name image0 image1 ... \n\t descriptors:brisk,surf,orb ,akaze(only if using opencv 3)"<<endl;
2197 - string descriptor=argv[1];
2199 - auto images=readImagePaths(argc,argv,2);
2200 - vector< cv::Mat > features= loadFeatures(images,descriptor);
2201 - testVocCreation(features);
2204 - testDatabase(features);
2206 - }catch(std::exception &ex){
2207 - cerr<<ex.what()<<endl;
2214 + * Author: Rafael Muñoz Salinas
2215 + * Description: demo application of DBoW3
2216 + * License: see the LICENSE.txt file
2219 +#include <iostream>
2226 +#include <opencv2/core/core.hpp>
2227 +#include <opencv2/highgui/highgui.hpp>
2228 +#include <opencv2/features2d/features2d.hpp>
2230 +#include <opencv2/xfeatures2d/nonfree.hpp>
2231 +#include <opencv2/xfeatures2d.hpp>
2233 +#include "DescManip.h"
2235 +using namespace DBoW3;
2236 +using namespace std;
2239 +//command line parser
2240 +class CmdLineParser{int argc; char **argv; public: CmdLineParser(int _argc,char **_argv):argc(_argc),argv(_argv){} bool operator[] ( string param ) {int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; return ( idx!=-1 ) ; } string operator()(string param,string defvalue="-1"){int idx=-1; for ( int i=0; i<argc && idx==-1; i++ ) if ( string ( argv[i] ) ==param ) idx=i; if ( idx==-1 ) return defvalue; else return ( argv[ idx+1] ); }};
2243 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2245 +// extended surf gives 128-dimensional vectors
2246 +const bool EXTENDED_SURF = false;
2247 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2251 + cout << endl << "Press enter to continue" << endl;
2256 +vector<string> readImagePaths(int argc,char **argv,int start){
2257 + vector<string> paths;
2258 + for(int i=start;i<argc;i++) paths.push_back(argv[i]);
2262 +vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
2264 + cv::Ptr<cv::Feature2D> fdetector;
2265 + if (descriptor=="orb") fdetector=cv::ORB::create();
2266 + else if (descriptor=="brisk") fdetector=cv::BRISK::create();
2267 +#ifdef OPENCV_VERSION_3
2268 + else if (descriptor=="akaze") fdetector=cv::AKAZE::create();
2271 + else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
2274 + else throw std::runtime_error("Invalid descriptor");
2275 + assert(!descriptor.empty());
2276 + vector<cv::Mat> features;
2279 + cout << "Extracting features..." << endl;
2280 + for(size_t i = 0; i < path_to_images.size(); ++i)
2282 + vector<cv::KeyPoint> keypoints;
2283 + cv::Mat descriptors;
2284 + cout<<"reading image: "<<path_to_images[i]<<endl;
2285 + cv::Mat image = cv::imread(path_to_images[i], 0);
2286 + if(image.empty())throw std::runtime_error("Could not open image"+path_to_images[i]);
2287 + cout<<"extracting features"<<endl;
2288 + fdetector->detectAndCompute(image, cv::Mat(), keypoints, descriptors);
2289 + features.push_back(descriptors);
2290 + cout<<"done detecting features"<<endl;
2295 +// ----------------------------------------------------------------------------
2297 +void testVocCreation(const vector<cv::Mat> &features)
2299 + // branching factor and depth levels
2302 + const WeightingType weight = TF_IDF;
2303 + const ScoringType score = L1_NORM;
2305 + DBoW3::Vocabulary voc(k, L, weight, score);
2307 + cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
2308 + voc.create(features);
2309 + cout << "... done!" << endl;
2311 + cout << "Vocabulary information: " << endl
2312 + << voc << endl << endl;
2314 + // lets do something with this vocabulary
2315 + cout << "Matching images against themselves (0 low, 1 high): " << endl;
2317 + for(size_t i = 0; i < features.size(); i++)
2319 + voc.transform(features[i], v1);
2320 + for(size_t j = 0; j < features.size(); j++)
2322 + voc.transform(features[j], v2);
2324 + double score = voc.score(v1, v2);
2325 + cout << "Image " << i << " vs Image " << j << ": " << score << endl;
2329 + // save the vocabulary to disk
2330 + cout << endl << "Saving vocabulary..." << endl;
2331 + voc.save("small_voc.yml.gz");
2332 + cout << "Done" << endl;
2335 +////// ----------------------------------------------------------------------------
2337 +void testDatabase(const vector<cv::Mat > &features)
2339 + cout << "Creating a small database..." << endl;
2341 + // load the vocabulary from disk
2342 + Vocabulary voc("small_voc.yml.gz");
2344 + Database db(voc, false, 0); // false = do not use direct index
2345 + // (so ignore the last param)
2346 + // The direct index is useful if we want to retrieve the features that
2347 + // belong to some vocabulary node.
2348 + // db creates a copy of the vocabulary, we may get rid of "voc" now
2350 + // add images to the database
2351 + for(size_t i = 0; i < features.size(); i++)
2352 + db.add(features[i]);
2354 + cout << "... done!" << endl;
2356 + cout << "Database information: " << endl << db << endl;
2358 + // and query the database
2359 + cout << "Querying the database: " << endl;
2362 + for(size_t i = 0; i < features.size(); i++)
2364 + db.query(features[i], ret, 4);
2366 + // ret[0] is always the same image in this case, because we added it to the
2367 + // database. ret[1] is the second best match.
2369 + cout << "Searching for Image " << i << ". " << ret << endl;
2374 + // we can save the database. The created file includes the vocabulary
2375 + // and the entries added
2376 + cout << "Saving database..." << endl;
2377 + db.save("small_db.yml.gz");
2378 + cout << "... done!" << endl;
2380 + // once saved, we can load it again
2381 + cout << "Retrieving database once again..." << endl;
2382 + Database db2("small_db.yml.gz");
2383 + cout << "... done! This is: " << endl << db2 << endl;
2387 +// ----------------------------------------------------------------------------
2389 +int main(int argc,char **argv)
2393 + CmdLineParser cml(argc,argv);
2394 + if (cml["-h"] || argc<=2){
2395 + cerr<<"Usage: descriptor_name image0 image1 ... \n\t descriptors:brisk,surf,orb ,akaze(only if using opencv 3)"<<endl;
2399 + string descriptor=argv[1];
2401 + auto images=readImagePaths(argc,argv,2);
2402 + vector< cv::Mat > features= loadFeatures(images,descriptor);
2403 + testVocCreation(features);
2406 + testDatabase(features);
2408 + }catch(std::exception &ex){
2409 + cerr<<ex.what()<<endl;
2414 diff --git a/utils/images/image0.png b/examples/images/image0.png
2415 similarity index 100%
2416 rename from utils/images/image0.png
2417 rename to examples/images/image0.png
2418 diff --git a/utils/images/image1.png b/examples/images/image1.png
2419 similarity index 100%
2420 rename from utils/images/image1.png
2421 rename to examples/images/image1.png
2422 diff --git a/utils/images/image2.png b/examples/images/image2.png
2423 similarity index 100%
2424 rename from utils/images/image2.png
2425 rename to examples/images/image2.png
2426 diff --git a/utils/images/image3.png b/examples/images/image3.png
2427 similarity index 100%
2428 rename from utils/images/image3.png
2429 rename to examples/images/image3.png
2430 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
2431 deleted file mode 100644
2432 index a9c52b4..0000000
2433 --- a/src/CMakeLists.txt
2436 -INCLUDE_DIRECTORIES(. ./utils/)
2438 -FILE(GLOB hdrs_base "*.h" )
2439 -FILE(GLOB srcs_base "*.c*")
2441 -FILE(GLOB hdrs ${hdrs_base} )
2442 -FILE(GLOB srcs ${srcs_base} )
2445 -ADD_LIBRARY(${PROJECT_NAME} ${srcs} ${hdrs})
2446 -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} )
2448 -SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES # create *nix style library versions + symbolic links
2449 - DEFINE_SYMBOL DBOW_DSO_EXPORTS
2450 - VERSION ${PROJECT_VERSION}
2451 - SOVERSION ${PROJECT_SOVERSION}
2452 - CLEAN_DIRECT_OUTPUT 1 # allow creating static and shared libs without conflicts
2453 - OUTPUT_NAME "${PROJECT_NAME}${PROJECT_DLLVERSION}" # avoid conflicts between library and binary target names
2456 -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_LIBRARIES} )
2458 -INSTALL(TARGETS ${PROJECT_NAME}
2459 - RUNTIME DESTINATION bin COMPONENT main # Install the dll file in bin directory
2460 - LIBRARY DESTINATION ${LIB_INSTALL_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT main
2461 - ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT main) # Install the dll.a file in lib directory
2465 -INSTALL(FILES ${hdrs_base}
2466 - DESTINATION include/${PROJECT_NAME}
2471 diff --git a/orbvoc.dbow3 b/voc/orbvoc.dbow3
2472 similarity index 100%
2473 rename from orbvoc.dbow3
2474 rename to voc/orbvoc.dbow3
2476 From 9f9a9125423edd0b2cc7c84897d4387c5dcea44b Mon Sep 17 00:00:00 2001
2477 From: Ramadan <ramadan.ahmedr93@gmail.com>
2478 Date: Thu, 15 Aug 2019 14:00:28 +0200
2479 Subject: [PATCH 2/2] Fix DBow3Config.cmake
2482 Lib/DBow3Config.cmake | 2 +-
2483 1 file changed, 1 insertion(+), 1 deletion(-)
2485 diff --git a/Lib/DBow3Config.cmake b/Lib/DBow3Config.cmake
2486 index 9720a14..da63d5e 100644
2487 --- a/Lib/DBow3Config.cmake
2488 +++ b/Lib/DBow3Config.cmake
2490 include(CMakeFindDependencyMacro)
2491 find_dependency(OpenCV)
2492 find_dependency(OpenMP)
2493 -include("${CMAKE_CURRENT_LIST_DIR}/FbowTargets.cmake")
2494 \ No newline at end of file
2495 +include("${CMAKE_CURRENT_LIST_DIR}/DBow3Targets.cmake")
2496 \ No newline at end of file