]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/tools/vcpkg/ports/dbow3/fix_cmake.patch
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / tools / vcpkg / ports / dbow3 / fix_cmake.patch
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
5
6 ---
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%)
79
80 diff --git a/.gitignore b/.gitignore
81 new file mode 100644
82 index 0000000..8c4285e
83 --- /dev/null
84 +++ b/.gitignore
85 @@ -0,0 +1,249 @@
86 +## Ignore Visual Studio temporary files, build results, and
87 +## files generated by popular Visual Studio add-ons.
88 +
89 +# User-specific files
90 +*.suo
91 +*.user
92 +*.userosscache
93 +*.sln.docstates
94 +
95 +# User-specific files (MonoDevelop/Xamarin Studio)
96 +*.userprefs
97 +
98 +# Build results
99 +[Dd]ebug/
100 +[Dd]ebugPublic/
101 +[Rr]elease/
102 +[Rr]eleases/
103 +[Xx]64/
104 +[Xx]86/
105 +[Bb]uild/
106 +bld/
107 +[Bb]in/
108 +[Oo]bj/
109 +
110 +# Visual Studio 2015 cache/options directory
111 +.vs/
112 +out/
113 +# Uncomment if you have tasks that create the project's static files in wwwroot
114 +#wwwroot/
115 +
116 +# MSTest test Results
117 +[Tt]est[Rr]esult*/
118 +[Bb]uild[Ll]og.*
119 +
120 +# NUNIT
121 +*.VisualState.xml
122 +TestResult.xml
123 +
124 +# Build Results of an ATL Project
125 +[Dd]ebugPS/
126 +[Rr]eleasePS/
127 +dlldata.c
128 +
129 +# DNX
130 +project.lock.json
131 +artifacts/
132 +
133 +*_i.c
134 +*_p.c
135 +*_i.h
136 +*.ilk
137 +*.meta
138 +*.obj
139 +*.pch
140 +*.pdb
141 +*.pgc
142 +*.pgd
143 +*.rsp
144 +*.sbr
145 +*.tlb
146 +*.tli
147 +*.tlh
148 +*.tmp
149 +*.tmp_proj
150 +*.log
151 +*.vspscc
152 +*.vssscc
153 +.builds
154 +*.pidb
155 +*.svclog
156 +*.scc
157 +*.tlog
158 +*.idb
159 +# Chutzpah Test files
160 +_Chutzpah*
161 +
162 +# Visual C++ cache files
163 +ipch/
164 +*.aps
165 +*.ncb
166 +*.opendb
167 +*.opensdf
168 +*.sdf
169 +*.cachefile
170 +*.VC.db
171 +
172 +# Visual Studio profiler
173 +*.psess
174 +*.vsp
175 +*.vspx
176 +*.sap
177 +
178 +# TFS 2012 Local Workspace
179 +$tf/
180 +
181 +# Guidance Automation Toolkit
182 +*.gpState
183 +
184 +# ReSharper is a .NET coding add-in
185 +_ReSharper*/
186 +*.[Rr]e[Ss]harper
187 +*.DotSettings.user
188 +
189 +# JustCode is a .NET coding add-in
190 +.JustCode
191 +
192 +# TeamCity is a build add-in
193 +_TeamCity*
194 +
195 +# DotCover is a Code Coverage Tool
196 +*.dotCover
197 +
198 +# NCrunch
199 +_NCrunch_*
200 +.*crunch*.local.xml
201 +nCrunchTemp_*
202 +
203 +# MightyMoose
204 +*.mm.*
205 +AutoTest.Net/
206 +
207 +# Web workbench (sass)
208 +.sass-cache/
209 +
210 +# Installshield output folder
211 +[Ee]xpress/
212 +
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
222 +
223 +# Click-Once directory
224 +publish/
225 +
226 +# Publish Web Output
227 +*.[Pp]ublish.xml
228 +*.azurePubxml
229 +
230 +# TODO: Un-comment the next line if you do not want to checkin
231 +# your web deploy settings because they may include unencrypted
232 +# passwords
233 +#*.pubxml
234 +*.publishproj
235 +
236 +# NuGet Packages
237 +*.nupkg
238 +# The packages folder can be ignored because of Package Restore
239 +**/packages/*
240 +# except build/, which is used as an MSBuild target.
241 +!**/packages/build/
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
245 +*.nuget.props
246 +*.nuget.targets
247 +
248 +# Microsoft Azure Build Output
249 +csx/
250 +*.build.csdef
251 +
252 +# Microsoft Azure Emulator
253 +ecf/
254 +rcf/
255 +
256 +# Microsoft Azure ApplicationInsights config file
257 +ApplicationInsights.config
258 +
259 +# Windows Store app package directory
260 +AppPackages/
261 +BundleArtifacts/
262 +
263 +# Visual Studio cache files
264 +# files ending in .cache can be ignored
265 +*.[Cc]ache
266 +# but keep track of directories ending in .cache
267 +!*.[Cc]ache/
268 +
269 +# Others
270 +ClientBin/
271 +[Ss]tyle[Cc]op.*
272 +~$*
273 +*~
274 +*.dbmdl
275 +*.dbproj.schemaview
276 +*.pfx
277 +*.publishsettings
278 +node_modules/
279 +orleans.codegen.cs
280 +
281 +# RIA/Silverlight projects
282 +Generated_Code/
283 +
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/
288 +Backup*/
289 +UpgradeLog*.XML
290 +UpgradeLog*.htm
291 +
292 +# SQL Server files
293 +*.mdf
294 +*.ldf
295 +
296 +# Business Intelligence projects
297 +*.rdl.data
298 +*.bim.layout
299 +*.bim_*.settings
300 +
301 +# Microsoft Fakes
302 +FakesAssemblies/
303 +
304 +# GhostDoc plugin setting file
305 +*.GhostDoc.xml
306 +
307 +# Node.js Tools for Visual Studio
308 +.ntvs_analysis.dat
309 +
310 +# Visual Studio 6 build log
311 +*.plg
312 +
313 +# Visual Studio 6 workspace options file
314 +*.opt
315 +
316 +# Visual Studio LightSwitch build output
317 +**/*.HTMLClient/GeneratedArtifacts
318 +**/*.DesktopClient/GeneratedArtifacts
319 +**/*.DesktopClient/ModelManifest.xml
320 +**/*.Server/GeneratedArtifacts
321 +**/*.Server/ModelManifest.xml
322 +_Pvt_Extensions
323 +
324 +# LightSwitch generated files
325 +GeneratedArtifacts/
326 +ModelManifest.xml
327 +
328 +# Paket dependency manager
329 +.paket/paket.exe
330 +
331 +# FAKE - F# Make
332 +.fake/
333 +html
334 +xml
335 diff --git a/CMakeLists.txt b/CMakeLists.txt
336 index 9541cd7..a2a563a 100644
337 --- a/CMakeLists.txt
338 +++ b/CMakeLists.txt
339 @@ -1,268 +1,25 @@
340 -# ----------------------------------------------------------------------------
341 -# Basic Configuration
342 -# ----------------------------------------------------------------------------
343 -CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
344 +cmake_minimum_required(VERSION 3.10)
345
346 -set(CMAKE_CXX_STANDARD 11)
347 +project(DBow3 VERSION 1.0.0)
348
349 -PROJECT(DBoW3)
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)
359
360 -message("LIB_INSTALL_DIR: ${LIB_INSTALL_DIR}")
361 +# OpenCV
362 +option(USE_OPENCV_CONTRIB "Set on to use opencv-contrib" ON)
363
364 -#------------------------------------------------------
365 -# Build type
366 -#------------------------------------------------------
367 +# Optimization
368 +option(USE_SIMD "Set on to enabel avx optimization" ON)
369
370 -IF(NOT CMAKE_BUILD_TYPE )
371 - SET( CMAKE_BUILD_TYPE "Release" )
372 -ENDIF()
373
374 -#------------------------------------------------------
375 -# Lib Names and Dirs
376 -#------------------------------------------------------
377 +add_subdirectory(Lib)
378
379 -if(WIN32)
380 - # Postfix of DLLs:
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")
385 -else()
386 - # Postfix of so's:
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 )
390 -endif()
391 +if(BUILD_EXAMPLES)
392 + add_subdirectory(examples)
393 +endif(BUILD_EXAMPLES)
394
395 +if(BUILD_TESTS)
396 + add_subdirectory(tests)
397 +endif(BUILD_TESTS)
398
399 -
400 -#
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)
404 -
405 -# ----------------------------------------------------------------------------
406 -# Find Dependencies
407 -# ----------------------------------------------------------------------------
408 -find_package(OpenCV REQUIRED)
409 -IF(USE_CONTRIB)
410 -add_definitions(-DUSE_CONTRIB)
411 -ENDIF()
412 -if(NOT OpenCV_VERSION VERSION_LESS "3.0")
413 - ADD_DEFINITIONS(-DOPENCV_VERSION_3)
414 - SET(OPENCV_VERSION_3 ON)
415 -ELSE()
416 - SET(OPENCV_VERSION_3 OFF)
417 -ENDIF()
418 -
419 -include_directories(${OpenCV_INCLUDE_DIRS})
420 -
421 -SET(REQUIRED_LIBRARIES ${REQUIRED_LIBRARIES} ${OpenCV_LIBS})
422 -
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)
428 -IF (INSTALL_DOC)
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)
433 -ENDIF()
434 -
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")
440 -
441 -# ----------------------------------------------------------------------------
442 -# create configuration file from .in file (If you use windows take care with paths)
443 -# ----------------------------------------------------------------------------
444 -
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} )
449 -
450 -
451 -
452 -
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.")
458 -
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 "")
465 -
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")
472 - endif()
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")
476 - endif ()
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")
484 - endif()
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")
492 - endif ()
493 -
494 - set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall")
495 -
496 - if(WARNINGS_ARE_ERRORS)
497 - set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
498 - endif()
499 -
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")
503 - endif()
504 -
505 - # Whole program optimization
506 - if(WHOLE_PROGRAM_OPTIMIZATION)
507 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fwhole-program --combine")
508 - endif()
509 -
510 - # Other optimizations
511 - if(USE_OMIT_FRAME_POINTER)
512 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer")
513 - endif()
514 - if(USE_O2)
515 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O2")
516 - endif()
517 - if(USE_O3)
518 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O3")
519 - endif()
520 - if(USE_FAST_MATH)
521 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -ffast-math")
522 - endif()
523 - if(USE_POWERPC)
524 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5")
525 - endif()
526 - if(USE_MMX)
527 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mmmx")
528 - endif()
529 - if(USE_SSE)
530 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse")
531 - endif()
532 - if(USE_SSE2)
533 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -msse2")
534 - endif()
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")
537 - endif()
538 -
539 - if(ENABLE_PROFILING)
540 - set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -pg -g")
541 - else()
542 - if(NOT APPLE)
543 - set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -ffunction-sections")
544 - endif()
545 - endif()
546 -
547 -
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 ")
550 -
551 - MESSAGE( STATUS "-------------------------------------------------------------------------------" )
552 - message( STATUS "GNU COMPILER")
553 - MESSAGE( STATUS "-------------------------------------------------------------------------------" )
554 -
555 -
556 -
557 -
558 -ELSE() # MSVC
559 -
560 -
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}")
571 -
572 -
573 -
574 -#------------------------------------------------
575 -# DIRS
576 -#------------------------------------------------
577 -ADD_SUBDIRECTORY(src)
578 -IF (BUILD_UTILS)
579 -ADD_SUBDIRECTORY(utils)
580 -ENDIF()
581 -
582 -IF (BUILD_TESTS)
583 -ADD_SUBDIRECTORY(tests)
584 -ENDIF()
585 -
586 -
587 -# ----------------------------------------------------------------------------
588 -# display status message for important variables
589 -# ----------------------------------------------------------------------------
590 -message( STATUS )
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}")
596 -
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}")
601 -
602 -message( STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
603 -message( STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
604 -
605 -MESSAGE( STATUS )
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}" )
613 -
614 -MESSAGE( STATUS "USE_CONTRIB= ${USE_CONTRIB}" )
615 -
616 -MESSAGE( STATUS )
617 -MESSAGE( STATUS "OpenCV_LIB_DIR=${OpenCV_LIB_DIR}")
618 -MESSAGE( STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}")
619 -
620 -MESSAGE( STATUS )
621 -MESSAGE( STATUS )
622 -MESSAGE( STATUS "Change a value with: cmake -D<Variable>=<Value>" )
623 -MESSAGE( STATUS )
624 diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt
625 new file mode 100644
626 index 0000000..e56077b
627 --- /dev/null
628 +++ b/Lib/CMakeLists.txt
629 @@ -0,0 +1,99 @@
630 +cmake_minimum_required(VERSION 3.10)
631 +
632 +find_package(OpenCV REQUIRED)
633 +
634 +find_package(OpenMP REQUIRED)
635 +
636 +include(${CMAKE_SOURCE_DIR}/cmake/instructionSet.cmake)
637 +
638 +if(BUILD_SHARED_LIBS)
639 + add_library(DBow3 SHARED)
640 +
641 + target_compile_definitions(DBow3
642 + PUBLIC
643 + DBOW_API
644 + )
645 +
646 +else()
647 + add_library(DBow3 STATIC)
648 +endif()
649 +
650 +add_library(DBow3::DBow3 ALIAS DBow3)
651 +
652 +target_sources(DBow3
653 + PRIVATE
654 + src/BowVector.cpp
655 + src/Database.cpp
656 + src/DescManip.cpp
657 + src/FeatureVector.cpp
658 + src/QueryResults.cpp
659 + src/ScoringObject.cpp
660 + src/Vocabulary.cpp
661 + src/quicklz.c
662 +)
663 +
664 +target_include_directories(DBow3
665 + PUBLIC
666 + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
667 + $<INSTALL_INTERFACE:include>
668 +)
669 +
670 +target_link_libraries(DBow3
671 + PUBLIC
672 + OpenMP::OpenMP_CXX
673 +)
674 +
675 +if(USE_OPENCV_CONTRIB)
676 +target_link_libraries(DBow3
677 + PUBLIC
678 + ${OpenCV_LIBS}
679 +)
680 +
681 +target_include_directories(DBow3
682 + PUBLIC
683 + ${OpenCV_INCLUDE_DIR}
684 +)
685 +endif()
686 +
687 +if(USE_SIMD)
688 + target_link_libraries(DBow3
689 + PRIVATE
690 + SIMD::SSE4.1
691 + )
692 +endif()
693 +
694 +target_compile_definitions(DBow3
695 + PUBLIC
696 + NOMINMAX
697 + _USE_MATH_DEFINES
698 +)
699 +
700 +target_compile_features(DBow3
701 + PRIVATE
702 + cxx_std_14
703 +)
704 +
705 +
706 +install(TARGETS DBow3 EXPORT DBow3Targets
707 + LIBRARY DESTINATION lib
708 + ARCHIVE DESTINATION lib
709 + RUNTIME DESTINATION bin
710 + INCLUDES DESTINATION include
711 +)
712 +
713 +install (DIRECTORY include/ DESTINATION include)
714 +
715 +install(EXPORT DBow3Targets
716 + FILE DBow3Targets.cmake
717 + NAMESPACE DBow3::
718 + DESTINATION cmake/DBow3
719 +)
720 +
721 +include(CMakePackageConfigHelpers)
722 +
723 +write_basic_package_version_file(DBow3ConfigVersion.cmake
724 + COMPATIBILITY SameMajorVersion
725 +)
726 +
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
731 new file mode 100644
732 index 0000000..9720a14
733 --- /dev/null
734 +++ b/Lib/DBow3Config.cmake
735 @@ -0,0 +1,4 @@
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
742 similarity index 99%
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
748 @@ -12,6 +12,7 @@
749
750 #include <map>
751 #include <vector>
752 +#include <ostream>
753 #include "exports.h"
754 #if _WIN32
755 #include <cstdint>
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
785 similarity index 78%
786 rename from src/exports.h
787 rename to Lib/include/DBow3/exports.h
788 index c324953..a31b317 100644
789 --- a/src/exports.h
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 */
793 #endif
794
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.
801 -
802 +#ifdef _WIN32
803 +# ifdef DBOW_API
804 +# define DBOW_API __declspec(dllexport)
805 +# else
806 +# define DBOW_API __declspec(dllimport)
807 +# endif
808 #else
809 - #define DBOW_API
810 +# define DBOW_API
811 #endif
812
813 -
814 #define DBOW_VERSION "3.0.0"
815 #endif
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
825 similarity index 99%
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
831 @@ -13,7 +13,7 @@
832 #include <algorithm>
833 #include <cmath>
834
835 -#include "BowVector.h"
836 +#include "DBow3/BowVector.h"
837
838 namespace DBoW3 {
839
840 diff --git a/src/Database.cpp b/Lib/src/Database.cpp
841 similarity index 99%
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
847 @@ -1,4 +1,4 @@
848 -#include "Database.h"
849 +#include "DBow3/Database.h"
850
851 namespace DBoW3{
852
853 diff --git a/src/DescManip.cpp b/Lib/src/DescManip.cpp
854 similarity index 96%
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
860 @@ -1,273 +1,273 @@
861 -/**
862 - * File: DescManip.cpp
863 - * Date: June 2012
864 - * Author: Dorian Galvez-Lopez
865 - * Description: functions for ORB descriptors
866 - * License: see the LICENSE.txt file
867 - *
868 - */
869 -
870 -#include <vector>
871 -#include <string>
872 -#include <sstream>
873 -#include <iostream>
874 -#include <stdint.h>
875 -#include <limits.h>
876 -
877 -#include "DescManip.h"
878 -
879 -using namespace std;
880 -
881 -namespace DBoW3 {
882 -
883 -// --------------------------------------------------------------------------
884 -
885 -void DescManip::meanValue(const std::vector<cv::Mat> &descriptors,
886 - cv::Mat &mean)
887 -{
888 -
889 - if(descriptors.empty()) return;
890 -
891 - if(descriptors.size() == 1)
892 - {
893 - mean = descriptors[0].clone();
894 - return;
895 - }
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);
901 -
902 - for(size_t i = 0; i < descriptors.size(); ++i)
903 - {
904 - const cv::Mat &d = descriptors[i];
905 - const unsigned char *p = d.ptr<unsigned char>();
906 -
907 - for(int j = 0; j < d.cols; ++j, ++p)
908 - {
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 ];
917 - }
918 - }
919 -
920 - mean = cv::Mat::zeros(1, L, CV_8U);
921 - unsigned char *p = mean.ptr<unsigned char>();
922 -
923 - const int N2 = (int)descriptors.size() / 2 + descriptors.size() % 2;
924 - for(size_t i = 0; i < sum.size(); ++i)
925 - {
926 - if(sum[i] >= N2)
927 - {
928 - // set bit
929 - *p |= 1 << (7 - (i % 8));
930 - }
931 -
932 - if(i % 8 == 7) ++p;
933 - }
934 - }
935 - //non binary descriptor
936 - else{
937 - assert(descriptors[0].type()==CV_32F );//ensure it is float
938 -
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;
944 -
945 - }
946 -
947 -}
948 -
949 -// --------------------------------------------------------------------------
950 -static inline uint32_t distance_8uc1(const cv::Mat &a, const cv::Mat &b);
951 -
952 -double DescManip::distance(const cv::Mat &a, const cv::Mat &b)
953 -{
954 -
955 - //binary descriptor
956 - if (a.type()==CV_8U){
957 -
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
961 -
962 - const uint64_t *pa, *pb;
963 - pa = a.ptr<uint64_t>(); // a & b are actually CV_8U
964 - pb = b.ptr<uint64_t>();
965 -
966 - uint64_t v, ret = 0;
967 - for(size_t i = 0; i < a.cols / sizeof(uint64_t); ++i, ++pa, ++pb)
968 - {
969 - v = *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;
976 - }
977 -
978 - return ret;
979 - }
980 - else{
981 - double sqd = 0.;
982 - assert(a.type()==CV_32F);
983 - assert(a.rows==1);
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 ]);
988 - return sqd;
989 - }
990 -}
991 -
992 -
993 -
994 -
995 -// --------------------------------------------------------------------------
996 -
997 -std::string DescManip::toString(const cv::Mat &a)
998 -{
999 - stringstream ss;
1000 - //introduce a magic value to distinguish from DBOw2
1001 - ss<<"dbw3 ";
1002 - //save size and type
1003 -
1004 -
1005 - ss <<a.type()<<" "<<a.cols<<" ";
1006 -
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 << " ";
1011 - }else{
1012 -
1013 - const float *p = a.ptr<float>();
1014 - for(int i = 0; i < a.cols; ++i, ++p)
1015 - ss << *p << " ";
1016 -
1017 - }
1018 -
1019 - return ss.str();
1020 -}
1021 -
1022 -// --------------------------------------------------------------------------
1023 -
1024 -void DescManip::fromString(cv::Mat &a, const std::string &s)
1025 -{
1026 -
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
1032 - //READ UNTIL END
1033 - stringstream ss(s);
1034 - int val;
1035 - vector<uchar> data;data.reserve(100);
1036 - while( ss>>val) data.push_back(val);
1037 - //copy to a
1038 - a.create(1,data.size(),CV_8UC1);
1039 - memcpy(a.ptr<char>(0),&data[0],data.size());
1040 - }
1041 - else {
1042 - char szSign[10];
1043 - int type,cols;
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>();
1049 - int n;
1050 - for(int i = 0; i < a.cols; ++i, ++p)
1051 - if ( ss >> n) *p = (unsigned char)n;
1052 - }
1053 - else{
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;
1057 - }
1058 -
1059 - }
1060 -
1061 -}
1062 -
1063 -// --------------------------------------------------------------------------
1064 -
1065 -void DescManip::toMat32F(const std::vector<cv::Mat> &descriptors,
1066 - cv::Mat &mat)
1067 -{
1068 - if(descriptors.empty())
1069 - {
1070 - mat.release();
1071 - return;
1072 - }
1073 -
1074 - if(descriptors[0].type()==CV_8UC1){
1075 -
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>();
1080 -
1081 - for(size_t i = 0; i < N; ++i)
1082 - {
1083 - const int C = descriptors[i].cols;
1084 - const unsigned char *desc = descriptors[i].ptr<unsigned char>();
1085 -
1086 - for(int j = 0; j < C; ++j, p += 8)
1087 - {
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);
1096 - }
1097 - }
1098 - }
1099 - else{
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);
1106 - }
1107 -}
1108 -
1109 -void DescManip::toStream(const cv::Mat &m,std::ostream &str){
1110 - assert(m.rows==1 || m.isContinuous());
1111 - int type=m.type();
1112 - int cols=m.cols;
1113 - int rows=m.rows;
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);
1118 -}
1119 -
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);
1127 -}
1128 -
1129 -
1130 -// --------------------------------------------------------------------------
1131 -
1132 -} // namespace DBoW3
1133 -
1134 +/**
1135 + * File: DescManip.cpp
1136 + * Date: June 2012
1137 + * Author: Dorian Galvez-Lopez
1138 + * Description: functions for ORB descriptors
1139 + * License: see the LICENSE.txt file
1140 + *
1141 + */
1142 +
1143 +#include <vector>
1144 +#include <string>
1145 +#include <sstream>
1146 +#include <iostream>
1147 +#include <stdint.h>
1148 +#include <limits.h>
1149 +
1150 +#include "DBow3/DescManip.h"
1151 +
1152 +using namespace std;
1153 +
1154 +namespace DBoW3 {
1155 +
1156 +// --------------------------------------------------------------------------
1157 +
1158 +void DescManip::meanValue(const std::vector<cv::Mat> &descriptors,
1159 + cv::Mat &mean)
1160 +{
1161 +
1162 + if(descriptors.empty()) return;
1163 +
1164 + if(descriptors.size() == 1)
1165 + {
1166 + mean = descriptors[0].clone();
1167 + return;
1168 + }
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);
1174 +
1175 + for(size_t i = 0; i < descriptors.size(); ++i)
1176 + {
1177 + const cv::Mat &d = descriptors[i];
1178 + const unsigned char *p = d.ptr<unsigned char>();
1179 +
1180 + for(int j = 0; j < d.cols; ++j, ++p)
1181 + {
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 ];
1190 + }
1191 + }
1192 +
1193 + mean = cv::Mat::zeros(1, L, CV_8U);
1194 + unsigned char *p = mean.ptr<unsigned char>();
1195 +
1196 + const int N2 = (int)descriptors.size() / 2 + descriptors.size() % 2;
1197 + for(size_t i = 0; i < sum.size(); ++i)
1198 + {
1199 + if(sum[i] >= N2)
1200 + {
1201 + // set bit
1202 + *p |= 1 << (7 - (i % 8));
1203 + }
1204 +
1205 + if(i % 8 == 7) ++p;
1206 + }
1207 + }
1208 + //non binary descriptor
1209 + else{
1210 + assert(descriptors[0].type()==CV_32F );//ensure it is float
1211 +
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;
1217 +
1218 + }
1219 +
1220 +}
1221 +
1222 +// --------------------------------------------------------------------------
1223 +static inline uint32_t distance_8uc1(const cv::Mat &a, const cv::Mat &b);
1224 +
1225 +double DescManip::distance(const cv::Mat &a, const cv::Mat &b)
1226 +{
1227 +
1228 + //binary descriptor
1229 + if (a.type()==CV_8U){
1230 +
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
1234 +
1235 + const uint64_t *pa, *pb;
1236 + pa = a.ptr<uint64_t>(); // a & b are actually CV_8U
1237 + pb = b.ptr<uint64_t>();
1238 +
1239 + uint64_t v, ret = 0;
1240 + for(size_t i = 0; i < a.cols / sizeof(uint64_t); ++i, ++pa, ++pb)
1241 + {
1242 + v = *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;
1249 + }
1250 +
1251 + return ret;
1252 + }
1253 + else{
1254 + double sqd = 0.;
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 ]);
1261 + return sqd;
1262 + }
1263 +}
1264 +
1265 +
1266 +
1267 +
1268 +// --------------------------------------------------------------------------
1269 +
1270 +std::string DescManip::toString(const cv::Mat &a)
1271 +{
1272 + stringstream ss;
1273 + //introduce a magic value to distinguish from DBOw2
1274 + ss<<"dbw3 ";
1275 + //save size and type
1276 +
1277 +
1278 + ss <<a.type()<<" "<<a.cols<<" ";
1279 +
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 << " ";
1284 + }else{
1285 +
1286 + const float *p = a.ptr<float>();
1287 + for(int i = 0; i < a.cols; ++i, ++p)
1288 + ss << *p << " ";
1289 +
1290 + }
1291 +
1292 + return ss.str();
1293 +}
1294 +
1295 +// --------------------------------------------------------------------------
1296 +
1297 +void DescManip::fromString(cv::Mat &a, const std::string &s)
1298 +{
1299 +
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
1305 + //READ UNTIL END
1306 + stringstream ss(s);
1307 + int val;
1308 + vector<uchar> data;data.reserve(100);
1309 + while( ss>>val) data.push_back(val);
1310 + //copy to a
1311 + a.create(1,data.size(),CV_8UC1);
1312 + memcpy(a.ptr<char>(0),&data[0],data.size());
1313 + }
1314 + else {
1315 + char szSign[10];
1316 + int type,cols;
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>();
1322 + int n;
1323 + for(int i = 0; i < a.cols; ++i, ++p)
1324 + if ( ss >> n) *p = (unsigned char)n;
1325 + }
1326 + else{
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;
1330 + }
1331 +
1332 + }
1333 +
1334 +}
1335 +
1336 +// --------------------------------------------------------------------------
1337 +
1338 +void DescManip::toMat32F(const std::vector<cv::Mat> &descriptors,
1339 + cv::Mat &mat)
1340 +{
1341 + if(descriptors.empty())
1342 + {
1343 + mat.release();
1344 + return;
1345 + }
1346 +
1347 + if(descriptors[0].type()==CV_8UC1){
1348 +
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>();
1353 +
1354 + for(size_t i = 0; i < N; ++i)
1355 + {
1356 + const int C = descriptors[i].cols;
1357 + const unsigned char *desc = descriptors[i].ptr<unsigned char>();
1358 +
1359 + for(int j = 0; j < C; ++j, p += 8)
1360 + {
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);
1369 + }
1370 + }
1371 + }
1372 + else{
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);
1379 + }
1380 +}
1381 +
1382 +void DescManip::toStream(const cv::Mat &m,std::ostream &str){
1383 + assert(m.rows==1 || m.isContinuous());
1384 + int type=m.type();
1385 + int cols=m.cols;
1386 + int rows=m.rows;
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);
1391 +}
1392 +
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);
1400 +}
1401 +
1402 +
1403 +// --------------------------------------------------------------------------
1404 +
1405 +} // namespace DBoW3
1406 +
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
1414 @@ -7,7 +7,7 @@
1415 *
1416 */
1417
1418 -#include "FeatureVector.h"
1419 +#include "DBow3/FeatureVector.h"
1420 #include <map>
1421 #include <vector>
1422 #include <iostream>
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
1430 @@ -9,7 +9,7 @@
1431
1432 #include <iostream>
1433 #include <fstream>
1434 -#include "QueryResults.h"
1435 +#include "DBow3/QueryResults.h"
1436
1437 using namespace std;
1438
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
1446 @@ -8,8 +8,8 @@
1447 */
1448
1449 #include <cfloat>
1450 -#include "Vocabulary.h"
1451 -#include "BowVector.h"
1452 +#include "DBow3/Vocabulary.h"
1453 +#include "DBow3/BowVector.h"
1454
1455 using namespace DBoW3;
1456
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
1464 @@ -1,8 +1,8 @@
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"
1471 #include <sstream>
1472 -#include "timers.h"
1473 +#include "DBow3/timers.h"
1474 namespace DBoW3{
1475 // --------------------------------------------------------------------------
1476
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
1482 --- a/src/quicklz.c
1483 +++ b/Lib/src/quicklz.c
1484 @@ -9,7 +9,7 @@
1485
1486 // 1.5.0 final
1487
1488 -#include "quicklz.h"
1489 +#include "DBow3/quicklz.h"
1490
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
1496 --- /dev/null
1497 +++ b/cmake/instructionSet.cmake
1498 @@ -0,0 +1,13 @@
1499 +add_library(
1500 + SSE4.1
1501 + INTERFACE
1502 +)
1503 +
1504 +add_library(SIMD::SSE4.1 ALIAS SSE4.1)
1505 +
1506 +target_compile_options(
1507 + SSE4.1
1508 + INTERFACE
1509 + $<$<PLATFORM_ID:Linux>:-msse4.1;-march=native>
1510 + $<$<PLATFORM_ID:Windows>:/arch:AVX2>
1511 +)
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
1516 +++ /dev/null
1517 @@ -1,28 +0,0 @@
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")
1525 -
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}")
1531 -# EXEC_PROGRAM(
1532 -# "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
1533 -# OUTPUT_VARIABLE rm_out
1534 -# RETURN_VALUE rm_retval
1535 -# )
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}")
1543 -ENDFOREACH(file)
1544 -
1545 -
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
1550 +++ /dev/null
1551 @@ -1,36 +0,0 @@
1552 -# ===================================================================================
1553 -# @PROJECT_NAME@ CMake configuration file
1554 -#
1555 -# ** File generated automatically, do not modify **
1556 -#
1557 -# Usage from an external project:
1558 -# In your CMakeLists.txt, add these lines:
1559 -#
1560 -# FIND_PACKAGE(@PROJECT_NAME@ REQUIRED )
1561 -# TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${@PROJECT_NAME@_LIBS})
1562 -#
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"
1571 -#
1572 -# ===================================================================================
1573 -INCLUDE_DIRECTORIES("@CMAKE_INSTALL_PREFIX@/include")
1574 -SET(@PROJECT_NAME@_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include")
1575 -
1576 -LINK_DIRECTORIES("@CMAKE_INSTALL_PREFIX@/@LIB_INSTALL_DIR@")
1577 -SET(@PROJECT_NAME@_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@LIB_INSTALL_DIR@")
1578 -
1579 -SET(@PROJECT_NAME@_LIBS @REQUIRED_LIBRARIES@ @PROJECT_NAME@@PROJECT_DLLVERSION@)
1580 -SET(@PROJECT_NAME@_LIBRARIES @REQUIRED_LIBRARIES@ @PROJECT_NAME@@PROJECT_DLLVERSION@)
1581 -
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
1599 @@ -1,126 +1,126 @@
1600 -
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>
1603 -#include <vector>
1604 -
1605 -// DBoW3
1606 -#include "DBoW3.h"
1607 -
1608 -// OpenCV
1609 -#include <opencv2/core/core.hpp>
1610 -#include <opencv2/highgui/highgui.hpp>
1611 -#include <opencv2/features2d/features2d.hpp>
1612 -#ifdef USE_CONTRIB
1613 -#include <opencv2/xfeatures2d/nonfree.hpp>
1614 -#include <opencv2/xfeatures2d.hpp>
1615 -#endif
1616 -#include "DescManip.h"
1617 -
1618 -using namespace DBoW3;
1619 -using namespace std;
1620 -
1621 -
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] ); }};
1624 -
1625 -
1626 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1627 -
1628 -// extended surf gives 128-dimensional vectors
1629 -const bool EXTENDED_SURF = false;
1630 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1631 -
1632 -void wait()
1633 -{
1634 - cout << endl << "Press enter to continue" << endl;
1635 - getchar();
1636 -}
1637 -
1638 -
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]);
1642 - return paths;
1643 -}
1644 -
1645 -vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
1646 - //select detector
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();
1652 -#endif
1653 -#ifdef USE_CONTRIB
1654 - else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
1655 -#endif
1656 -
1657 - else throw std::runtime_error("Invalid descriptor");
1658 - assert(!descriptor.empty());
1659 - vector<cv::Mat> features;
1660 -
1661 -
1662 - cout << "Extracting features..." << endl;
1663 - for(size_t i = 0; i < path_to_images.size(); ++i)
1664 - {
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;
1674 - }
1675 - return features;
1676 -}
1677 -
1678 -// ----------------------------------------------------------------------------
1679 -void saveToFile(string filename,const vector<cv::Mat> &features){
1680 -
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);
1691 - }
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());
1696 - }
1697 -}
1698 -
1699 -// ----------------------------------------------------------------------------
1700 -
1701 -int main(int argc,char **argv)
1702 -{
1703 -
1704 - try{
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;
1708 - return -1;
1709 - }
1710 -
1711 - string descriptor=argv[1];
1712 - string output=argv[2];
1713 -
1714 - auto images=readImagePaths(argc,argv,3);
1715 - vector< cv::Mat > features= loadFeatures(images,descriptor);
1716 -
1717 - //save features to file
1718 - saveToFile(argv[2],features);
1719 -
1720 - }catch(std::exception &ex){
1721 - cerr<<ex.what()<<endl;
1722 - }
1723 -
1724 - return 0;
1725 -}
1726 +
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>
1729 +#include <vector>
1730 +
1731 +// DBoW3
1732 +#include "DBoW3.h"
1733 +
1734 +// OpenCV
1735 +#include <opencv2/core/core.hpp>
1736 +#include <opencv2/highgui/highgui.hpp>
1737 +#include <opencv2/features2d/features2d.hpp>
1738 +#ifdef USE_CONTRIB
1739 +#include <opencv2/xfeatures2d/nonfree.hpp>
1740 +#include <opencv2/xfeatures2d.hpp>
1741 +#endif
1742 +#include "DescManip.h"
1743 +
1744 +using namespace DBoW3;
1745 +using namespace std;
1746 +
1747 +
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] ); }};
1750 +
1751 +
1752 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1753 +
1754 +// extended surf gives 128-dimensional vectors
1755 +const bool EXTENDED_SURF = false;
1756 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1757 +
1758 +void wait()
1759 +{
1760 + cout << endl << "Press enter to continue" << endl;
1761 + getchar();
1762 +}
1763 +
1764 +
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]);
1768 + return paths;
1769 +}
1770 +
1771 +vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
1772 + //select detector
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();
1778 +#endif
1779 +#ifdef USE_CONTRIB
1780 + else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
1781 +#endif
1782 +
1783 + else throw std::runtime_error("Invalid descriptor");
1784 + assert(!descriptor.empty());
1785 + vector<cv::Mat> features;
1786 +
1787 +
1788 + cout << "Extracting features..." << endl;
1789 + for(size_t i = 0; i < path_to_images.size(); ++i)
1790 + {
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;
1800 + }
1801 + return features;
1802 +}
1803 +
1804 +// ----------------------------------------------------------------------------
1805 +void saveToFile(string filename,const vector<cv::Mat> &features){
1806 +
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);
1817 + }
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());
1822 + }
1823 +}
1824 +
1825 +// ----------------------------------------------------------------------------
1826 +
1827 +int main(int argc,char **argv)
1828 +{
1829 +
1830 + try{
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;
1834 + return -1;
1835 + }
1836 +
1837 + string descriptor=argv[1];
1838 + string output=argv[2];
1839 +
1840 + auto images=readImagePaths(argc,argv,3);
1841 + vector< cv::Mat > features= loadFeatures(images,descriptor);
1842 +
1843 + //save features to file
1844 + saveToFile(argv[2],features);
1845 +
1846 + }catch(std::exception &ex){
1847 + cerr<<ex.what()<<endl;
1848 + }
1849 +
1850 + return 0;
1851 +}
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
1859 @@ -1,71 +1,71 @@
1860 -//Second step,creates the vocabulary from the set of features. It can be slow
1861 -#include <iostream>
1862 -#include <vector>
1863 -
1864 -// DBoW3
1865 -#include "DBoW3.h"
1866 -
1867 -// OpenCV
1868 -#include <opencv2/core/core.hpp>
1869 -using namespace DBoW3;
1870 -using namespace std;
1871 -
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] ); }};
1874 -
1875 -// ----------------------------------------------------------------------------
1876 -
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);}
1883 - uint32_t size;
1884 - ifile.read((char*)&size,sizeof(size));
1885 - features.resize(size);
1886 - for(size_t i=0;i<size;i++){
1887 -
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());
1894 - }
1895 - return features;
1896 -}
1897 -
1898 -// ----------------------------------------------------------------------------
1899 -
1900 -int main(int argc,char **argv)
1901 -{
1902 -
1903 - try{
1904 - CmdLineParser cml(argc,argv);
1905 - if (cml["-h"] || argc!=3){
1906 - cerr<<"Usage: features output_voc.yml[.gz]"<<endl;
1907 - return -1;
1908 - }
1909 -
1910 -
1911 - auto features=readFeaturesFromFile(argv[1]);
1912 -
1913 - const int k = 9;
1914 - const int L = 3;
1915 - const WeightingType weight = TF_IDF;
1916 - const ScoringType score = L1_NORM;
1917 - DBoW3::Vocabulary voc (k, L, weight, score);
1918 -
1919 - cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
1920 - voc.create(features);
1921 - cerr<<"Saving "<<argv[2]<<endl;
1922 - voc.save(argv[2]);
1923 -
1924 -
1925 - }catch(std::exception &ex){
1926 - cerr<<ex.what()<<endl;
1927 - }
1928 -
1929 - return 0;
1930 -}
1931 +//Second step,creates the vocabulary from the set of features. It can be slow
1932 +#include <iostream>
1933 +#include <vector>
1934 +
1935 +// DBoW3
1936 +#include "DBoW3.h"
1937 +
1938 +// OpenCV
1939 +#include <opencv2/core/core.hpp>
1940 +using namespace DBoW3;
1941 +using namespace std;
1942 +
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] ); }};
1945 +
1946 +// ----------------------------------------------------------------------------
1947 +
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);}
1954 + uint32_t size;
1955 + ifile.read((char*)&size,sizeof(size));
1956 + features.resize(size);
1957 + for(size_t i=0;i<size;i++){
1958 +
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());
1965 + }
1966 + return features;
1967 +}
1968 +
1969 +// ----------------------------------------------------------------------------
1970 +
1971 +int main(int argc,char **argv)
1972 +{
1973 +
1974 + try{
1975 + CmdLineParser cml(argc,argv);
1976 + if (cml["-h"] || argc!=3){
1977 + cerr<<"Usage: features output_voc.yml[.gz]"<<endl;
1978 + return -1;
1979 + }
1980 +
1981 +
1982 + auto features=readFeaturesFromFile(argv[1]);
1983 +
1984 + const int k = 9;
1985 + const int L = 3;
1986 + const WeightingType weight = TF_IDF;
1987 + const ScoringType score = L1_NORM;
1988 + DBoW3::Vocabulary voc (k, L, weight, score);
1989 +
1990 + cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
1991 + voc.create(features);
1992 + cerr<<"Saving "<<argv[2]<<endl;
1993 + voc.save(argv[2]);
1994 +
1995 +
1996 + }catch(std::exception &ex){
1997 + cerr<<ex.what()<<endl;
1998 + }
1999 +
2000 + return 0;
2001 +}
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
2009 @@ -1,202 +1,202 @@
2010 -/**
2011 - * Date: 2016
2012 - * Author: Rafael Muñoz Salinas
2013 - * Description: demo application of DBoW3
2014 - * License: see the LICENSE.txt file
2015 - */
2016 -
2017 -#include <iostream>
2018 -#include <vector>
2019 -
2020 -// DBoW3
2021 -#include "DBoW3.h"
2022 -
2023 -// OpenCV
2024 -#include <opencv2/core/core.hpp>
2025 -#include <opencv2/highgui/highgui.hpp>
2026 -#include <opencv2/features2d/features2d.hpp>
2027 -#ifdef USE_CONTRIB
2028 -#include <opencv2/xfeatures2d/nonfree.hpp>
2029 -#include <opencv2/xfeatures2d.hpp>
2030 -#endif
2031 -#include "DescManip.h"
2032 -
2033 -using namespace DBoW3;
2034 -using namespace std;
2035 -
2036 -
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] ); }};
2039 -
2040 -
2041 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2042 -
2043 -// extended surf gives 128-dimensional vectors
2044 -const bool EXTENDED_SURF = false;
2045 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2046 -
2047 -void wait()
2048 -{
2049 - cout << endl << "Press enter to continue" << endl;
2050 - getchar();
2051 -}
2052 -
2053 -
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]);
2057 - return paths;
2058 -}
2059 -
2060 -vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
2061 - //select detector
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();
2067 -#endif
2068 -#ifdef USE_CONTRIB
2069 - else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
2070 -#endif
2071 -
2072 - else throw std::runtime_error("Invalid descriptor");
2073 - assert(!descriptor.empty());
2074 - vector<cv::Mat> features;
2075 -
2076 -
2077 - cout << "Extracting features..." << endl;
2078 - for(size_t i = 0; i < path_to_images.size(); ++i)
2079 - {
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;
2089 - }
2090 - return features;
2091 -}
2092 -
2093 -// ----------------------------------------------------------------------------
2094 -
2095 -void testVocCreation(const vector<cv::Mat> &features)
2096 -{
2097 - // branching factor and depth levels
2098 - const int k = 9;
2099 - const int L = 3;
2100 - const WeightingType weight = TF_IDF;
2101 - const ScoringType score = L1_NORM;
2102 -
2103 - DBoW3::Vocabulary voc(k, L, weight, score);
2104 -
2105 - cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
2106 - voc.create(features);
2107 - cout << "... done!" << endl;
2108 -
2109 - cout << "Vocabulary information: " << endl
2110 - << voc << endl << endl;
2111 -
2112 - // lets do something with this vocabulary
2113 - cout << "Matching images against themselves (0 low, 1 high): " << endl;
2114 - BowVector v1, v2;
2115 - for(size_t i = 0; i < features.size(); i++)
2116 - {
2117 - voc.transform(features[i], v1);
2118 - for(size_t j = 0; j < features.size(); j++)
2119 - {
2120 - voc.transform(features[j], v2);
2121 -
2122 - double score = voc.score(v1, v2);
2123 - cout << "Image " << i << " vs Image " << j << ": " << score << endl;
2124 - }
2125 - }
2126 -
2127 - // save the vocabulary to disk
2128 - cout << endl << "Saving vocabulary..." << endl;
2129 - voc.save("small_voc.yml.gz");
2130 - cout << "Done" << endl;
2131 -}
2132 -
2133 -////// ----------------------------------------------------------------------------
2134 -
2135 -void testDatabase(const vector<cv::Mat > &features)
2136 -{
2137 - cout << "Creating a small database..." << endl;
2138 -
2139 - // load the vocabulary from disk
2140 - Vocabulary voc("small_voc.yml.gz");
2141 -
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
2147 -
2148 - // add images to the database
2149 - for(size_t i = 0; i < features.size(); i++)
2150 - db.add(features[i]);
2151 -
2152 - cout << "... done!" << endl;
2153 -
2154 - cout << "Database information: " << endl << db << endl;
2155 -
2156 - // and query the database
2157 - cout << "Querying the database: " << endl;
2158 -
2159 - QueryResults ret;
2160 - for(size_t i = 0; i < features.size(); i++)
2161 - {
2162 - db.query(features[i], ret, 4);
2163 -
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.
2166 -
2167 - cout << "Searching for Image " << i << ". " << ret << endl;
2168 - }
2169 -
2170 - cout << endl;
2171 -
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;
2177 -
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;
2182 -}
2183 -
2184 -
2185 -// ----------------------------------------------------------------------------
2186 -
2187 -int main(int argc,char **argv)
2188 -{
2189 -
2190 - try{
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;
2194 - return -1;
2195 - }
2196 -
2197 - string descriptor=argv[1];
2198 -
2199 - auto images=readImagePaths(argc,argv,2);
2200 - vector< cv::Mat > features= loadFeatures(images,descriptor);
2201 - testVocCreation(features);
2202 -
2203 -
2204 - testDatabase(features);
2205 -
2206 - }catch(std::exception &ex){
2207 - cerr<<ex.what()<<endl;
2208 - }
2209 -
2210 - return 0;
2211 -}
2212 +/**
2213 + * Date: 2016
2214 + * Author: Rafael Muñoz Salinas
2215 + * Description: demo application of DBoW3
2216 + * License: see the LICENSE.txt file
2217 + */
2218 +
2219 +#include <iostream>
2220 +#include <vector>
2221 +
2222 +// DBoW3
2223 +#include "DBoW3.h"
2224 +
2225 +// OpenCV
2226 +#include <opencv2/core/core.hpp>
2227 +#include <opencv2/highgui/highgui.hpp>
2228 +#include <opencv2/features2d/features2d.hpp>
2229 +#ifdef USE_CONTRIB
2230 +#include <opencv2/xfeatures2d/nonfree.hpp>
2231 +#include <opencv2/xfeatures2d.hpp>
2232 +#endif
2233 +#include "DescManip.h"
2234 +
2235 +using namespace DBoW3;
2236 +using namespace std;
2237 +
2238 +
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] ); }};
2241 +
2242 +
2243 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2244 +
2245 +// extended surf gives 128-dimensional vectors
2246 +const bool EXTENDED_SURF = false;
2247 +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2248 +
2249 +void wait()
2250 +{
2251 + cout << endl << "Press enter to continue" << endl;
2252 + getchar();
2253 +}
2254 +
2255 +
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]);
2259 + return paths;
2260 +}
2261 +
2262 +vector< cv::Mat > loadFeatures( std::vector<string> path_to_images,string descriptor="") throw (std::exception){
2263 + //select detector
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();
2269 +#endif
2270 +#ifdef USE_CONTRIB
2271 + else if(descriptor=="surf" ) fdetector=cv::xfeatures2d::SURF::create(400, 4, 2, EXTENDED_SURF);
2272 +#endif
2273 +
2274 + else throw std::runtime_error("Invalid descriptor");
2275 + assert(!descriptor.empty());
2276 + vector<cv::Mat> features;
2277 +
2278 +
2279 + cout << "Extracting features..." << endl;
2280 + for(size_t i = 0; i < path_to_images.size(); ++i)
2281 + {
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;
2291 + }
2292 + return features;
2293 +}
2294 +
2295 +// ----------------------------------------------------------------------------
2296 +
2297 +void testVocCreation(const vector<cv::Mat> &features)
2298 +{
2299 + // branching factor and depth levels
2300 + const int k = 9;
2301 + const int L = 3;
2302 + const WeightingType weight = TF_IDF;
2303 + const ScoringType score = L1_NORM;
2304 +
2305 + DBoW3::Vocabulary voc(k, L, weight, score);
2306 +
2307 + cout << "Creating a small " << k << "^" << L << " vocabulary..." << endl;
2308 + voc.create(features);
2309 + cout << "... done!" << endl;
2310 +
2311 + cout << "Vocabulary information: " << endl
2312 + << voc << endl << endl;
2313 +
2314 + // lets do something with this vocabulary
2315 + cout << "Matching images against themselves (0 low, 1 high): " << endl;
2316 + BowVector v1, v2;
2317 + for(size_t i = 0; i < features.size(); i++)
2318 + {
2319 + voc.transform(features[i], v1);
2320 + for(size_t j = 0; j < features.size(); j++)
2321 + {
2322 + voc.transform(features[j], v2);
2323 +
2324 + double score = voc.score(v1, v2);
2325 + cout << "Image " << i << " vs Image " << j << ": " << score << endl;
2326 + }
2327 + }
2328 +
2329 + // save the vocabulary to disk
2330 + cout << endl << "Saving vocabulary..." << endl;
2331 + voc.save("small_voc.yml.gz");
2332 + cout << "Done" << endl;
2333 +}
2334 +
2335 +////// ----------------------------------------------------------------------------
2336 +
2337 +void testDatabase(const vector<cv::Mat > &features)
2338 +{
2339 + cout << "Creating a small database..." << endl;
2340 +
2341 + // load the vocabulary from disk
2342 + Vocabulary voc("small_voc.yml.gz");
2343 +
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
2349 +
2350 + // add images to the database
2351 + for(size_t i = 0; i < features.size(); i++)
2352 + db.add(features[i]);
2353 +
2354 + cout << "... done!" << endl;
2355 +
2356 + cout << "Database information: " << endl << db << endl;
2357 +
2358 + // and query the database
2359 + cout << "Querying the database: " << endl;
2360 +
2361 + QueryResults ret;
2362 + for(size_t i = 0; i < features.size(); i++)
2363 + {
2364 + db.query(features[i], ret, 4);
2365 +
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.
2368 +
2369 + cout << "Searching for Image " << i << ". " << ret << endl;
2370 + }
2371 +
2372 + cout << endl;
2373 +
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;
2379 +
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;
2384 +}
2385 +
2386 +
2387 +// ----------------------------------------------------------------------------
2388 +
2389 +int main(int argc,char **argv)
2390 +{
2391 +
2392 + try{
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;
2396 + return -1;
2397 + }
2398 +
2399 + string descriptor=argv[1];
2400 +
2401 + auto images=readImagePaths(argc,argv,2);
2402 + vector< cv::Mat > features= loadFeatures(images,descriptor);
2403 + testVocCreation(features);
2404 +
2405 +
2406 + testDatabase(features);
2407 +
2408 + }catch(std::exception &ex){
2409 + cerr<<ex.what()<<endl;
2410 + }
2411 +
2412 + return 0;
2413 +}
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
2434 +++ /dev/null
2435 @@ -1,35 +0,0 @@
2436 -INCLUDE_DIRECTORIES(. ./utils/)
2437 -
2438 -FILE(GLOB hdrs_base "*.h" )
2439 -FILE(GLOB srcs_base "*.c*")
2440 -
2441 -FILE(GLOB hdrs ${hdrs_base} )
2442 -FILE(GLOB srcs ${srcs_base} )
2443 -
2444 -
2445 -ADD_LIBRARY(${PROJECT_NAME} ${srcs} ${hdrs})
2446 -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} )
2447 -
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
2454 -)
2455 -
2456 -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_LIBRARIES} )
2457 -
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
2462 -
2463 -
2464 -
2465 -INSTALL(FILES ${hdrs_base}
2466 - DESTINATION include/${PROJECT_NAME}
2467 - COMPONENT main)
2468 -
2469 -
2470 -
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
2475
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
2480
2481 ---
2482 Lib/DBow3Config.cmake | 2 +-
2483 1 file changed, 1 insertion(+), 1 deletion(-)
2484
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
2489 @@ -1,4 +1,4 @@
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