diff --git a/CMakeLists.txt b/CMakeLists.txt index 32d49d4..7a38009 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,64 @@ cmake_minimum_required(VERSION 2.8) project(DLoopDetector) +include(ExternalProject) option(BUILD_DemoBRIEF "Build demo application with BRIEF features" OFF) option(BUILD_DemoSURF "Build demo application with SURF features" OFF) +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + +if(MSVC) + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() +elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic") +endif() + set(HDRS include/DLoopDetector/DLoopDetector.h include/DLoopDetector/TemplatedLoopDetector.h) +set(DEPENDENCY_DIR ${CMAKE_CURRENT_BINARY_DIR}/dependencies) +set(DEPENDENCY_INSTALL_DIR ${DEPENDENCY_DIR}/install) + find_package(OpenCV REQUIRED) -find_package(DLib REQUIRED) -find_package(DBoW2 REQUIRED) +include_directories(${OpenCV_INCLUDE_DIRS}) + +macro(GetDependency name other_dependency) + find_package(${name} QUIET + PATHS ${DEPENDENCY_INSTALL_DIR}) + if(${${name}_FOUND}) + message("${name} library found, using it from the system") + include_directories(${${name}_INCLUDE_DIRS}) + add_custom_target(${name}) + else(${${name}_FOUND}) + message("${name} library not found in the system, it will be downloaded on build") + option(DOWNLOAD_${name}_dependency "Download ${name} dependency" ON) + if(${DOWNLOAD_${name}_dependency}) + ExternalProject_Add(${name} + PREFIX ${DEPENDENCY_DIR} + GIT_REPOSITORY http://github.com/dorian3d/${name} + GIT_TAG v1.1-nonfree + INSTALL_DIR ${DEPENDENCY_INSTALL_DIR} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= + DEPENDS ${other_dependency}) + else() + message(SEND_ERROR "Please, activate DOWNLOAD_${name}_dependency option or download manually") + endif(${DOWNLOAD_${name}_dependency}) + endif(${${name}_FOUND}) +endmacro(GetDependency) + +GetDependency(DLib "") +GetDependency(DBoW2 DLib) +add_custom_target(Dependencies ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS DBoW2 DLib) -include_directories(include/DLoopDetector/ ${OpenCV_INCLUDE_DIRS} ${DLib_INCLUDE_DIRS} ${DBoW2_INCLUDE_DIRS}) +include_directories(include/DLoopDetector/) if(BUILD_DemoBRIEF) add_executable(demo_brief demo/demo_brief.cpp) @@ -24,18 +71,23 @@ if(BUILD_DemoSURF) endif(BUILD_DemoSURF) if(BUILD_DemoBRIEF OR BUILD_DemoSURF) - set(RESOURCE_FILE ${CMAKE_BINARY_DIR}/resources.tar.gz) - if(NOT EXISTS ${CMAKE_BINARY_DIR}/resources/) - if(NOT EXISTS ${RESOURCE_FILE}) - file(DOWNLOAD http://doriangalvez.com/resources/DLoopDetector/resources.tar.gz - ${RESOURCE_FILE} STATUS status SHOW_PROGRESS EXPECTED_MD5 c001da68ddaceed1de9c16aaac22ed80) - if(${status}) - message(FATAL_ERROR "Error downloading resources for demo applications") - endif(${status}) - endif(NOT EXISTS ${RESOURCE_FILE}) - execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${RESOURCE_FILE}) - file(REMOVE ${RESOURCE_FILE}) - endif(NOT EXISTS ${CMAKE_BINARY_DIR}/resources/) + option(DOWNLOAD_Demo_Resources "Download resources for demo application" ON) + if(DOWNLOAD_Demo_Resources) + set(RESOURCES_DIR ${CMAKE_CURRENT_BINARY_DIR}/resources/) + if(NOT EXISTS ${RESOURCES_DIR}) + ExternalProject_Add(Resources + PREFIX ${CMAKE_BINARY_DIR} + URL http://doriangalvez.com/resources/DLoopDetector/resources.tar.gz + URL_MD5 c001da68ddaceed1de9c16aaac22ed80 + SOURCE_DIR ${RESOURCES_DIR} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "") + add_custom_target(DownloadResources ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS Resources) + endif(NOT EXISTS ${RESOURCES_DIR}) + else() + message("Demo resources are not going to be downloaded unless the option is activated. Demo applications will not work") + endif(DOWNLOAD_Demo_Resources) endif(BUILD_DemoBRIEF OR BUILD_DemoSURF) configure_file(src/DLoopDetector.cmake.in @@ -46,3 +98,4 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DLoopDetectorConfig.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}) install(FILES "${PROJECT_BINARY_DIR}/DLoopDetectorConfig.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/DLoopDetector/) +install(DIRECTORY ${DEPENDENCY_INSTALL_DIR}/ DESTINATION ${CMAKE_INSTALL_PREFIX} OPTIONAL) diff --git a/README.md b/README.md index a3ca5c4..023d0e1 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ If you use this software in an academic work, please cite: ## Install and usage notes +DLoopDetector requires [DLib](https://github.com/dorian3d/DLib) and [DBoW2](https://github.com/dorian3d/DBoW2), which are installed automatically. + DLoopDetector requires OpenCV and the `boost::dynamic_bitset` class in order to use the BRIEF version. You can install Boost by typing: $ sudo apt-get install libboost-dev diff --git a/demo/demoDetector.h b/demo/demoDetector.h index f24e32f..2c81ce5 100644 --- a/demo/demoDetector.h +++ b/demo/demoDetector.h @@ -14,8 +14,8 @@ #include // OpenCV -#include -#include +#include +#include // DLoopDetector and DBoW2 #include diff --git a/demo/demo_brief.cpp b/demo/demo_brief.cpp index cb61fb5..5a248d5 100644 --- a/demo/demo_brief.cpp +++ b/demo/demo_brief.cpp @@ -16,8 +16,8 @@ #include // Brief // OpenCV -#include -#include +#include +#include #include "demoDetector.h" diff --git a/demo/demo_surf.cpp b/demo/demo_surf.cpp index f419d2e..50641c9 100644 --- a/demo/demo_surf.cpp +++ b/demo/demo_surf.cpp @@ -16,11 +16,9 @@ #include // defines macros CVXX // OpenCV -#include -#include -#if CV24 -#include -#endif +#include +#include +#include // Demo #include "demoDetector.h" @@ -81,16 +79,17 @@ void SurfExtractor::operator() (const cv::Mat &im, vector &keys, vector > &descriptors) const { // extract surfs with opencv - static cv::SURF surf_detector(400); + static cv::Ptr surf_detector = + cv::xfeatures2d::SURF::create(400); - surf_detector.extended = 0; + surf_detector->setExtended(false); keys.clear(); // opencv 2.4 does not clear the vector vector plain; - surf_detector(im, cv::Mat(), keys, plain); + surf_detector->detectAndCompute(im, cv::Mat(), keys, plain); // change descriptor format - const int L = surf_detector.descriptorSize(); + const int L = surf_detector->descriptorSize(); descriptors.resize(plain.size() / L); unsigned int j = 0;