diff --git a/CMakeLists.txt b/CMakeLists.txt index bdb08b0..a967f55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,22 @@ option(BUILD_DUtils "Build DUtils (basic c++ functions)." ON) option(BUILD_DUtilsCV "Build DUtilsCV (OpenCV functions, requires DUtils)." ON) option(BUILD_DVision "Build DVision (computer vision functions, requires DUtilsCV)." ON) +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() + if(BUILD_DUtils) set(HDRS include/DUtils/ include/DUtils/BinaryFile.h include/DUtils/DUtils.h include/DUtils/FileModes.h include/DUtils/Math.hpp @@ -34,17 +50,23 @@ endif(BUILD_DUtilsCV) if(BUILD_DVision) set(HDRS - include/DVision/BRIEF.h include/DVision/DVision.h include/DVision/HSolver.h include/DVision/Matches.h + include/DVision/DVision.h include/DVision/HSolver.h include/DVision/Matches.h include/DVision/PMVSCamera.h include/DVision/PixelPointFile.h include/DVision/BundleCamera.h include/DVision/FSolver.h include/DVision/ImageFunctions.h include/DVision/PLYFile.h include/DVision/PatchFile.h include/DVision/SurfSet.h ${HDRS}) set(SRCS - src/DVision/BRIEF.cpp src/DVision/FSolver.cpp src/DVision/ImageFunctions.cpp src/DVision/PLYFile.cpp + src/DVision/FSolver.cpp src/DVision/ImageFunctions.cpp src/DVision/PLYFile.cpp src/DVision/PatchFile.cpp src/DVision/SurfSet.cpp src/DVision/BundleCamera.cpp src/DVision/HSolver.cpp src/DVision/Matches.cpp src/DVision/PMVSCamera.cpp src/DVision/PixelPointFile.cpp ${SRCS}) + + find_package(Boost QUIET) # For dynamic_bitset + if (Boost_FOUND) + set(HDRS include/DVision/BRIEF.h ${HDRS}) + set(SRCS src/DVision/BRIEF.cpp ${SRCS}) + endif(Boost_FOUND) endif(BUILD_DVision) @@ -52,8 +74,13 @@ if(BUILD_DUtilsCV OR BUILD_DVision) find_package(OpenCV REQUIRED) endif(BUILD_DUtilsCV OR BUILD_DVision) +set(LIB_SHARED "SHARED") +if(WIN32) + set(LIB_SHARED "STATIC") +endif(WIN32) + include_directories(include/DUtils include/DUtilsCV include/DVision ${OpenCV_INCLUDE_DIRS}) -add_library(${PROJECT_NAME} SHARED ${SRCS}) +add_library(${PROJECT_NAME} ${LIB_SHARED} ${SRCS}) target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) configure_file(src/DLib.cmake.in diff --git a/include/DUtils/BinaryFile.h b/include/DUtils/BinaryFile.h index 3766180..1494fe9 100644 --- a/include/DUtils/BinaryFile.h +++ b/include/DUtils/BinaryFile.h @@ -16,7 +16,6 @@ #include "DException.h" #include "FileModes.h" #include -using namespace std; namespace DUtils { @@ -49,7 +48,7 @@ class BinaryFile * @param mode: READ or WRITE * @throws DException if cannot open the file */ - BinaryFile(const string &filename, const FILE_MODES mode); + BinaryFile(const std::string &filename, const FILE_MODES mode); /** * Opens a file for reading. It closes any other opened file @@ -63,7 +62,7 @@ class BinaryFile * @param filename * @throws DException if cannot open the file */ - inline void OpenForReading(const string &filename) + inline void OpenForReading(const std::string &filename) { OpenForReading(filename.c_str()); } @@ -80,7 +79,7 @@ class BinaryFile * @param filename * @throws DException if cannot create the file */ - inline void OpenForWriting(const string &filename) + inline void OpenForWriting(const std::string &filename) { OpenForWriting(filename.c_str()); } @@ -97,7 +96,7 @@ class BinaryFile * @param filename * @throws DException if cannot open the file */ - inline void OpenForAppending(const string &filename) + inline void OpenForAppending(const std::string &filename) { OpenForAppending(filename.c_str()); } @@ -241,7 +240,7 @@ class BinaryFile /// Opening mode FILE_MODES m_mode; // opening mode /// File stream - fstream m_f; // fstream + std::fstream m_f; // fstream /// Auxiliar buffer char m_aux[8]; // auxiliar buffer diff --git a/include/DUtils/ConfigFile.h b/include/DUtils/ConfigFile.h index 548e0d3..8dfaed5 100644 --- a/include/DUtils/ConfigFile.h +++ b/include/DUtils/ConfigFile.h @@ -202,7 +202,7 @@ class ConfigFile * @param used the names of the tokens that cannot be replaced because of * circular dependencies */ - void resolveVar(std::string &value, const std::set &used); + void resolveVar(std::string &value, const std::set &used); protected: @@ -221,7 +221,7 @@ template T ConfigFile::getAnonymous(int n) const { const char U = '?'; - stringstream ss; + std::stringstream ss; ss << U << n; return get(ss.str().c_str()); } @@ -255,11 +255,11 @@ void ConfigFile::put(const std::string &name, const T &data) template void ConfigFile::put(const char *name, const T &data) { - pair::iterator, bool> status; + std::pair::iterator, bool> status; std::string value = StringFunctions::toString(data); - status = m_data.insert(make_pair(name, value)); + status = m_data.insert(std::make_pair(name, value)); if(!status.second) { diff --git a/include/DUtils/DException.h b/include/DUtils/DException.h index c8e7450..4282bb4 100644 --- a/include/DUtils/DException.h +++ b/include/DUtils/DException.h @@ -15,13 +15,12 @@ #include #include -using namespace std; namespace DUtils { /// General exception class DException : - public exception + public std::exception { public: /** @@ -39,7 +38,7 @@ class DException : * Creates an exception with a custom error message * @param msg: message */ - DException(const string &msg) throw(): m_message(msg){} + DException(const std::string &msg) throw(): m_message(msg){} /** * Destructor @@ -56,7 +55,7 @@ class DException : protected: /// Error message - string m_message; + std::string m_message; }; } diff --git a/include/DUtils/DUtils.h b/include/DUtils/DUtils.h index ab75640..7883a8a 100644 --- a/include/DUtils/DUtils.h +++ b/include/DUtils/DUtils.h @@ -16,7 +16,7 @@ * Written by Dorian Galvez-Lopez, * University of Zaragoza * - * Check my website to obtain updates: http://webdiis.unizar.es/~dorian + * Check my website to obtain updates: http://doriangalvez.com * * \section license License * This program is free software: you can redistribute it and/or modify diff --git a/include/DUtils/LineFile.h b/include/DUtils/LineFile.h index ac49126..a3d0150 100644 --- a/include/DUtils/LineFile.h +++ b/include/DUtils/LineFile.h @@ -16,7 +16,6 @@ #include "FileModes.h" #include #include -using namespace std; namespace DUtils { @@ -48,7 +47,7 @@ class LineFile * @param mode: READ or WRITE * @throws DException if cannot open the file */ - LineFile(const string &filename, const FILE_MODES mode); + LineFile(const std::string &filename, const FILE_MODES mode); /** * Opens a file for reading. It closes any other opened file @@ -62,7 +61,7 @@ class LineFile * @param filename * @throws DException if cannot create the file */ - inline void OpenForReading(const string &filename) + inline void OpenForReading(const std::string &filename) { OpenForReading(filename.c_str()); } @@ -79,7 +78,7 @@ class LineFile * @param filename * @throws DException if cannot create the file */ - inline void OpenForWriting(const string &filename) + inline void OpenForWriting(const std::string &filename) { OpenForWriting(filename.c_str()); } @@ -96,7 +95,7 @@ class LineFile * @param filename * @throws DException if cannot open the file */ - inline void OpenForAppending(const string &filename) + inline void OpenForAppending(const std::string &filename) { OpenForAppending(filename.c_str()); } @@ -125,7 +124,7 @@ class LineFile * Writes a line * @throws DException if wrong access mode */ - inline LineFile& operator<< (const string &s) + inline LineFile& operator<< (const std::string &s) { return this->operator <<(s.c_str()); } @@ -135,28 +134,28 @@ class LineFile * @param s: string to write on * @throws DException if wrong access mode */ - LineFile& operator>> (string &s); + LineFile& operator>> (std::string &s); /** * Reads all the remaining lines in the file * @param v vector to store the lines in * @throws DException if wrong access mode */ - LineFile& operator>> (vector &v); + LineFile& operator>> (std::vector &v); /** * Writes several lines at a time * @param v: vector of line strings * @throws DException if wrong access mode */ - void Dump(const vector &v); + void Dump(const std::vector &v); /** * Writes several lines at a time * @param v: vector of line strings * @throws DException if wrong access mode */ - inline LineFile& operator<< (const vector &v) + inline LineFile& operator<< (const std::vector &v) { Dump(v); return *this; @@ -186,9 +185,9 @@ class LineFile /// Opening mode FILE_MODES m_mode; // opening mode /// File stream - fstream m_f; // fstream + std::fstream m_f; // fstream /// Next line to read - string m_next_line; // next line to read + std::string m_next_line; // next line to read }; } diff --git a/include/DUtils/Profiler.h b/include/DUtils/Profiler.h index 3b00ce4..b756de9 100644 --- a/include/DUtils/Profiler.h +++ b/include/DUtils/Profiler.h @@ -200,7 +200,7 @@ class Profiler */ void showStatistics(const std::string &name = "", const std::string &suffix = "s", double scale = 1., - ostream &out = std::cout) const; + std::ostream &out = std::cout) const; protected: diff --git a/include/DUtils/STL.h b/include/DUtils/STL.h index b885bd6..47aaad2 100644 --- a/include/DUtils/STL.h +++ b/include/DUtils/STL.h @@ -303,7 +303,7 @@ void STL::print(const std::vector &v, const std::string &name, f << *vit << " "; } f << "]"; - f << endl; + f << std::endl; } // --------------------------------------------------------------------------- diff --git a/include/DUtils/Timestamp.h b/include/DUtils/Timestamp.h index b92f89f..9717720 100644 --- a/include/DUtils/Timestamp.h +++ b/include/DUtils/Timestamp.h @@ -11,7 +11,6 @@ #define __D_TIMESTAMP__ #include -using namespace std; namespace DUtils { @@ -78,7 +77,7 @@ class Timestamp * Sets the timestamp from a string with the time in seconds * @param stime: string such as "1235603336.036609" */ - void setTime(const string &stime); + void setTime(const std::string &stime); /** * Sets the timestamp from a number of seconds from the epoch @@ -94,7 +93,7 @@ class Timestamp /** * Returns this timestamp as the number of seconds in fixed length string format */ - string getStringTime() const; + std::string getStringTime() const; /** * Returns the difference in seconds between this timestamp (greater) and t (smaller) @@ -181,14 +180,14 @@ class Timestamp * @note This has not been tested under Windows * @note The timestamp is truncated to seconds */ - string Format(bool machine_friendly = false) const; + std::string Format(bool machine_friendly = false) const; /** * Returns a string version of the elapsed time in seconds, with the format * xd hh:mm:ss, hh:mm:ss, mm:ss or s.us * @param s: elapsed seconds (given by getFloatTime) to format */ - static string Format(double s); + static std::string Format(double s); protected: diff --git a/include/DUtilsCV/CvVersion.h b/include/DUtilsCV/CvVersion.h deleted file mode 100644 index 334f675..0000000 --- a/include/DUtilsCV/CvVersion.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * File: CvVersion.h - * Project: - * Author: Dorian Galvez-Lopez - * Date: February 3, 2013 - * Description: Checks OpenCV version - * License: see the LICENSE.txt file - * - */ - -#include - -#if !CV22 && !CV23 && !CV24 - #if CV_MAJOR_VERSION == 2 - #if CV_MINOR_VERSION == 2 - #define CV22 1 - #elif CV_MINOR_VERSION == 3 - #define CV23 1 - #elif CV_MINOR_VERSION == 4 - #define CV24 1 - #endif - #else - #define CV30 1 - #endif -#endif - - diff --git a/include/DUtilsCV/DUtilsCV.h b/include/DUtilsCV/DUtilsCV.h index 40c877f..2d5d41f 100644 --- a/include/DUtilsCV/DUtilsCV.h +++ b/include/DUtilsCV/DUtilsCV.h @@ -16,7 +16,7 @@ * Written by Dorian Galvez-Lopez, * University of Zaragoza * - * Check my website to obtain updates: http://webdiis.unizar.es/~dorian + * Check my website to obtain updates: http://doriangalvez.com * * \section requirements Requirements * This library requires the DUtils library and the OpenCV library. @@ -56,8 +56,5 @@ namespace DUtilsCV #include "Transformations.h" #include "Geometry.h" -// CV version -#include "CvVersion.h" - #endif diff --git a/include/DUtilsCV/Drawing.h b/include/DUtilsCV/Drawing.h index a9acb35..4ca41b3 100644 --- a/include/DUtilsCV/Drawing.h +++ b/include/DUtilsCV/Drawing.h @@ -12,7 +12,8 @@ #define __D_CV_DRAWING__ #include -#include +#include +#include namespace DUtilsCV { diff --git a/include/DUtilsCV/GUI.h b/include/DUtilsCV/GUI.h index 690f221..8fe156d 100644 --- a/include/DUtilsCV/GUI.h +++ b/include/DUtilsCV/GUI.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include namespace DUtilsCV diff --git a/include/DUtilsCV/Geometry.h b/include/DUtilsCV/Geometry.h index 15da524..8d85141 100644 --- a/include/DUtilsCV/Geometry.h +++ b/include/DUtilsCV/Geometry.h @@ -11,7 +11,7 @@ #ifndef __D_CV_GEOMETRY__ #define __D_CV_GEOMETRY__ -#include +#include namespace DUtilsCV { diff --git a/include/DUtilsCV/IO.h b/include/DUtilsCV/IO.h index d7996fe..4454801 100644 --- a/include/DUtilsCV/IO.h +++ b/include/DUtilsCV/IO.h @@ -13,8 +13,7 @@ #include #include -#include -#include +#include #include namespace DUtilsCV @@ -104,26 +103,6 @@ class IO const std::string &nodename = "data"); // Save and Load functions to make calling easier - - /** - * Saves a fern classifier - * @param filename - * @param c - * @param nodename - */ - inline static void save(const std::string &filename, - const cv::FernClassifier &c, - const std::string &nodename = "fern_classifier"); - - /** - * Loads a fern classifier - * @param filename - * @param c - * @param nodename - */ - inline static void load(const std::string &filename, - cv::FernClassifier &c, - const std::string &nodename = "fern_classifier"); }; @@ -167,24 +146,6 @@ void IO::load(const std::string &filename, T& c, // --------------------------------------------------------------------------- -inline void IO::save(const std::string &filename, - const cv::FernClassifier &c, - const std::string &nodename) -{ - IO::save(filename, c, nodename); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -inline void IO::load(const std::string &filename, - cv::FernClassifier &c, - const std::string &nodename) -{ - IO::load(filename, c, nodename); -} - -// --------------------------------------------------------------------------- - } #endif diff --git a/include/DUtilsCV/Mat.h b/include/DUtilsCV/Mat.h index ad59f0d..7ea76d9 100644 --- a/include/DUtilsCV/Mat.h +++ b/include/DUtilsCV/Mat.h @@ -11,7 +11,7 @@ #ifndef __D_CV_MAT__ #define __D_CV_MAT__ -#include +#include #include namespace DUtilsCV diff --git a/include/DUtilsCV/Transformations.h b/include/DUtilsCV/Transformations.h index 4413476..253d0c9 100644 --- a/include/DUtilsCV/Transformations.h +++ b/include/DUtilsCV/Transformations.h @@ -11,7 +11,7 @@ #ifndef __TRANSFORMATIONS__ #define __TRANSFORMATIONS__ -#include +#include namespace DUtilsCV { diff --git a/include/DUtilsCV/Types.h b/include/DUtilsCV/Types.h index 6bc9024..ba2284c 100644 --- a/include/DUtilsCV/Types.h +++ b/include/DUtilsCV/Types.h @@ -11,7 +11,7 @@ #ifndef __D_CV_TYPES__ #define __D_CV_TYPES__ -#include +#include #include namespace DUtilsCV diff --git a/include/DVision/BRIEF.h b/include/DVision/BRIEF.h index 1ae244b..eec1c54 100644 --- a/include/DVision/BRIEF.h +++ b/include/DVision/BRIEF.h @@ -29,7 +29,7 @@ #ifndef __D_BRIEF__ #define __D_BRIEF__ -#include +#include #include #include @@ -47,7 +47,7 @@ class BRIEF enum Type { RANDOM, // random pairs (Calonder's original version) - RANDOM_CLOSE, // random but close pairs (used in GalvezIROS11) + RANDOM_CLOSE // random but close pairs (used in GalvezIROS11) }; public: diff --git a/include/DVision/BundleCamera.h b/include/DVision/BundleCamera.h index 8720980..f9f0f3f 100644 --- a/include/DVision/BundleCamera.h +++ b/include/DVision/BundleCamera.h @@ -12,7 +12,7 @@ #define __BUNDLE_CAMERA__ #include -#include +#include #include #include diff --git a/include/DVision/DVision.h b/include/DVision/DVision.h index 40bcc54..b26b00d 100644 --- a/include/DVision/DVision.h +++ b/include/DVision/DVision.h @@ -16,7 +16,7 @@ * Written by Dorian Galvez-Lopez, * University of Zaragoza * - * Check my website to obtain updates: http://webdiis.unizar.es/~dorian + * Check my website to obtain updates: http://doriangalvez.com * * \section requirements Requirements * This library requires the DUtils and DUtilsCV libraries and the OpenCV library. diff --git a/include/DVision/FSolver.h b/include/DVision/FSolver.h index 0e9586a..8c6c011 100644 --- a/include/DVision/FSolver.h +++ b/include/DVision/FSolver.h @@ -11,7 +11,7 @@ #ifndef __D_F_SOLVER__ #define __D_F_SOLVER__ -#include +#include #include namespace DVision { diff --git a/include/DVision/HSolver.h b/include/DVision/HSolver.h index 1b1519b..2331590 100644 --- a/include/DVision/HSolver.h +++ b/include/DVision/HSolver.h @@ -11,7 +11,7 @@ #ifndef __D_H_SOLVER__ #define __D_H_SOLVER__ -#include +#include #include #include "FSolver.h" diff --git a/include/DVision/ImageFunctions.h b/include/DVision/ImageFunctions.h index 2215526..562d03d 100644 --- a/include/DVision/ImageFunctions.h +++ b/include/DVision/ImageFunctions.h @@ -11,7 +11,7 @@ #ifndef __D_IMAGE_FUNCTIONS__ #define __D_IMAGE_FUNCTIONS__ -#include +#include namespace DVision { diff --git a/include/DVision/PMVSCamera.h b/include/DVision/PMVSCamera.h index 5701367..7cd516b 100644 --- a/include/DVision/PMVSCamera.h +++ b/include/DVision/PMVSCamera.h @@ -12,7 +12,7 @@ #define __PMVS_CAMERA__ #include -#include +#include #include namespace DVision { diff --git a/include/DVision/SurfSet.h b/include/DVision/SurfSet.h index 0ca6ffe..7e49bb2 100644 --- a/include/DVision/SurfSet.h +++ b/include/DVision/SurfSet.h @@ -17,12 +17,8 @@ #ifndef __D_SURF_SET__ #define __D_SURF_SET__ -// Set if U-SURF is supported by Opencv (probably by applying this patch: -// https://code.ros.org/trac/opencv/ticket/825 ) -#define USURF_SUPPORTED 0 - -#include -#include +#include +#include #include #include @@ -55,11 +51,8 @@ class SurfSet void Extract(const cv::Mat &image, double hessianTh = 400.0, bool extended = false); -#if USURF_SUPPORTED /** * Extract U-SURF points from an image - * NOTE: this function is only available if opencv supports U-SURF - * (by applying the corresponding patch) * @param image * @param surf surf data * @param hessianTh hessian threshold @@ -68,7 +61,6 @@ class SurfSet */ void _ExtractUpright(const cv::Mat &image, double hessianTh = 400.0, bool extended = false); -#endif /** * Copies the given keypoints and computes their SURF descriptors @@ -80,11 +72,8 @@ class SurfSet void Compute(const cv::Mat &image, const std::vector &keypoints, bool extended = false); -#if USURF_SUPPORTED /** * Copies the given keypoints and computes their U-SURF descriptors - * NOTE: this function is only available if opencv supports U-SURF - * (by applying the corresponding patch) * @param image * @param keypoints * @param extended if true, 128-dimensional surf are used instead of 64-d @@ -92,7 +81,6 @@ class SurfSet */ void _ComputeUpright(const cv::Mat &image, const std::vector &keypoints, bool extended = false); -#endif /** * Returns the length of the descriptor vectors of the SURF features @@ -228,13 +216,27 @@ class SurfSet protected: + struct SURFParams { + float hessianThreshold; + bool extended; + bool upright; + int nOctaves; + int nOctaveLayers; + + SURFParams(float hessianThreshold = 400, bool extended = false, + bool upright = false, + int nOctaves = 4, int nOctaveLayers = 3) + : hessianThreshold(hessianThreshold), extended(extended), + upright(upright), nOctaves(nOctaves), nOctaveLayers(nOctaveLayers) {} + }; + /** * Performs the actual extraction with the provided parameters * @param image * @param params surf detector params * @see SurfSet::Extract */ - void extract(const cv::Mat &image, const CvSURFParams ¶ms); + void extract(const cv::Mat &image, const SURFParams ¶ms); /** * Performs the actual computation with the provided parameters @@ -244,7 +246,7 @@ class SurfSet * @see SurfSet::Compute */ void compute(const cv::Mat &image, - const std::vector &keypoints, const CvSURFParams ¶ms); + const std::vector &keypoints, const SURFParams ¶ms); /** * Calculates the square distance between two descriptors @@ -290,7 +292,7 @@ class SurfSet * @note This function is copied from the opencv surf.cpp file, written * by Liu Liu */ - int getPointOctave(const CvSURFPoint& kpt, const CvSURFParams& params) const; + int getPointOctave(const cv::KeyPoint& kpt, const SURFParams& params) const; protected: diff --git a/src/DLib.cmake.in b/src/DLib.cmake.in index 86de2a4..42a8cd5 100644 --- a/src/DLib.cmake.in +++ b/src/DLib.cmake.in @@ -4,8 +4,9 @@ FIND_LIBRARY(DLib_LIBRARY DLib FIND_PATH(DLib_INCLUDE_DIR DLibConfig.cmake PATHS @CMAKE_INSTALL_PREFIX@/include/@PROJECT_NAME@ ) -LIST(APPEND DLib_INCLUDE_DIR ${DLib_INCLUDE_DIR}/../DUtils +LIST(APPEND DLib_INCLUDE_DIR + ${DLib_INCLUDE_DIR}/../ ${DLib_INCLUDE_DIR}/../DUtils ${DLib_INCLUDE_DIR}/../DUtilsCV ${DLib_INCLUDE_DIR}/../DVision) SET(DLib_LIBRARIES ${DLib_LIBRARY}) SET(DLib_LIBS ${DLib_LIBRARY}) -SET(DLib_INCLUDE_DIRS ${DLib_INCLUDE_DIR}) \ No newline at end of file +SET(DLib_INCLUDE_DIRS ${DLib_INCLUDE_DIR}) diff --git a/src/DUtils/BinaryFile.cpp b/src/DUtils/BinaryFile.cpp index 029c689..532a7db 100644 --- a/src/DUtils/BinaryFile.cpp +++ b/src/DUtils/BinaryFile.cpp @@ -57,7 +57,7 @@ BinaryFile::BinaryFile(const char *filename, const FILE_MODES mode) Init(filename, mode); } -BinaryFile::BinaryFile(const string &filename, const FILE_MODES mode) +BinaryFile::BinaryFile(const std::string &filename, const FILE_MODES mode) { Init(filename.c_str(), mode); } @@ -82,9 +82,9 @@ void BinaryFile::OpenForReading(const char *filename) { Close(); - m_f.open(filename, ios::in | ios::binary); + m_f.open(filename, std::ios::in | std::ios::binary); if(!m_f.is_open()){ - throw DException(string("Cannot open ") + filename + " for reading"); + throw DException(std::string("Cannot open ") + filename + " for reading"); }else{ m_mode = READ; } @@ -94,9 +94,9 @@ void BinaryFile::OpenForWriting(const char *filename) { Close(); - m_f.open(filename, ios::out | ios::binary); + m_f.open(filename, std::ios::out | std::ios::binary); if(!m_f.is_open()){ - throw DException(string("Cannot open ") + filename + " for writing"); + throw DException(std::string("Cannot open ") + filename + " for writing"); }else{ m_mode = WRITE; } @@ -106,9 +106,9 @@ void BinaryFile::OpenForAppending(const char *filename) { Close(); - m_f.open(filename, ios::out | ios::app | ios::binary); + m_f.open(filename, std::ios::out | std::ios::app | std::ios::binary); if(!m_f.is_open()){ - throw DException(string("Cannot open ") + filename + " for writing at the end"); + throw DException(std::string("Cannot open ") + filename + " for writing at the end"); }else{ m_mode = DUtils::FILE_MODES(WRITE | APPEND); } diff --git a/src/DUtils/Timestamp.cpp b/src/DUtils/Timestamp.cpp index 4551839..8281dfc 100644 --- a/src/DUtils/Timestamp.cpp +++ b/src/DUtils/Timestamp.cpp @@ -96,7 +96,7 @@ double Timestamp::getFloatTime() const { string Timestamp::getStringTime() const { char buf[32]; - sprintf(buf, "%.6lf", this->getFloatTime()); + sprintf(buf, "%.6f", this->getFloatTime()); return string(buf); } diff --git a/src/DUtilsCV/Drawing.cpp b/src/DUtilsCV/Drawing.cpp index 45233d9..9b56416 100644 --- a/src/DUtilsCV/Drawing.cpp +++ b/src/DUtilsCV/Drawing.cpp @@ -9,8 +9,9 @@ */ #include -#include -#include +#include +#include +#include #include "Drawing.h" using namespace std; @@ -125,7 +126,7 @@ void Drawing::drawCorrespondences(cv::Mat &image, const cv::Mat &img1, cvSetImageROI(ipl_ret, roi); IplImage ipl_aux1 = IplImage(aux1); - cvCopyImage(&ipl_aux1, ipl_ret); + cvCopy(&ipl_aux1, ipl_ret); roi.x = 0; roi.y = img1.rows; @@ -134,7 +135,7 @@ void Drawing::drawCorrespondences(cv::Mat &image, const cv::Mat &img1, cvSetImageROI(ipl_ret, roi); IplImage ipl_aux2 = IplImage(aux2); - cvCopyImage(&ipl_aux2, ipl_ret); + cvCopy(&ipl_aux2, ipl_ret); cvResetImageROI(ipl_ret); diff --git a/src/DUtilsCV/GUI.cpp b/src/DUtilsCV/GUI.cpp index 615a2d4..429237e 100644 --- a/src/DUtilsCV/GUI.cpp +++ b/src/DUtilsCV/GUI.cpp @@ -10,8 +10,9 @@ #include #include -#include -#include +#include +#include +#include #include #include #include diff --git a/src/DUtilsCV/Geometry.cpp b/src/DUtilsCV/Geometry.cpp index e29d8c2..32ab557 100644 --- a/src/DUtilsCV/Geometry.cpp +++ b/src/DUtilsCV/Geometry.cpp @@ -8,7 +8,7 @@ * */ -#include +#include #include "Geometry.h" #include "Types.h" diff --git a/src/DUtilsCV/IO.cpp b/src/DUtilsCV/IO.cpp index ac9d500..fc0eb24 100644 --- a/src/DUtilsCV/IO.cpp +++ b/src/DUtilsCV/IO.cpp @@ -10,8 +10,8 @@ #include #include -#include -#include +#include +#include #include #include "IO.h" #include "Types.h" diff --git a/src/DUtilsCV/Mat.cpp b/src/DUtilsCV/Mat.cpp index 7ab0a14..9690f8d 100644 --- a/src/DUtilsCV/Mat.cpp +++ b/src/DUtilsCV/Mat.cpp @@ -9,7 +9,7 @@ */ #include "Mat.h" -#include +#include #include using namespace std; diff --git a/src/DUtilsCV/Transformations.cpp b/src/DUtilsCV/Transformations.cpp index 858222a..cbdaebe 100644 --- a/src/DUtilsCV/Transformations.cpp +++ b/src/DUtilsCV/Transformations.cpp @@ -10,7 +10,8 @@ #include "Transformations.h" #include "Types.h" -#include +#include +#include using namespace DUtilsCV; diff --git a/src/DUtilsCV/Types.cpp b/src/DUtilsCV/Types.cpp index 235e228..87095ed 100644 --- a/src/DUtilsCV/Types.cpp +++ b/src/DUtilsCV/Types.cpp @@ -8,7 +8,7 @@ * */ -#include +#include #include #include "Types.h" diff --git a/src/DVision/BRIEF.cpp b/src/DVision/BRIEF.cpp index 2795d49..2782e52 100644 --- a/src/DVision/BRIEF.cpp +++ b/src/DVision/BRIEF.cpp @@ -13,6 +13,7 @@ #include "BRIEF.h" #include "DUtils.h" #include +#include #include using namespace std; diff --git a/src/DVision/BundleCamera.cpp b/src/DVision/BundleCamera.cpp index 29924b3..ef1d56d 100644 --- a/src/DVision/BundleCamera.cpp +++ b/src/DVision/BundleCamera.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include "BundleCamera.h" using namespace DVision::Bundle; diff --git a/src/DVision/FSolver.cpp b/src/DVision/FSolver.cpp index 2c503e6..3b62555 100644 --- a/src/DVision/FSolver.cpp +++ b/src/DVision/FSolver.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include "FSolver.h" #include "DUtils.h" diff --git a/src/DVision/HSolver.cpp b/src/DVision/HSolver.cpp index 44d0e5c..1d61772 100644 --- a/src/DVision/HSolver.cpp +++ b/src/DVision/HSolver.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include "HSolver.h" #include "DUtils.h" diff --git a/src/DVision/ImageFunctions.cpp b/src/DVision/ImageFunctions.cpp index 51f28d1..5120651 100644 --- a/src/DVision/ImageFunctions.cpp +++ b/src/DVision/ImageFunctions.cpp @@ -8,7 +8,8 @@ * */ -#include +#include +#include #include "ImageFunctions.h" #include "DUtils.h" diff --git a/src/DVision/Matches.cpp b/src/DVision/Matches.cpp index c39d567..4b7538b 100644 --- a/src/DVision/Matches.cpp +++ b/src/DVision/Matches.cpp @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include #include "Matches.h" #include "DUtilsCV.h" // defines macros CVXX diff --git a/src/DVision/PMVSCamera.cpp b/src/DVision/PMVSCamera.cpp index fb586c8..10b652b 100644 --- a/src/DVision/PMVSCamera.cpp +++ b/src/DVision/PMVSCamera.cpp @@ -9,7 +9,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/DVision/SurfSet.cpp b/src/DVision/SurfSet.cpp index fe81049..dbbd79f 100644 --- a/src/DVision/SurfSet.cpp +++ b/src/DVision/SurfSet.cpp @@ -21,14 +21,10 @@ #include #include "DUtils.h" -#include "DUtilsCV.h" // defines macros CVXX - -#include -#include -#if CV24 -#include -#endif +#include +#include +#include using namespace std; @@ -108,93 +104,44 @@ void SurfSet::LoadCustom(const std::string &filename) void SurfSet::Extract(const cv::Mat &image, double hessianTh, bool extended) { - CvSURFParams params = cvSURFParams(hessianTh, (extended ? 1: 0) ); + SURFParams params(hessianTh, extended); extract(image, params); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#if USURF_SUPPORTED void SurfSet::_ExtractUpright(const cv::Mat &image, double hessianTh, bool extended) { - CvSURFParams params = cvSURFParams(hessianTh, (extended ? 1: 0) ); - params.upright = 1; + SURFParams params(hessianTh, extended, true); extract(image, params); } -#endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SurfSet::extract(const cv::Mat &image, const CvSURFParams ¶ms) +void SurfSet::extract(const cv::Mat &image, const SURFParams ¶ms) { - #if CV24 - // OpenCV 2.4 implementation - - cv::SURF surf(params.hessianThreshold, params.nOctaves, params.nOctaveLayers, - (params.extended == 1), false /* upright */); - - cv::Mat descs; - surf(image, cv::Mat() /* mask */, this->keys, descs); - - const int L = (params.extended == 1 ? 128 : 64); - this->descriptors.resize(this->keys.size() * L); - this->laplacians.resize(this->keys.size()); - - vector::const_iterator kit; - vector::iterator lit = this->laplacians.begin(); - for(kit = this->keys.begin(); kit != this->keys.end(); ++kit, ++lit) - { - *lit = kit->class_id; // laplacian sign should be stored here - } - - //assert(descs.type() == CV_32F && descs.isContinuous()); - - std::copy(descs.ptr(), descs.ptr() + (descs.rows * descs.cols), - this->descriptors.begin()); - - #else - - // old implementation opencv 2.0 - CvSeq *kp1=NULL; - CvSeq *desc1=NULL; - CvMemStorage *storage = cvCreateMemStorage(0); - - IplImage ipl_image = IplImage(image); - cvExtractSURF(&ipl_image, NULL, &kp1, &desc1, storage, params); + cv::Ptr surf = cv::xfeatures2d::SURF::create( + params.hessianThreshold, params.nOctaves, params.nOctaveLayers, + params.extended, params.upright); - CvSeqReader reader, kreader; - cvStartReadSeq( desc1, &reader, 0 ); - cvStartReadSeq( kp1, &kreader, 0 ); + cv::Mat descs; + surf->detectAndCompute(image, cv::Mat() /* mask */, this->keys, descs); - const int L = (params.extended ? 128 : 64); + const int L = (params.extended == 1 ? 128 : 64); + this->descriptors.resize(this->keys.size() * L); + this->laplacians.resize(this->keys.size()); - descriptors.resize(desc1->total * L); - keys.resize(kp1->total); - laplacians.resize(kp1->total); + vector::const_iterator kit; + vector::iterator lit = this->laplacians.begin(); + for(kit = this->keys.begin(); kit != this->keys.end(); ++kit, ++lit) + { + *lit = kit->class_id; // laplacian sign should be stored here + } - for( int i = 0; i < desc1->total; i++ ) - { - const CvSURFPoint *p= (const CvSURFPoint*)kreader.ptr; - const float* vec = (const float*)reader.ptr; - CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader ); - CV_NEXT_SEQ_ELEM( kreader.seq->elem_size, kreader ); - - keys[i].pt.x = p->pt.x; - keys[i].pt.y = p->pt.y; - keys[i].angle = p->dir; - keys[i].size = (float)p->size; - keys[i].response = p->hessian; - keys[i].octave = getPointOctave(*p, params); - laplacians[i] = p->laplacian; - - for(int j = 0; j < L; ++j){ - descriptors[i*L + j] = vec[j]; - } - } - - cvReleaseMemStorage(&storage); - - #endif + //assert(descs.type() == CV_32F && descs.isContinuous()); + + std::copy(descs.ptr(), descs.ptr() + (descs.rows * descs.cols), + this->descriptors.begin()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -202,115 +149,56 @@ void SurfSet::extract(const cv::Mat &image, const CvSURFParams ¶ms) void SurfSet::Compute(const cv::Mat &image, const std::vector &keypoints, bool extended) { - CvSURFParams params = cvSURFParams(0, (extended ? 1: 0) ); + SURFParams params(0, extended); compute(image, keypoints, params); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#if USURF_SUPPORTED - void SurfSet::_ComputeUpright(const cv::Mat &image, const std::vector &keypoints, bool extended) { - CvSURFParams params = cvSURFParams(0, (extended ? 1: 0) ); - params.upright = 1; + SURFParams params(0, extended, true); compute(image, keypoints, params); } -#endif - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SurfSet::compute(const cv::Mat &image, - const std::vector &keypoints, const CvSURFParams ¶ms) + const std::vector &keypoints, const SURFParams ¶ms) { - #if CV24 - // OpenCV 2.4 implementation - if(keypoints.empty()) - { - this->keys.clear(); - this->descriptors.clear(); - this->laplacians.clear(); - } - else - { - this->keys = keypoints; + if(keypoints.empty()) + { + this->keys.clear(); + this->descriptors.clear(); + this->laplacians.clear(); + } + else + { + this->keys = keypoints; - cv::SURF surf(params.hessianThreshold, params.nOctaves, - params.nOctaveLayers, (params.extended == 1), false /* upright */); - - cv::Mat descs; - surf(image, cv::Mat() /* mask */, this->keys, descs, true); - - this->descriptors.resize(this->keys.size() * descs.cols); - this->laplacians.resize(this->keys.size()); - - vector::const_iterator kit; - vector::iterator lit = this->laplacians.begin(); - for(kit = this->keys.begin(); kit != this->keys.end(); ++kit, ++lit) - { - *lit = kit->class_id; // laplacian sign should be stored here - } - - assert(descs.type() == CV_32F && descs.isContinuous()); - - std::copy(descs.ptr(), descs.ptr() + (descs.rows * descs.cols), - this->descriptors.begin()); - } - - #else - - const int L = (params.extended ? 128 : 64); - - keys = keypoints; - laplacians.resize(keys.size()); - descriptors.resize(keys.size() * L); - - std::fill(laplacians.begin(), laplacians.end(), 1); + cv::Ptr surf = cv::xfeatures2d::SURF::create( + params.hessianThreshold, params.nOctaves, params.nOctaveLayers, + params.extended, params.upright); + + cv::Mat descs; + surf->compute(image, this->keys, descs); - CvSeqWriter writer; - CvMemStorage *storage = cvCreateMemStorage(0); - cvStartWriteSeq(0, sizeof(CvSeq), sizeof(CvSURFPoint), storage, &writer); - CvSURFPoint p; + this->descriptors.resize(this->keys.size() * descs.cols); + this->laplacians.resize(this->keys.size()); - std::vector::const_iterator kit; - for(kit = keypoints.begin(); kit != keypoints.end(); ++kit) + vector::const_iterator kit; + vector::iterator lit = this->laplacians.begin(); + for(kit = this->keys.begin(); kit != this->keys.end(); ++kit, ++lit) { - p.pt.x = kit->pt.x; - p.pt.y = kit->pt.y; - p.dir = kit->angle; - p.size = kit->size; - p.hessian = kit->response; - p.laplacian = 1; - - CV_WRITE_SEQ_ELEM(p, writer); + *lit = kit->class_id; // laplacian sign should be stored here } - - CvSeq *kp1 = cvEndWriteSeq(&writer); - CvSeq *desc1 = NULL; - - IplImage ipl_image = IplImage(image); - cvExtractSURF(&ipl_image, NULL, &kp1, &desc1, storage, - params, 1); // use provided keypoints); - - CvSeqReader reader; - cvStartReadSeq( desc1, &reader, 0 ); - assert(desc1->total == (int)keys.size()); // ### check - - for( int i = 0; i < desc1->total; i++ ) - { - const float* vec = (const float*)reader.ptr; - CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader ); + assert(descs.type() == CV_32F && descs.isContinuous()); - for(int j = 0; j < L; ++j){ - descriptors[i*L + j] = vec[j]; - } - } - - cvReleaseMemStorage(&storage); - #endif + std::copy(descs.ptr(), descs.ptr() + (descs.rows * descs.cols), + this->descriptors.begin()); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -630,23 +518,9 @@ void SurfSet::save(cv::FileStorage &fs, int idx) const fs << "descriptor_length" << GetDescriptorLength(); cv::write(fs, "keypoints", keys); - #if CV24 - cv::write(fs, "descriptors", descriptors); - cv::write(fs, "laplacians", laplacians); - #else - - if(!descriptors.empty()) - fs << "descriptors" << "[" << descriptors << "]"; - else - fs << "descriptors" << "[" << "]"; - - if(!laplacians.empty()) - fs << "laplacians" << "[" << laplacians << "]"; - else - fs << "laplacians" << "[" << "]"; - - #endif - + cv::write(fs, "descriptors", descriptors); + cv::write(fs, "laplacians", laplacians); + fs << "}"; } @@ -678,18 +552,13 @@ void SurfSet::load(cv::FileStorage &fs, int idx) descriptors.resize(keys.size() * L); laplacians.resize(keys.size()); - #if CV24 - cv::read(fn["descriptors"], descriptors); - cv::read(fn["laplacians"], laplacians); - #else - fn["descriptors"] >> descriptors; - fn["laplacians"] >> laplacians; - #endif + cv::read(fn["descriptors"], descriptors); + cv::read(fn["laplacians"], laplacians); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int SurfSet::getPointOctave(const CvSURFPoint& kpt, const CvSURFParams& params) +int SurfSet::getPointOctave(const cv::KeyPoint& kpt, const SURFParams& params) const { // these are as defined in opencv surf.cpp