diff --git a/.cproject b/.cproject index fb26a59fb395cb1692a20a67d7f9d8d029898dc6..9c0b0f80b66e6fd52b9ad948d7afd3f059c3a9fd 100644 --- a/.cproject +++ b/.cproject @@ -23,7 +23,7 @@ <builder buildPath="${workspace_loc:/vision_utils}/build" id="cdt.managedbuild.target.gnu.builder.base.1544635012" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/> <tool id="cdt.managedbuild.tool.gnu.archiver.base.646136846" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.433122623" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"> - <option id="gnu.cpp.compiler.option.include.paths.937784075" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"> + <option id="gnu.cpp.compiler.option.include.paths.937784075" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <listOptionValue builtIn="false" value="/usr/local/include"/> <listOptionValue builtIn="false" value="/usr/include"/> <listOptionValue builtIn="false" value="/opt/ros/indigo/include/opencv-3.1.0-dev"/> @@ -31,7 +31,7 @@ <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.341288586" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> </tool> <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.61708613" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"> - <option id="gnu.c.compiler.option.include.paths.829945653" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"> + <option id="gnu.c.compiler.option.include.paths.829945653" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <listOptionValue builtIn="false" value="/usr/local/include"/> <listOptionValue builtIn="false" value="/usr/include"/> <listOptionValue builtIn="false" value="/opt/ros/indigo/include/opencv-3.1.0-dev"/> @@ -40,7 +40,7 @@ </tool> <tool id="cdt.managedbuild.tool.gnu.c.linker.base.2056051326" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/> <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1724439765" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"> - <option id="gnu.cpp.link.option.paths.619011598" superClass="gnu.cpp.link.option.paths" valueType="libPaths"> + <option id="gnu.cpp.link.option.paths.619011598" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths"> <listOptionValue builtIn="false" value="/usr/lib"/> <listOptionValue builtIn="false" value="/usr/local/lib"/> </option> @@ -50,7 +50,7 @@ </inputType> </tool> <tool id="cdt.managedbuild.tool.gnu.assembler.base.507993336" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"> - <option id="gnu.both.asm.option.include.paths.408889783" superClass="gnu.both.asm.option.include.paths" valueType="includePath"> + <option id="gnu.both.asm.option.include.paths.408889783" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"> <listOptionValue builtIn="false" value="/usr/local/include"/> <listOptionValue builtIn="false" value="/usr/include"/> <listOptionValue builtIn="false" value="/opt/ros/indigo/include/opencv-3.1.0-dev"/> @@ -101,4 +101,5 @@ </scannerConfigBuildInfo> </storageModule> <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/> + <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> </cproject> diff --git a/cmake_modules/FindYamlCpp.cmake b/cmake_modules/FindYamlCpp.cmake new file mode 100644 index 0000000000000000000000000000000000000000..196c4754e2787a9fa4f47eb8716fd2525bc84fd4 --- /dev/null +++ b/cmake_modules/FindYamlCpp.cmake @@ -0,0 +1,99 @@ +# Locate yaml-cpp +# +# This module defines +# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp +# YAMLCPP_LIBNAME, name of yaml library +# YAMLCPP_LIBRARY, where to find yaml-cpp +# YAMLCPP_LIBRARY_RELEASE, where to find Release or RelWithDebInfo yaml-cpp +# YAMLCPP_LIBRARY_DEBUG, where to find Debug yaml-cpp +# YAMLCPP_INCLUDE_DIR, where to find yaml.h +# YAMLCPP_LIBRARY_DIR, the directories to find YAMLCPP_LIBRARY +# +# By default, the dynamic libraries of yaml-cpp will be found. To find the static ones instead, +# you must set the YAMLCPP_USE_STATIC_LIBS variable to TRUE before calling find_package(YamlCpp ...) + +# attempt to find static library first if this is set +if(YAMLCPP_USE_STATIC_LIBS) + set(YAMLCPP_STATIC libyaml-cpp.a) + set(YAMLCPP_STATIC_DEBUG libyaml-cpp-dbg.a) +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ### Set Yaml libary name for Windows + set(YAMLCPP_LIBNAME "libyaml-cppmd" CACHE STRING "Name of YAML library") + set(YAMLCPP_LIBNAME optimized ${YAMLCPP_LIBNAME} debug ${YAMLCPP_LIBNAME}d) +else() ### Set Yaml libary name for Unix, Linux, OS X, etc + set(YAMLCPP_LIBNAME "yaml-cpp" CACHE STRING "Name of YAML library") +endif() + +# find the yaml-cpp include directory +find_path(YAMLCPP_INCLUDE_DIR + NAMES yaml-cpp/yaml.h + PATH_SUFFIXES include + PATHS + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/include + ~/Library/Frameworks/yaml-cpp/include/ + /Library/Frameworks/yaml-cpp/include/ + /usr/local/include/ + /usr/include/ + /sw/yaml-cpp/ # Fink + /opt/local/yaml-cpp/ # DarwinPorts + /opt/csw/yaml-cpp/ # Blastwave + /opt/yaml-cpp/) + +# find the release yaml-cpp library +find_library(YAMLCPP_LIBRARY_RELEASE + NAMES ${YAMLCPP_STATIC} yaml-cpp libyaml-cppmd.lib + PATH_SUFFIXES lib64 lib Release RelWithDebInfo + PATHS + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/ + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt) + +# find the debug yaml-cpp library +find_library(YAMLCPP_LIBRARY_DEBUG + NAMES ${YAMLCPP_STATIC_DEBUG} yaml-cpp-dbg libyaml-cppmdd.lib + PATH_SUFFIXES lib64 lib Debug + PATHS + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/ + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt) + +# set library vars +set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_RELEASE}) +if(CMAKE_BUILD_TYPE MATCHES Debug AND EXISTS ${YAMLCPP_LIBRARY_DEBUG}) + set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_DEBUG}) +endif() + +get_filename_component(YAMLCPP_LIBRARY_RELEASE_DIR ${YAMLCPP_LIBRARY_RELEASE} PATH) +get_filename_component(YAMLCPP_LIBRARY_DEBUG_DIR ${YAMLCPP_LIBRARY_DEBUG} PATH) +set(YAMLCPP_LIBRARY_DIR ${YAMLCPP_LIBRARY_RELEASE_DIR} ${YAMLCPP_LIBRARY_DEBUG_DIR}) + +# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG + YAMLCPP_INCLUDE_DIR + YAMLCPP_LIBRARY + YAMLCPP_LIBRARY_DIR) +mark_as_advanced( + YAMLCPP_INCLUDE_DIR + YAMLCPP_LIBRARY_DIR + YAMLCPP_LIBRARY + YAMLCPP_LIBRARY_RELEASE + YAMLCPP_LIBRARY_RELEASE_DIR + YAMLCPP_LIBRARY_DEBUG + YAMLCPP_LIBRARY_DEBUG_DIR) + diff --git a/internal/config.h b/internal/config.h new file mode 100644 index 0000000000000000000000000000000000000000..6449c336a10ce2de3629678959b70208e2055486 --- /dev/null +++ b/internal/config.h @@ -0,0 +1,6 @@ +#ifndef VU_INTERNAL_CONFIG_H_ +#define VU_INTERNAL_CONFIG_H_ + +#define _VU_ROOT_DIR "/home/asantamaria/git/asantamaria_cpp/vision_utils" + +#endif /* VU_INTERNAL_CONFIG_H_ */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 471ed40a450f258cb329d610740ed5646ba3a304..caeb1d5afc126c3c5eb9c98b8919472d9b435a26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,23 @@ # library source files -#SET(sources vision_utils.cpp cam_utils/cam_utils.cpp feature_detector/feature_detector.cpp feature_descriptor/feature_descriptor.cpp feature_matcher/feature_matcher.cpp) -SET(sources vision_utils.cpp detectors/detector_base.cpp detectors/detector_orb.cpp) +#SET(sources vision_utils.cpp feature_detector/feature_detector.cpp feature_descriptor/feature_descriptor.cpp feature_matcher/feature_matcher.cpp) +SET(sources + vision_utils.cpp + sensors/sensor_base.cpp + sensors/camera/sensor_camera.cpp + detectors/detector_base.cpp + detectors/orb/detector_orb.cpp) # application header files -#SET(headers vision_utils.h common/common_base.h cam_utils/cam_utils.h feature_detector/feature_detector.h feature_descriptor/feature_descriptor.h feature_matcher/feature_matcher.h) -SET(headers vision_utils.h factory.h detectors/detector_factory.h detectors/detector_base.h detectors/detector_orb.h) +#SET(headers vision_utils.h feature_detector/feature_detector.h feature_descriptor/feature_descriptor.h feature_matcher/feature_matcher.h) +SET(headers + vision_utils.h + factory.h + sensors/sensor_factory.h + sensors/sensor_base.h + sensors/camera/sensor_camera.h + detectors/detector_factory.h + detectors/detector_base.h + detectors/orb/detector_orb.h) # locate the necessary dependencies FIND_PACKAGE(Eigen3 REQUIRED) @@ -28,8 +41,7 @@ endif(OpenCV_FOUND) INCLUDE (${PROJECT_SOURCE_DIR}/cmake_modules/FindYamlCpp.cmake) IF(YAMLCPP_FOUND) MESSAGE(STATUS "Yaml-cpp related sources will be built.") - #SET(ENV{USE_YAML} true) - add_definitions( -DUSING_YAML ) + ADD_DEFINITIONS( -DUSING_YAML ) ELSEIF(YAMLCPP_FOUND) MESSAGE("[WARN] yaml-cpp Library NOT FOUND!") ENDIF(YAMLCPP_FOUND) @@ -41,15 +53,33 @@ IF(YAMLCPP_FOUND) INCLUDE_DIRECTORIES(${YAMLCPP_INCLUDE_DIR}) ENDIF(YAMLCPP_FOUND) +SET(_VU_ROOT_DIR ${CMAKE_SOURCE_DIR}) + +# Define the directory where will be the configured config.h +SET(VU_CONFIG_DIR ${PROJECT_BINARY_DIR}/conf/internal) + +# Create the specified output directory if it does not exist. +IF(NOT EXISTS "${VU_CONFIG_DIR}") + MESSAGE(STATUS "Creating config output directory: ${VU_CONFIG_DIR}") + FILE(MAKE_DIRECTORY "${VU_CONFIG_DIR}") +ENDIF() +IF(EXISTS "${VU_CONFIG_DIR}" AND NOT IS_DIRECTORY "${VU_CONFIG_DIR}") + MESSAGE(FATAL_ERROR "Bug: Specified CONFIG_DIR: ${VU_CONFIG_DIR} exists, but is not a directory.") +ENDIF() +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/internal/config.h.in "${VU_CONFIG_DIR}/config.h") + +# Include config.h directory at first. +include_directories("${PROJECT_BINARY_DIR}/conf") + # create the shared library ADD_LIBRARY(${PROJECT_NAME} SHARED ${sources}) # link necessary libraries TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS} ${Boost_LIBRARIES}) -IF(YAMLCPP_FOUND) -INCLUDE_DIRECTORIES(${YAMLCPP_LIBRARY_DIR}) -ENDIF(YAMLCPP_FOUND) +IF (YAMLCPP_FOUND) + TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${YAMLCPP_LIBRARY}) +ENDIF (YAMLCPP_FOUND) # install INSTALL(TARGETS ${PROJECT_NAME} @@ -58,6 +88,9 @@ INSTALL(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib/${PROJECT_NAME}) INSTALL(FILES ${headers} DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ../cmake_modules/Find${PROJECT_NAME}.cmake DESTINATION ${CMAKE_ROOT}/Modules/) +INSTALL(FILES "${VU_CONFIG_DIR}/config.h" DESTINATION include/${PROJECT_NAME}/internal) # examples of usage ADD_SUBDIRECTORY(examples) + + diff --git a/src/cam_utils/cam_utils.cpp b/src/cam_utils/cam_utils.cpp deleted file mode 100644 index 41985eb7b8ba2989f36d92b2d9ac1514deb1583f..0000000000000000000000000000000000000000 --- a/src/cam_utils/cam_utils.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "cam_utils.h" - -CamUtils::CamUtils() -{ -} - -CamUtils::~CamUtils() -{ -} - -bool CamUtils::openCamera(const int& _cam_num, cv::VideoCapture& _cam) -{ - cv::VideoCapture camera(_cam_num); - if (!camera.isOpened()) // check if we succeeded - { - std::cerr << "ERROR: Could not open camera: " << _cam_num << std::endl; - return false; - } - _cam = camera; - return true; -} - -bool CamUtils::getFrame(cv::VideoCapture& _cam, cv::Mat& _frame) -{ - try - { - _cam >> _frame; - } - catch (cv::Exception& e) - { - std::cout << "An exception occurred. Ignoring frame. " << e.err << std::endl; - return false; - } - return true; -} - -bool CamUtils::showFrame(const std::string& _window_name, const cv::Mat& _frame) -{ - try - { - cv::imshow(_window_name, _frame); - } - catch (cv::Exception& e) - { - std::cout << "An exception occurred. Ignoring frame. " << e.err << std::endl; - return false; - } - return true; -} diff --git a/src/cam_utils/cam_utils.h b/src/cam_utils/cam_utils.h deleted file mode 100644 index 567f212e2c225b43f3650e55d79af55e3689beba..0000000000000000000000000000000000000000 --- a/src/cam_utils/cam_utils.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _CAMUTILS_H -#define _CAMUTILS_H - -// std stuff -#include <stdio.h> -#include <iostream> - -// OpenCV stuff -#include "opencv2/opencv.hpp" - -class CamUtils -{ - public: - - /** - * \brief Constructor - * - * Main class constructor. - */ - CamUtils(); - - /** - * \brief Destructor - * - * Main class destructor. - */ - ~CamUtils(); - - /** - * \brief Open Webcam - * - * This method opens the specified webcam using OpenCV - * Inputs: - * _cam_num: system camera number (int) - * Ouptuts: - * cam: camera handle (cv::VideoCapture) - * - * Returns true if the camera is correctly opened - * - */ - bool openCamera(const int& _cam_num, cv::VideoCapture& _cam); - - /** - * \brief Get frame - * - * This method gets a frame from the specified webcam - * - * Inputs: - * cam: camera handle (cv::VideoCapture) - * Outputs: - * frame: filled frame (cv::Mat) - * Returns true if the frame is correctly obtained - */ - bool getFrame(cv::VideoCapture& _cam, cv::Mat& _frame); - - /** - *\brief Show Frame - * - * This method shows the specified frame using OpenCV - * - * Inputs: - * window_name: Window name inwhich the frame will be displayed (string) - * frame: Frame to be displayed (cv::Mat) - * Returns true if the frame is correctly displayed - */ - bool showFrame(const std::string& _window_name, const cv::Mat& _frame); -}; - -#endif diff --git a/src/detectors/detector_base.cpp b/src/detectors/detector_base.cpp index d7eb6e9952fe38ca973d38c00754fa580463a8da..dc39c16f84be24fd13aea8c2393e2dc53a07b782 100644 --- a/src/detectors/detector_base.cpp +++ b/src/detectors/detector_base.cpp @@ -10,4 +10,4 @@ DetectorBase::~DetectorBase(void) { } -} // namespace wolf +} // namespace vision_utils diff --git a/src/detectors/detector_base.h b/src/detectors/detector_base.h index c533b9681885c46cce611d0c46350299474e20a1..b88e9b8b7f6f4a537d9f41c8c1b9c5032d31dbf9 100644 --- a/src/detectors/detector_base.h +++ b/src/detectors/detector_base.h @@ -4,6 +4,8 @@ // vision_utils #include "../vision_utils.h" +typedef cv::Ptr<cv::FeatureDetector> FeatureDetectorPtr; + namespace vision_utils { @@ -38,9 +40,6 @@ class DetectorBase : public VUBase, public std::enable_shared_from_this<Detector * \brief Virtual destructor */ virtual ~DetectorBase(void); - - virtual void detect(const cv::Mat& _image) = 0; - virtual void detect(const cv::Mat& _image, const cv::Mat& _mask) = 0; }; } /* namespace vision_utils */ diff --git a/src/detectors/detector_orb.cpp b/src/detectors/detector_orb.cpp deleted file mode 100644 index 6ca7f46b82302d7ac3393b9c2462163a80eb0ef6..0000000000000000000000000000000000000000 --- a/src/detectors/detector_orb.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "detector_orb.h" - -namespace vision_utils { - -DetectorORB::DetectorORB(void) -{} - -DetectorORB::~DetectorORB(void) -{} - -void DetectorORB::detect(const cv::Mat& _image) -{ - std::cout << "[" << name_ << "] Detecting without mask" << std::endl; -} -void DetectorORB::detect(const cv::Mat& _image, const cv::Mat& _mask) -{ - std::cout << "[" << name_ << "] Detecting with mask" << std::endl; -} - -} /* namespace vision_utils */ - -// Register in the DetectorsFactory -#include "detector_factory.h" - -namespace vision_utils -{ -// TODO: How can I pass parameters then? -DetectorORBPtr setup(const std::string& _type, const std::string& _unique_name, const DetectorParamsBasePtr& _params) -{ - DetectorBasePtr det_ptr = DetectorFactory::get().create(_type, _unique_name, _params); - DetectorORBPtr DetORB_ptr = std::static_pointer_cast<DetectorORB>(det_ptr); - return DetORB_ptr; -}; - -VU_REGISTER_DETECTOR("ORB", DetectorORB); - -} /* namespace vision_utils */ diff --git a/src/detectors/detector_orb.h b/src/detectors/detector_orb.h deleted file mode 100644 index ed57f8858f59c9583cbcf8c0b85c37d6e16f31c0..0000000000000000000000000000000000000000 --- a/src/detectors/detector_orb.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _DETECTOR_ORB_H_ -#define _DETECTOR_ORB_H_ - -#include "detector_base.h" - -namespace vision_utils { - -// Create all pointers -VU_PTR_TYPEDEFS(DetectorORB); - -//class -class DetectorORB : public DetectorBase { - - public: - DetectorORB(); - virtual ~DetectorORB(void); - - void detect(const cv::Mat& _image); - void detect(const cv::Mat& _image, const cv::Mat& _mask); - - std::string getName(void); - - // Factory method - static DetectorBasePtr create(const std::string& _unique_name, const DetectorParamsBasePtr _params); - - private: - - std::string name_; - - void setName(const std::string& _name); -}; - -/* - * brief Retrieve object name - */ -inline std::string DetectorORB::getName(void) { return name_; } - -/* - * brief Set object name - */ -inline void DetectorORB::setName(const std::string& _name){ name_ = _name; } - -/* - * brief Create object in factory - */ -inline DetectorBasePtr DetectorORB::create(const std::string& _unique_name, const DetectorParamsBasePtr _params) -{ - DetectorORBPtr det_ptr = std::make_shared<DetectorORB>(); - det_ptr->setName(_unique_name); - return det_ptr; -} - -/* - * brief Setup and get the corresponding pointer - */ -DetectorORBPtr setup(const std::string& _type, const std::string& _unique_name, const DetectorParamsBasePtr& _params); - -} /* namespace vision_utils */ - -#endif diff --git a/src/detectors/orb/detector_orb.cpp b/src/detectors/orb/detector_orb.cpp new file mode 100644 index 0000000000000000000000000000000000000000..918794cdaf82ebda6e284104d0fa01fffb0065ab --- /dev/null +++ b/src/detectors/orb/detector_orb.cpp @@ -0,0 +1,83 @@ +#include "detector_orb.h" + +namespace vision_utils { + +DetectorORB::DetectorORB(void): + is_line_det_(false) +{} + +DetectorORB::~DetectorORB(void) +{} + +KeyPointVector DetectorORB::detect(const cv::Mat& _image) +{ + cv::Mat mask = cv::Mat::ones(_image.size(), CV_8U); + return detect(_image, mask); +} +KeyPointVector DetectorORB::detect(const cv::Mat& _image, const cv::Mat& _mask) +{ + KeyPointVector kpts; + clock_t tStart = clock(); + detector_->detect(_image, kpts, _mask); + comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; + + return kpts; +} + +} /* namespace vision_utils */ + +// Register in the DetectorsFactory +#include "../detector_factory.h" + +namespace vision_utils +{ + +DetectorBasePtr setupDetector(const std::string& _type, const std::string& _unique_name, const DetectorParamsBasePtr& _params) +{ + DetectorBasePtr det_ptr = DetectorFactory::get().create(_type, _unique_name, _params); + std::cout << "[" << _unique_name << "] setup done." << std::endl; + return det_ptr; +}; + +#ifdef USING_YAML + +DetectorBasePtr setupDetector(const std::string& _type, const std::string& _unique_name, const std::string& _filename_dot_yaml) +{ + DetectorParamsBasePtr params = loadYAMLDetectorParams(_filename_dot_yaml); + return setupDetector(_type, _unique_name, params); +} + +DetectorParamsBasePtr loadYAMLDetectorParams(const std::string& _filename_dot_yaml) +{ + DetectorParamsORBPtr params_ptr = std::make_shared<DetectorParamsORB>(); + + using std::string; + using YAML::Node; + Node yaml_params = YAML::LoadFile(_filename_dot_yaml); + if (!yaml_params.IsNull()) + { + Node d_yaml = yaml_params["detector"]; + if(d_yaml["type"].as<string>() == "ORB") + { + params_ptr->nfeatures = d_yaml["nfeatures"].as<unsigned int>(); + params_ptr->scaleFactor = d_yaml["scale factor"].as<float>(); + params_ptr->nlevels = d_yaml["nlevels"].as<unsigned int>(); + params_ptr->edgeThreshold = d_yaml["edge threshold"].as<unsigned int>(); + params_ptr->firstLevel = d_yaml["first level"].as<unsigned int>(); + params_ptr->WTA_K = d_yaml["WTA_K"].as<unsigned int>(); + params_ptr->scoreType = d_yaml["score type"].as<int>(); // enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; + params_ptr->patchSize = d_yaml["patch size"].as<unsigned int>(); + }else + { + std::cerr << "Wrong type " << d_yaml["type"].as<string>() << std::endl; + } + } + + return params_ptr; +} + +#endif + +VU_REGISTER_DETECTOR("ORB", DetectorORB); + +} /* namespace vision_utils */ diff --git a/src/detectors/orb/detector_orb.h b/src/detectors/orb/detector_orb.h new file mode 100644 index 0000000000000000000000000000000000000000..67c10306e718e8f6a5ccfd9a128f25ca9ddf81cf --- /dev/null +++ b/src/detectors/orb/detector_orb.h @@ -0,0 +1,117 @@ +#ifndef _DETECTOR_ORB_H_ +#define _DETECTOR_ORB_H_ + +#include "../detector_base.h" + +// yaml-cpp library +#ifdef USING_YAML + #include <yaml-cpp/yaml.h> +#endif + +namespace vision_utils { + +// Create all pointers +VU_PTR_TYPEDEFS(DetectorORB); +VU_PTR_TYPEDEFS(DetectorParamsORB); + +/** \brief Class parameters + * + */ +struct DetectorParamsORB: public DetectorParamsBase +{ + int nfeatures = 500; + float scaleFactor = 1.2f; + int nlevels = 8; + int edgeThreshold = 31; + int firstLevel = 0; + int WTA_K = 2; + int scoreType = cv::ORB::HARRIS_SCORE; + int patchSize = 31; +}; + +/** \brief ORB DETECTOR class + * + */ +class DetectorORB : public DetectorBase { + + public: + DetectorORB(); + virtual ~DetectorORB(void); + + std::string getName(void); + + bool isLineDetector(void); + + KeyPointVector detect(const cv::Mat& _image); + KeyPointVector detect(const cv::Mat& _image, const cv::Mat& _mask); + + // Factory method + static DetectorBasePtr create(const std::string& _unique_name, const DetectorParamsBasePtr _params); + + private: + + std::string name_; + + FeatureDetectorPtr detector_; + + bool is_line_det_; + + void setName(const std::string& _name); + void setParams(const DetectorParamsORBPtr _params); +}; + +/* + * brief Retrieve object name + */ +inline std::string DetectorORB::getName(void) { return name_; } + +/* + * brief Set object name + */ +inline void DetectorORB::setName(const std::string& _name){ name_ = _name; } + +/* + * brief Returns if this is a line detector + */ +inline bool DetectorORB::isLineDetector(void){ return is_line_det_; } + +/* + * brief Set object name + */ +inline void DetectorORB::setParams(const DetectorParamsORBPtr _params) +{ + detector_ = cv::ORB::create(_params->nfeatures, + _params->scaleFactor, + _params->nlevels, + _params->edgeThreshold, + _params->firstLevel, + _params->WTA_K, + _params->scoreType, + _params->patchSize); +} + + +/* + * brief Create object in factory + */ +inline DetectorBasePtr DetectorORB::create(const std::string& _unique_name, const DetectorParamsBasePtr _params) +{ + DetectorORBPtr det_ptr = std::make_shared<DetectorORB>(); + DetectorParamsORBPtr det_params_ptr = std::static_pointer_cast<DetectorParamsORB>(_params); + det_ptr->setName(_unique_name); + det_ptr->setParams(det_params_ptr); + return det_ptr; +} + +/* + * brief Setup and get the corresponding pointer + */ +DetectorBasePtr setupDetector(const std::string& _type, const std::string& _unique_name, const DetectorParamsBasePtr& _params); +#ifdef USING_YAML +DetectorBasePtr setupDetector(const std::string& _type, const std::string& _unique_name, const std::string& _filename_dot_yaml); +DetectorParamsBasePtr loadYAMLDetectorParams(const std::string& _filename_dot_yaml); +#endif + +} /* namespace vision_utils */ + +#endif /* _DETECTOR_ORB_H_ */ diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 1d38d15a386af64d3d43237d779c3d125da8b3b7..5028d712de83a311e33b63144b39570c32cc3b51 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -1,15 +1,15 @@ # create an example application -#ADD_EXECUTABLE(capture capture.cpp) -#ADD_EXECUTABLE(feature_detectors feature_detect.cpp) #ADD_EXECUTABLE(feature_detectors_and_descriptors feature_detect_descript.cpp) #ADD_EXECUTABLE(feature_detectors_descriptors_and_matchers feature_detect_descript_match.cpp) ADD_EXECUTABLE(test_factories test_factories.cpp ) +ADD_EXECUTABLE(test_sensor test_sensor.cpp) +ADD_EXECUTABLE(test_detector test_detector.cpp) # link necessary libraries -#TARGET_LINK_LIBRARIES(capture vision_utils) -#TARGET_LINK_LIBRARIES(feature_detectors vision_utils) #TARGET_LINK_LIBRARIES(feature_detectors_and_descriptors vision_utils) #TARGET_LINK_LIBRARIES(feature_detectors_descriptors_and_matchers vision_utils) -TARGET_LINK_LIBRARIES(test_factories ${PROJECT_NAME}) \ No newline at end of file +TARGET_LINK_LIBRARIES(test_factories ${PROJECT_NAME}) +TARGET_LINK_LIBRARIES(test_sensor vision_utils) +TARGET_LINK_LIBRARIES(test_detector vision_utils) \ No newline at end of file diff --git a/src/examples/capture.cpp b/src/examples/capture.cpp deleted file mode 100644 index 9d6d4c4c4ca0405f5e7f41d866d6d9c88dedf481..0000000000000000000000000000000000000000 --- a/src/examples/capture.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// OWN stuff -#include <string> - -#include "../vision_utils.h" - -int main(int argc, char *argv[]) -{ - // Open camera - cv::VideoCapture cam; - CamUtils cam_fc; - cam_fc.openCamera(0, cam); - - cv::startWindowThread(); - cv::namedWindow("Cam Test", 1); - - for (;;) - { - // Get frame - cv::Mat frame; - cam_fc.getFrame(cam, frame); - - // Show frame - cv::imshow("Cam Test", frame); - cv::waitKey(1); - //if (cv::waitKey(30) >= 0) break; - } - - cv::destroyAllWindows(); -} diff --git a/src/examples/test_detector.cpp b/src/examples/test_detector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2cd0b998abbcdc3f437b9a8d2b8c1a40ad9ee0fd --- /dev/null +++ b/src/examples/test_detector.cpp @@ -0,0 +1,77 @@ +#include <iostream> +#include <iomanip> +#include <cstdlib> + +#include "../vision_utils.h" + +// Sensors +#include "../sensors/camera/sensor_camera.h" + +// Detectors +#include "../detectors/orb/detector_orb.h" + +int main(void) +{ + using namespace vision_utils; + using std::shared_ptr; + using std::make_shared; + using std::static_pointer_cast; + + // Root dir path + std::string vu_root = _VU_ROOT_DIR; + + // Setup camera sensor by default + + SensorBasePtr sen_b_ptr = setupSensor("CAMERA", "CAMERA_test", vu_root + "/src/examples/yaml/sensor_camera.yaml"); + SensorCameraPtr sen_ptr = std::static_pointer_cast<SensorCamera>(sen_b_ptr); + + std::cout << "\n================ DETECTOR TEST =================" << std::endl; + + std::cout << std::endl << "Which DETECTOR do you want to test? Type one of the registered names [default: ORB]"; + + std::string def_detector = "ORB"; + std::string det_name = readFromUser(def_detector); + + DetectorBasePtr det_b_ptr = setupDetector(def_detector, def_detector + "_test", vu_root + "/src/examples/yaml/detector_orb.yaml"); + DetectorORBPtr det_ptr = std::static_pointer_cast<DetectorORB>(det_b_ptr); + + + // Open camera + sen_ptr->open(0); + + cv::startWindowThread(); + cv::namedWindow(sen_ptr->getName(), 1); + cv::namedWindow(det_ptr->getName(), cv::WINDOW_NORMAL); + + for (int nframe = 0; nframe < 1000; ++nframe) + { + // Get frame + cv::Mat frame; + sen_ptr->getFrame(frame); + + // Show ORIGINAL frame + cv::imshow(sen_ptr->getName(), frame); + + if (!det_ptr->isLineDetector()) + { + KeyPointVector keypoints; + keypoints = det_ptr->detect(frame); + drawKeyPoints(frame, keypoints); + } +// TODO: Draw lines with the same API as points +// else +// { +// KeyLineVector keylines; +// keylines = det_ptr->detect(frame); +// drawKeyLines(frame, keylines); +// } + + std::cout << "\e[A" << "Detection time: " << det_ptr->getTime() << std::endl; + + // Show frame + cv::imshow(det_ptr->getName(), frame); + cv::waitKey(1); + } + + cv::destroyAllWindows(); +} diff --git a/src/examples/test_factories.cpp b/src/examples/test_factories.cpp index 50ed2bddae040dc6cc2754425b298c2d5510ee60..d58e5e2d5693434f3c76fc3dded380b4a65518d6 100644 --- a/src/examples/test_factories.cpp +++ b/src/examples/test_factories.cpp @@ -2,7 +2,11 @@ #include <iomanip> #include <cstdlib> -#include <detectors/detector_orb.h> +// Sensors +#include "../sensors/camera/sensor_camera.h" + +// Detectors +#include "../detectors/orb/detector_orb.h" int main(void) { @@ -11,25 +15,30 @@ int main(void) using std::make_shared; using std::static_pointer_cast; + // Root dir path + std::string vu_root = _VU_ROOT_DIR; + std::cout << "\n====== Registering creators in the Factories =======" << std::endl; std::cout << "If you look above, you see the registered creators.\n" "There is only one attempt per class, and it is successful!\n" "We do this by registering in the class\'s .cpp file.\n"; - std::cout << "\n================ Detector Factory =================" << std::endl; + std::cout << "\n================= Sensor Factory ==================" << std::endl; - // TODO: Parameters as YAML file - DetectorParamsBasePtr orb_params; - DetectorORBPtr DetORBptr = setup("ORB", "ORB detector", orb_params); + SensorBasePtr sen_b_ptr = setupSensor("CAMERA", "CAMERA sensor", vu_root + "/src/examples/yaml/sensor_camera.yaml"); + SensorCameraPtr sen_cam_ptr = std::static_pointer_cast<SensorCamera>(sen_b_ptr); + + std::cout << "\n================ Detector Factory =================" << std::endl; - std::cout << "[" << DetORBptr->getName() << "] setup successfully." << std::endl; + DetectorBasePtr det_b_ptr = setupDetector("ORB", "ORB detector", vu_root + "/src/examples/yaml/detector_orb.yaml"); + DetectorORBPtr det_orb_ptr = std::static_pointer_cast<DetectorORB>(det_b_ptr); std::cout << "\n================= Running Example ================" << std::endl; std::cout << std::endl; - cv::Mat image = cv::Mat(640,480,CV_32F); - DetORBptr->detect(image); + cv::Mat image = cv::Mat(640,480, CV_8UC3, cv::Scalar(0, 0, 0)); + KeyPointVector kpts = det_orb_ptr->detect(image); std::cout << std::endl; return 0; diff --git a/src/examples/test_sensor.cpp b/src/examples/test_sensor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d2729f137fa3038cfe450d54af55dad4ff1d3f4 --- /dev/null +++ b/src/examples/test_sensor.cpp @@ -0,0 +1,46 @@ +#include <iostream> +#include <iomanip> +#include <cstdlib> + +// Sensors +#include "../sensors/camera/sensor_camera.h" + +int main(void) +{ + using namespace vision_utils; + using std::shared_ptr; + using std::make_shared; + using std::static_pointer_cast; + + // Root dir path + std::string vu_root = _VU_ROOT_DIR; + + std::cout << "\n================ SENSOR TEST =================" << std::endl; + + std::cout << std::endl << "Which SENSOR do you want to test? Type one of the registered names [default: CAMERA]"; + + std::string def_sensor = "CAMERA"; + std::string sen_name = readFromUser(def_sensor); + + SensorBasePtr sen_b_ptr = setupSensor(sen_name, sen_name + "_test", vu_root + "/src/examples/yaml/sensor_camera.yaml"); + SensorCameraPtr sen_cam_ptr = std::static_pointer_cast<SensorCamera>(sen_b_ptr); + + // Open camera + sen_cam_ptr->open(0); + + cv::startWindowThread(); + cv::namedWindow(sen_cam_ptr->getName(), 1); + + for (int nframe = 0; nframe < 1000; ++nframe) + { + // Get frame + cv::Mat frame; + sen_cam_ptr->getFrame(frame); + + // Show frame + cv::imshow(sen_cam_ptr->getName(), frame); + cv::waitKey(1); + } + + cv::destroyAllWindows(); +} diff --git a/src/examples/yaml/detector_orb.yaml b/src/examples/yaml/detector_orb.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a442d98534d6615c2f4d0e5a609b2bf7941ed0b2 --- /dev/null +++ b/src/examples/yaml/detector_orb.yaml @@ -0,0 +1,11 @@ +detector: + type: "ORB" + nfeatures: 100 + scale factor: 1.2 + nlevels: 8 + edge threshold: 8 # 16 + first level: 0 + WTA_K: 2 # See: http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html#a180ae17d3300cf2c619aa240d9b607e5 + score type: 1 #enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; + patch size: 15 # 31 + diff --git a/src/examples/yaml/detector_orb.yaml~ b/src/examples/yaml/detector_orb.yaml~ new file mode 100644 index 0000000000000000000000000000000000000000..b87079480832711898bfa23535d9cef09344161d --- /dev/null +++ b/src/examples/yaml/detector_orb.yaml~ @@ -0,0 +1,11 @@ +detector: + type: "ORB" + nfeatures: 100 + scale factor: 1.2 + nlevels: 8 + edge threshold: 8 # 16 + first level: 0 + WTA_K: 2 # See: http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html#a180ae17d3300cf2c619aa240d9b607e5 + score type: 1 #enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; + patch size: 15 # 31 + diff --git a/src/examples/yaml/sensor_camera.yaml b/src/examples/yaml/sensor_camera.yaml new file mode 100644 index 0000000000000000000000000000000000000000..628b27400f04d81781fce718dce5ff4a7673095e --- /dev/null +++ b/src/examples/yaml/sensor_camera.yaml @@ -0,0 +1,2 @@ +sensor: + type: "CAMERA" diff --git a/src/examples/yaml/sensor_camera.yaml~ b/src/examples/yaml/sensor_camera.yaml~ new file mode 100644 index 0000000000000000000000000000000000000000..a077628744dcfa5a6f77b00c95cd3faab05d4cce --- /dev/null +++ b/src/examples/yaml/sensor_camera.yaml~ @@ -0,0 +1 @@ +sensor type: "CAMERA" diff --git a/src/factory.h b/src/factory.h index 77195ac4203ec4ffaf2c573da563257be4d5539d..91ff917f63e31f469939c2957bd98a7165250575 100644 --- a/src/factory.h +++ b/src/factory.h @@ -7,11 +7,6 @@ #include <iostream> #include <iomanip> -// yaml -#ifdef USING_YAML -#include <yaml-cpp/yaml.h> -#endif - namespace vision_utils { diff --git a/src/internal/config.h.in b/src/internal/config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..1d5c2a8bbaeb5ee6e6dfe9f26b03013b8bbbeb41 --- /dev/null +++ b/src/internal/config.h.in @@ -0,0 +1,6 @@ +#ifndef VU_INTERNAL_CONFIG_H_ +#define VU_INTERNAL_CONFIG_H_ + +#define _VU_ROOT_DIR "${_VU_ROOT_DIR}" + +#endif /* VU_INTERNAL_CONFIG_H_ */ diff --git a/src/sensors/camera/sensor_camera.cpp b/src/sensors/camera/sensor_camera.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7293c5b10d3a71ca613e515b0388063f54a5f729 --- /dev/null +++ b/src/sensors/camera/sensor_camera.cpp @@ -0,0 +1,67 @@ +#include "sensor_camera.h" + +namespace vision_utils { + +SensorCamera::SensorCamera(void) +{} + +SensorCamera::~SensorCamera(void) +{} + +} /* namespace vision_utils */ + +// Register in the DetectorsFactory +#include "../sensor_factory.h" + +namespace vision_utils +{ + +SensorBasePtr setupSensor(const std::string& _type, const std::string& _unique_name, const IntrinsicsBasePtr& _intrinsics) +{ + SensorBasePtr set_ptr = SensorFactory::get().create(_type, _unique_name, _intrinsics); + std::cout << "[" << _unique_name << "] setup done." << std::endl; + return set_ptr; +}; + +#ifdef USING_YAML + +SensorBasePtr setupSensor(const std::string& _type, const std::string& _unique_name, const std::string& _filename_dot_yaml) +{ + IntrinsicsBasePtr params = loadYAMLSensorParams(_filename_dot_yaml); + return setupSensor(_type, _unique_name, params); +} + +IntrinsicsBasePtr loadYAMLSensorParams(const std::string& _filename_dot_yaml) +{ + IntrinsicsCameraPtr params_ptr = std::make_shared<IntrinsicsCamera>(); + + using std::string; + using YAML::Node; + Node yaml_params = YAML::LoadFile(_filename_dot_yaml); + if (!yaml_params.IsNull()) + { + Node d_yaml = yaml_params["sensor"]; + if(d_yaml["type"].as<string>() == "CAMERA") + { +// params_ptr->nfeatures = d_yaml["nfeatures"].as<unsigned int>(); +// params_ptr->scaleFactor = d_yaml["scale factor"].as<float>(); +// params_ptr->nlevels = d_yaml["nlevels"].as<unsigned int>(); +// params_ptr->edgeThreshold = d_yaml["edge threshold"].as<unsigned int>(); +// params_ptr->firstLevel = d_yaml["first level"].as<unsigned int>(); +// params_ptr->WTA_K = d_yaml["WTA_K"].as<unsigned int>(); +// params_ptr->scoreType = d_yaml["score type"].as<int>(); // enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; +// params_ptr->patchSize = d_yaml["patch size"].as<unsigned int>(); + }else + { + std::cerr << "Wrong type " << d_yaml["type"].as<string>() << std::endl; + } + } + + return params_ptr; +} + +#endif + +VU_REGISTER_SENSOR("CAMERA", SensorCamera); + +} /* namespace vision_utils */ diff --git a/src/sensors/camera/sensor_camera.h b/src/sensors/camera/sensor_camera.h new file mode 100644 index 0000000000000000000000000000000000000000..c70122e61520ba7f884457e6f995f125c137bbe6 --- /dev/null +++ b/src/sensors/camera/sensor_camera.h @@ -0,0 +1,176 @@ +#ifndef _SENSOR_CAMERA_H_ +#define _SENSOR_CAMERA_H_ + +#include "../sensor_base.h" + +// yaml-cpp library +#ifdef USING_YAML + #include <yaml-cpp/yaml.h> +#endif + +namespace vision_utils { + +// Create all pointers +VU_PTR_TYPEDEFS(SensorCamera); +VU_PTR_TYPEDEFS(IntrinsicsCamera); + +/** \brief class parameters + * + */ +struct IntrinsicsCamera: public IntrinsicsBase +{ + // TODO: Set parameters with eigen? +// int nfeatures = 500; +// float scaleFactor = 1.2f; +// int nlevels = 8; +// int edgeThreshold = 31; +// int firstLevel = 0; +// int WTA_K = 2; +// int scoreType = cv::ORB::HARRIS_SCORE; +// int patchSize = 31; +}; + +/** \brief ORB DETECTOR class + * + */ +class SensorCamera : public SensorBase { + + public: + + SensorCamera(); + virtual ~SensorCamera(void); + + std::string getName(void); + + /** + * \brief Open Webcam + * + * This method opens the specified webcam using OpenCV + * Inputs: + * _cam_num: system camera number (int) + * _ cam: camera handle (cv::VideoCapture) + * Returns true if the camera is correctly opened + * + */ + bool open(const int& _cam_num); + + /** + * \brief Get frame + * + * This method gets a frame from the specified webcam + * Inputs: + * _cam: camera handle (cv::VideoCapture) + * _frame: filled frame (cv::Mat) + * Returns true if the frame is correctly obtained + */ + bool getFrame(cv::Mat& _frame); + + /** + *\brief Show Frame + * + * This method shows the specified frame using OpenCV + * Inputs: + * _window_name: Window name inwhich the frame will be displayed (string) + * _frame: Frame to be displayed (cv::Mat) + * Returns true if the frame is correctly displayed + */ + bool showFrame(const std::string& _window_name, const cv::Mat& _frame); + + // Factory method + static SensorBasePtr create(const std::string& _unique_name, const IntrinsicsBasePtr _intrinsics); + + private: + + std::string name_; + cv::VideoCapture vidcapture_; + + void setName(const std::string& _name); + void setParams(const IntrinsicsCameraPtr _params); +}; + +/* + * brief Retrieve object name + */ +inline std::string SensorCamera::getName(void) { return name_; } + +/* + * brief Set object name + */ +inline void SensorCamera::setName(const std::string& _name){ name_ = _name; } + +/* + * brief Set object name + */ +inline void SensorCamera::setParams(const IntrinsicsCameraPtr _params) +{ + // TODO: depending on intrinsics structure +// detector_ = cv::ORB::create(_params->nfeatures, +// _params->scaleFactor, +// _params->nlevels, +// _params->edgeThreshold, +// _params->firstLevel, +// _params->WTA_K, +// _params->scoreType, +// _params->patchSize); +// +// std::cout << "COMMON: " << _params->nfeatures << std::endl; +} + +inline bool SensorCamera::open(const int& _cam_num) +{ + cv::VideoCapture camera(_cam_num); + if (!camera.isOpened()) // check if we succeeded + { + std::cerr << "[" << getName() << "]: ERROR opening camera " << _cam_num << std::endl; + return false; + } + vidcapture_ = camera; + return true; +} + +inline bool SensorCamera::getFrame(cv::Mat& _frame) +{ + try { vidcapture_ >> _frame; } + catch (cv::Exception& e) + { + std::cout << "[" << getName() << "]: An exception occurred. Ignoring frame. " << e.err << std::endl; + return false; + } + return true; +} + +inline bool SensorCamera::showFrame(const std::string& _window_name, const cv::Mat& _frame) +{ + try { cv::imshow(_window_name, _frame); } + catch (cv::Exception& e) + { + std::cout << "[" << getName() << "]: An exception occurred. Dropping frame. " << e.err << std::endl; + return false; + } + return true; +} + +/* + * brief Create object in factory + */ +inline SensorBasePtr SensorCamera::create(const std::string& _unique_name, const IntrinsicsBasePtr _intrinsics) +{ + SensorCameraPtr sen_ptr = std::make_shared<SensorCamera>(); + IntrinsicsCameraPtr sen_params_ptr = std::static_pointer_cast<IntrinsicsCamera>(_intrinsics); + sen_ptr->setName(_unique_name); + sen_ptr->setParams(sen_params_ptr); + return sen_ptr; +} + +/* + * brief Setup and get the corresponding pointer + */ +SensorBasePtr setupSensor(const std::string& _type, const std::string& _unique_name, const IntrinsicsBasePtr& _intrinsics); +#ifdef USING_YAML +SensorBasePtr setupSensor(const std::string& _type, const std::string& _unique_name, const std::string& _filename_dot_yaml); +IntrinsicsBasePtr loadYAMLSensorParams(const std::string& _filename_dot_yaml); +#endif + +} /* namespace vision_utils */ + +#endif /* _SENSOR_CAMERA_H_ */ diff --git a/src/sensors/sensor_base.cpp b/src/sensors/sensor_base.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ee22f814627d483a8eeabcaa1b6df6c5fae38add --- /dev/null +++ b/src/sensors/sensor_base.cpp @@ -0,0 +1,13 @@ +#include "sensor_base.h" + +namespace vision_utils { + +SensorBase::SensorBase(void) +{ +} + +SensorBase::~SensorBase(void) +{ +} + +} // namespace vision_utils diff --git a/src/sensors/sensor_base.h b/src/sensors/sensor_base.h new file mode 100644 index 0000000000000000000000000000000000000000..39706ece4b2386651954e4364a560d90e926fb73 --- /dev/null +++ b/src/sensors/sensor_base.h @@ -0,0 +1,45 @@ +#ifndef _SENSOR_BASE_H_ +#define _SENSOR_BASE_H_ + +// vision_utils +#include "../vision_utils.h" + +namespace vision_utils +{ + +///////////////////////////////////////////////////////////////////////// +// CLASS DEFINITIONS +///////////////////////////////////////////////////////////////////////// + +// Create all pointers +VU_PTR_TYPEDEFS(SensorBase); +VU_PTR_TYPEDEFS(IntrinsicsBase); + +/** \brief base class for DETECTOR parameters + * + * Derive from this class to create DETECTOR class parameters. + */ +struct IntrinsicsBase: public ParamsBase {}; + +/** \brief base class for DETECTOR base + * + * Derive from this class to create DETECTOR base class parameters. + */ +class SensorBase : public VUBase, public std::enable_shared_from_this<SensorBase> +{ + public: + + /** + * \brief Constructor without parameters + */ + SensorBase(void); + + /** + * \brief Virtual destructor + */ + virtual ~SensorBase(void); +}; + +} /* namespace vision_utils */ + +#endif /* _SENSOR_BASE_H_ */ diff --git a/src/sensors/sensor_factory.h b/src/sensors/sensor_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..933f16e838111741872da03b77d67a4106e833e3 --- /dev/null +++ b/src/sensors/sensor_factory.h @@ -0,0 +1,32 @@ +#ifndef _SENSOR_FACTORY_H_ +#define _SENSOR_FACTORY_H_ + +namespace vision_utils +{ +class SensorBase; +struct SensorParamsBase; +} + +#include "../factory.h" + +namespace vision_utils +{ + +/* Sensor Factory */ +typedef Factory<SensorBase, + const std::string&, + const IntrinsicsBasePtr> SensorFactory; + +template<> +inline std::string SensorFactory::getClass() +{ + return "SensorFactory"; +} + +#define VU_REGISTER_SENSOR(SensorType, SensorName) \ + namespace{ const bool SensorName##Registered = \ + SensorFactory::get().registerCreator(SensorType, SensorName::create); }\ + +} /* namespace vision_utils */ + +#endif /* SENSOR_FACTORY_H_ */ diff --git a/src/vision_utils.cpp b/src/vision_utils.cpp index b710643faf1661cbee32da585c46539b7ef3c814..78ddd9fff2a236e87a9ed13ae29908062b8172b0 100644 --- a/src/vision_utils.cpp +++ b/src/vision_utils.cpp @@ -3,36 +3,4 @@ namespace vision_utils { -///////////////////////////////////////////////////////////////////////// -// USEFUL FUNCTIONS -///////////////////////////////////////////////////////////////////////// - - -bool LessPoints(const cv::Point2f& lhs, const cv::Point2f& rhs) -{ - return (lhs.x < rhs.x) || ((lhs.x == rhs.x) && (lhs.y < rhs.y)); -} - -std::vector<cv::Point2f> vecIntersec(std::vector<cv::Point2f> v1, std::vector<cv::Point2f> v2) -{ - std::vector<cv::Point2f> v3; - // Sort vectors - std::sort(v1.begin(), v1.end(), LessPoints); - std::sort(v2.begin(), v2.end(), LessPoints); - // Intersect - std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), std::back_inserter(v3), LessPoints); - return v3; -} - -std::vector<cv::Point2f> vecUnion(std::vector<cv::Point2f> v1, std::vector<cv::Point2f> v2) -{ - std::vector<cv::Point2f> v3; - // Sort vectors - std::sort(v1.begin(), v1.end(), LessPoints); - std::sort(v2.begin(), v2.end(), LessPoints); - // Intersect - std::set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), std::back_inserter(v3), LessPoints); - return v3; -} - } /* namespace vision_utils */ diff --git a/src/vision_utils.h b/src/vision_utils.h index ea537d915e79773f46ecd257dd515622dcaaf59a..85dcdafae1a24c33cd6dc40c74522f97405e0da9 100644 --- a/src/vision_utils.h +++ b/src/vision_utils.h @@ -1,6 +1,8 @@ #ifndef _VU_UTILS_H #define _VU_UTILS_H +#include "internal/config.h" + // std #include <functional> #include <set> @@ -26,7 +28,6 @@ using namespace boost::assign; // bring 'operator+=()' into scope #include <opencv2/xfeatures2d.hpp> #include <opencv2/line_descriptor/descriptor.hpp> -typedef std::vector<cv::KeyPoint> KeyPointVector; typedef std::vector<cv::KeyPoint> KeyPointVector; typedef std::vector<cv::line_descriptor::KeyLine> KeyLineVector; @@ -109,9 +110,9 @@ VU_PTR_TYPEDEFS(VUBase); ///////////////////////////////////////////////////////////////////////// template <typename T> -T readFromUser(const T& def_num) +T readFromUser(const T& _default) { - T read = def_num; + T read = _default; std::string input; std::getline( std::cin, input ); if ( !input.empty() ) @@ -123,6 +124,49 @@ T readFromUser(const T& def_num) return read; } +///////////////////////////////////////////////////////////////////////// +// USEFUL FUNCTIONS +///////////////////////////////////////////////////////////////////////// + + +inline bool LessPoints(const cv::Point2f& lhs, const cv::Point2f& rhs) +{ + return (lhs.x < rhs.x) || ((lhs.x == rhs.x) && (lhs.y < rhs.y)); +} + +inline std::vector<cv::Point2f> vecIntersec(std::vector<cv::Point2f> v1, std::vector<cv::Point2f> v2) +{ + std::vector<cv::Point2f> v3; + // Sort vectors + std::sort(v1.begin(), v1.end(), LessPoints); + std::sort(v2.begin(), v2.end(), LessPoints); + // Intersect + std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), std::back_inserter(v3), LessPoints); + return v3; +} + +inline std::vector<cv::Point2f> vecUnion(std::vector<cv::Point2f> v1, std::vector<cv::Point2f> v2) +{ + // Sort vectors and intersect + std::vector<cv::Point2f> v3; + std::sort(v1.begin(), v1.end(), LessPoints); + std::sort(v2.begin(), v2.end(), LessPoints); + std::set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), std::back_inserter(v3), LessPoints); + return v3; +} + +inline void drawKeyPoints(cv::Mat& _image, const KeyPointVector& _kp_vec) +{ + for (unsigned int ii = 0; ii < _kp_vec.size(); ++ii) + cv::circle(_image, _kp_vec[ii].pt, 5, cv::Scalar(128, 128, 255), -1); +} + +inline void drawKeyLines(cv::Mat& _image, const KeyLineVector& _kl_vec) +{ + for (unsigned int ii = 0; ii < _kl_vec.size(); ++ii) + cv::line(_image, _kl_vec[ii].getStartPoint(), _kl_vec[ii].getEndPoint(), cv::Scalar(128, 128, 255), 3); +} + } /* namespace vision_utils */ #endif