Skip to content

Commit

Permalink
Merge pull request #2 from dorian3d/update/version
Browse files Browse the repository at this point in the history
Code updated to OpenCV 3.1
  • Loading branch information
dorian3d committed May 1, 2016
2 parents 84bfc56 + bb2f65e commit 4bb1c69
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 28 deletions.
83 changes: 68 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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=<INSTALL_DIR>
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)
Expand All @@ -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
Expand All @@ -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)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions demo/demoDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <string>

// OpenCV
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>

// DLoopDetector and DBoW2
#include <DBoW2/DBoW2.h>
Expand Down
4 changes: 2 additions & 2 deletions demo/demo_brief.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <DVision/DVision.h> // Brief

// OpenCV
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>

#include "demoDetector.h"

Expand Down
17 changes: 8 additions & 9 deletions demo/demo_surf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
#include <DUtilsCV/DUtilsCV.h> // defines macros CVXX

// OpenCV
#include <opencv/cv.h>
#include <opencv/highgui.h>
#if CV24
#include <opencv2/nonfree/features2d.hpp>
#endif
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>

// Demo
#include "demoDetector.h"
Expand Down Expand Up @@ -81,16 +79,17 @@ void SurfExtractor::operator() (const cv::Mat &im,
vector<cv::KeyPoint> &keys, vector<vector<float> > &descriptors) const
{
// extract surfs with opencv
static cv::SURF surf_detector(400);
static cv::Ptr<cv::xfeatures2d::SURF> 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<float> 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;
Expand Down

0 comments on commit 4bb1c69

Please sign in to comment.