From 57965e33647f2c83e8e4d0e5ec1dc7f303e8eeed Mon Sep 17 00:00:00 2001 From: asantamaria <asantamaria@iri.upc.edu> Date: Fri, 4 Aug 2017 13:53:01 +0200 Subject: [PATCH] compiles but needs check and example --- CMakeLists.txt | 21 +- src/CMakeLists.txt | 4 +- src/common/common_base.h | 206 -------------- src/common/factory.h | 5 +- src/common/vision_utils.h | 290 ++++++++++++++++++++ src/detectors/detector_base.cpp | 18 ++ src/detectors/detector_base.h | 83 ++++++ src/detectors/detector_factory.h | 32 +++ src/detectors/detector_orb.cpp | 35 +++ src/detectors/detector_orb.h | 39 +++ src/examples/test_factories.cpp | 80 ++++++ src/feature_descriptor/feature_descriptor.h | 2 +- src/feature_detector/feature_detector.h | 2 +- src/feature_matcher/feature_matcher.h | 2 +- src/vision_utils.cpp | 34 --- src/vision_utils.h | 38 --- 16 files changed, 602 insertions(+), 289 deletions(-) delete mode 100644 src/common/common_base.h create mode 100644 src/common/vision_utils.h create mode 100644 src/detectors/detector_base.cpp create mode 100644 src/detectors/detector_base.h create mode 100644 src/detectors/detector_factory.h create mode 100644 src/detectors/detector_orb.cpp create mode 100644 src/detectors/detector_orb.h create mode 100644 src/examples/test_factories.cpp delete mode 100644 src/vision_utils.cpp delete mode 100644 src/vision_utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ec4ad5c..a31fce8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,25 @@ IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "DEBUG") ENDIF (NOT CMAKE_BUILD_TYPE) -SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -D_REENTRANT") -SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -D_REENTRANT") +if(UNIX) + # GCC is not strict enough by default, so enable most of the warnings. + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -Werror=all -Werror=extra -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers") +endif(UNIX) + +#Set compiler according C++11 support +include(CheckCXXCompilerFlag) +CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) +if(COMPILER_SUPPORTS_CXX11) + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has C++11 support.") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif(COMPILER_SUPPORTS_CXX0X) + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has C++0x support.") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +else() + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") +endif() ADD_SUBDIRECTORY(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a0b52a..e513ccb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,10 @@ # 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 detectors/detector_base.cpp detectors/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 common/common_base.h detectors/factory.h detectors/detector_base.cpp detectors/detector_orb.cpp) +SET(headers common/vision_utils.h detectors/factory.h detectors/detector_factory.h detectors/detector_base.h detectors/detector_orb.h) # locate the necessary dependencies FIND_PACKAGE(Eigen3 REQUIRED) diff --git a/src/common/common_base.h b/src/common/common_base.h deleted file mode 100644 index 81308d8..0000000 --- a/src/common/common_base.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef _VU_BASE_H -#define _VU_BASE_H - -// std -#include <functional> -#include <set> -#include <iostream> -#include <map> -#include <vector> -#include <string> -#include <iostream> -#include <time.h> -#include <memory> // shared_ptr and weak_ptr - -// Boost -#include <boost/assign/std/vector.hpp> // for 'operator+=()' -using namespace boost::assign; // bring 'operator+=()' into scope - -// OpenCV -#include <opencv2/core/core.hpp> -#include <opencv2/core/types.hpp> -#include <opencv2/imgproc/imgproc.hpp> -#include <opencv2/highgui/highgui.hpp> -#include <opencv2/features2d/features2d.hpp> -#include <opencv2/xfeatures2d/nonfree.hpp> -#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; - -/** - * \brief Class to set object types - */ -class TypesList { - -public: - - TypesList(void): init_(false) {}; - - ~TypesList(void) {}; - - void set(std::vector<std::string> &_types) - { - for (unsigned int ii = 0; ii < _types.size(); ii++) - types_[_types[ii]] = ii; - init_= true; - }; - - std::vector<std::string> list(void) - { - std::vector<std::string> list; - list.reserve(types_.size()); - for(std::map<std::string,int>::iterator it = types_.begin(); it != types_.end(); ++it) - { - list.push_back(it->first); - } - return list; - } - - int operator()(const std::string &name) { - if (init_) - { - // Search done to take advantage of MAP alphabetical order - int idx = 0; - for (std::map<std::string, int>::const_iterator it = types_.begin();it != types_.end(); ++it) - { - if (it->first.compare(name) == 0) - return idx; - ++idx; - } - - - } - else - { - std::cerr << "[Vision Utils]: Wrong object initialization" << std::cout; - } - return 0; - }; - - std::string operator()(const int &num) { - if (init_) - { - // Search done to take advantage of MAP alphabetical order - int idx = 0; - for (std::map<std::string, int>::const_iterator it = types_.begin();it != types_.end(); ++it) - { - if (num == idx) - return it->first; - ++idx; - } - } - else - std::cerr << "[Vision Utils]: Wrong object initialization" << std::cout; - return 0; - }; - - unsigned int size(void) - { return types_.size(); } - -protected: - - std::map<std::string, int> types_; - bool init_; -}; - -/** - * \brief Class to set object parameters - * - * Derive from this class to create classes of parameters. - */ -class ParamsBase { -public: - ParamsBase(void) { - } - ; - ~ParamsBase(void) { - } - ; - std::string type; - std::string name; -}; - -/** - * \brief base Class - */ -class VUBase { - -public: - - VUBase(void): is_init_(false) {}; - - virtual ~VUBase(void){}; - - /** - * \brief Get detection duration - */ - double getTime(void){return comp_time_;}; - - /** - * \brief list types - */ - std::vector<std::string> list(void) - { return types_.list();}; - - /** - * \brief Set object without constructor - */ - bool set(const std::string& _type, const ParamsBase &_params) - { - bool success = init(_type, _params); - return success; - }; - - void get(std::string& _type) - { _type = type_; }; - - void get(int& _type) - { - _type = types_(type_); - }; - - cv::Mat drawKeyFeatures(const cv::Mat& _image, const KeyPointVector& _kp_vec) - { - cv::Mat img_out(_image); - - for (unsigned int ii = 0; ii < _kp_vec.size(); ++ii) - cv::circle(img_out, _kp_vec[ii].pt, 5, cv::Scalar(128, 128, 255), -1); - - return img_out; - } - - cv::Mat drawKeyFeatures(const cv::Mat& _image, const KeyLineVector& _kl_vec) - { - cv::Mat img_out(_image); - - for (unsigned int ii = 0; ii < _kl_vec.size(); ++ii) - cv::line(img_out, _kl_vec[ii].getStartPoint(), _kl_vec[ii].getEndPoint(), cv::Scalar(128, 128, 255), 3); - - return img_out; - } - - -protected: - - // Flags - bool is_init_; - - double comp_time_; // Detection time - - TypesList types_; - - std::string type_; - - virtual bool init(const std::string &_type, const ParamsBase &_params) = 0; - - /** - * \brief Set all types - */ - virtual void setAllTypes(void) = 0; - -}; - -#endif diff --git a/src/common/factory.h b/src/common/factory.h index a6f71ea..d37bb3a 100644 --- a/src/common/factory.h +++ b/src/common/factory.h @@ -1,9 +1,6 @@ #ifndef FACTORY_H_ #define FACTORY_H_ -// wolf -//#include "wolf.h" - // std #include <string> #include <map> @@ -301,4 +298,4 @@ inline std::string Factory<TypeBase, TypeInput...>::getClass() } /* namespace vision_utils */ -#endif /* FACTORY_H_ */ +#endif diff --git a/src/common/vision_utils.h b/src/common/vision_utils.h new file mode 100644 index 0000000..076ad37 --- /dev/null +++ b/src/common/vision_utils.h @@ -0,0 +1,290 @@ +#ifndef _VU_BASE_H +#define _VU_BASE_H + +// std +#include <functional> +#include <set> +#include <iostream> +#include <map> +#include <vector> +#include <string> +#include <iostream> +#include <time.h> +#include <memory> // shared_ptr and weak_ptr + +// Boost +#include <boost/assign/std/vector.hpp> // for 'operator+=()' +using namespace boost::assign; // bring 'operator+=()' into scope + +// OpenCV +#include <opencv2/core/core.hpp> +#include <opencv2/core/types.hpp> +#include <opencv2/imgproc/imgproc.hpp> +#include <opencv2/highgui/highgui.hpp> +#include <opencv2/features2d/features2d.hpp> +#include <opencv2/xfeatures2d/nonfree.hpp> +#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; + +namespace vision_utils { + +///////////////////////////////////////////////////////////////////////// +// TYPEDEFS FOR POINTERS, LISTS AND ITERATORS IN THE WOLF TREE +///////////////////////////////////////////////////////////////////////// + +#define VU_PTR_TYPEDEFS(ClassName) \ + class ClassName; \ + typedef std::shared_ptr<ClassName> ClassName##Ptr; \ + typedef std::shared_ptr<const ClassName> ClassName##ConstPtr; \ + typedef std::weak_ptr<ClassName> ClassName##WPtr; + +#define VU_LIST_TYPEDEFS(ClassName) \ + class ClassName; \ + typedef std::list<ClassName##Ptr> ClassName##List; \ + typedef ClassName##List::iterator ClassName##Iter; + +#define VU_STRUCT_PTR_TYPEDEFS(StructName) \ + struct StructName; \ + typedef std::shared_ptr<StructName> StructName##Ptr; \ + typedef std::shared_ptr<const StructName> StructName##ConstPtr; \ + +///////////////////////////////////////////////////////////////////////// +// CLASS DEFINITIONS +///////////////////////////////////////////////////////////////////////// + +/** + * \brief Class to set object types + */ +class TypesList { + +public: + + TypesList(void): init_(false) {}; + + ~TypesList(void) {}; + + void set(std::vector<std::string> &_types) + { + for (unsigned int ii = 0; ii < _types.size(); ii++) + types_[_types[ii]] = ii; + init_= true; + }; + + std::vector<std::string> list(void) + { + std::vector<std::string> list; + list.reserve(types_.size()); + for(std::map<std::string,int>::iterator it = types_.begin(); it != types_.end(); ++it) + { + list.push_back(it->first); + } + return list; + } + + int operator()(const std::string &name) { + if (init_) + { + // Search done to take advantage of MAP alphabetical order + int idx = 0; + for (std::map<std::string, int>::const_iterator it = types_.begin();it != types_.end(); ++it) + { + if (it->first.compare(name) == 0) + return idx; + ++idx; + } + + + } + else + { + std::cerr << "[Vision Utils]: Wrong object initialization" << std::endl; + } + return 0; + }; + + std::string operator()(const int &num) { + if (init_) + { + // Search done to take advantage of MAP alphabetical order + int idx = 0; + for (std::map<std::string, int>::const_iterator it = types_.begin();it != types_.end(); ++it) + { + if (num == idx) + return it->first; + ++idx; + } + } + else + std::cerr << "[Vision Utils]: Wrong object initialization" << std::endl; + return 0; + }; + + unsigned int size(void) + { return types_.size(); } + +protected: + + std::map<std::string, int> types_; + bool init_; +}; + +/** + * \brief Class to set object parameters + * + * Derive from this class to create classes of parameters. + */ +class ParamsBase { +public: + ParamsBase(void) { + } + ; + ~ParamsBase(void) { + } + ; + std::string type; + std::string name; +}; + +/** + * \brief base Class + */ +class VUBase { + +public: + + VUBase(void){}; + + virtual ~VUBase(void){}; + + /** + * \brief Get detection duration + */ + double getTime(void){return comp_time_;}; + +// /** +// * \brief list types +// */ +// std::vector<std::string> list(void) +// { return types_.list();}; +// +// /** +// * \brief Set object without constructor +// */ +// bool set(const std::string& _type, const ParamsBase &_params) +// { +// bool success = init(_type, _params); +// return success; +// }; +// +// void get(std::string& _type) +// { _type = type_; }; +// +// void get(int& _type) +// { +// _type = types_(type_); +// }; +// +// cv::Mat drawKeyFeatures(const cv::Mat& _image, const KeyPointVector& _kp_vec) +// { +// cv::Mat img_out(_image); +// +// for (unsigned int ii = 0; ii < _kp_vec.size(); ++ii) +// cv::circle(img_out, _kp_vec[ii].pt, 5, cv::Scalar(128, 128, 255), -1); +// +// return img_out; +// } +// +// cv::Mat drawKeyFeatures(const cv::Mat& _image, const KeyLineVector& _kl_vec) +// { +// cv::Mat img_out(_image); +// +// for (unsigned int ii = 0; ii < _kl_vec.size(); ++ii) +// cv::line(img_out, _kl_vec[ii].getStartPoint(), _kl_vec[ii].getEndPoint(), cv::Scalar(128, 128, 255), 3); +// +// return img_out; +// } +// + +protected: + + // Flags + + double comp_time_; // Detection time + +// TypesList types_; +// +// std::string type_; + +// virtual bool init(const std::string &_type, const ParamsBase &_params) = 0; +// +// /** +// * \brief Set all types +// */ +// virtual void setAllTypes(void) = 0; + +}; + +VU_PTR_TYPEDEFS(TypesList); +VU_PTR_TYPEDEFS(ParamsBase); +VU_PTR_TYPEDEFS(VUBase); + + + +///////////////////////////////////////////////////////////////////////// +// USEFUL FUNCTIONS +///////////////////////////////////////////////////////////////////////// + +// unnamed namespace used for helper functions local to this file. +// +//std::string uppercase(std::string s) {for (auto & c: s) c = std::toupper(c); return s;} +// +//template <typename T> +//T readFromUser(const T& def_num) +//{ +// T read = def_num; +// std::string input; +// std::getline( std::cin, input ); +// if ( !input.empty() ) +// { +// std::istringstream stream( input ); +// stream >> read; +// } +// +// return read; +//} +// +//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 */ + +#endif diff --git a/src/detectors/detector_base.cpp b/src/detectors/detector_base.cpp new file mode 100644 index 0000000..a7c5c74 --- /dev/null +++ b/src/detectors/detector_base.cpp @@ -0,0 +1,18 @@ +#include "detector_base.h" + +namespace vision_utils { + +DetectorBase::DetectorBase(const DetectorParams& _params) +{ + +} + +DetectorBase::DetectorBase(void) +{ +} + +DetectorBase::~DetectorBase() +{ +} + +} /* namespace vision_utils */ diff --git a/src/detectors/detector_base.h b/src/detectors/detector_base.h new file mode 100644 index 0000000..d8f26f9 --- /dev/null +++ b/src/detectors/detector_base.h @@ -0,0 +1,83 @@ +#ifndef DETECTOR_BASE_H_ +#define DETECTOR_BASE_H_ + +//Wolf includes +#include "common/vision_utils.h" +#include "detector_factory.h" + +namespace vision_utils { + +VU_PTR_TYPEDEFS(DetectorParams); +VU_PTR_TYPEDEFS(DetectorBase); + +/** \brief base class for DETECTOR parameters + * + * Derive from this class to create DETECTOR class parameters. + */ +class DetectorParams: public ParamsBase { +public: + DetectorParams(void) { + } + ; + ~DetectorParams(void) { + } + ; + std::string type; + std::string name; +}; + +class DetectorBase : public VUBase, public std::enable_shared_from_this<DetectorBase> +{ + public: + + /** + * \brief Constructor + * + * \param _type Type of detector + * \param _params Detector parameters + */ + DetectorBase(const DetectorParams& _params); + + /** + * \brief Constructor without parameters + */ + DetectorBase(void); + + /** + * \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; +}; + +///////////////////////////////////////////////////////// +// Installations +///////////////////////////////////////////////////////// + +//DetectorBasePtr installDetector(const std::string& _det_type, // +// const std::string& _unique_det_name, // +// ParamsBase _params) +//{ +// DetectorBasePtr det_ptr = DetectorFactory::get().create(uppercase(_det_type), _unique_det_name, _params); +// return det_ptr; +//} + +//DetectorBasePtr installDetector(const std::string& _det_type, // +// const std::string& _unique_det_name, // +// const std::string& _params_filename) +//{ +// if (_params_filename != "") +// { +// ParamsBasePtr params_ptr = ParamsFactory::get().create(_det_type, _params_filename); +// return installDetector(_det_type, _unique_det_name, params_ptr); +// } +// else +// return installDetector(_det_type, _unique_det_name, ParamsBasePtr()); +// +//} + +} /* namespace vision_utils */ + +#endif diff --git a/src/detectors/detector_factory.h b/src/detectors/detector_factory.h new file mode 100644 index 0000000..31c4578 --- /dev/null +++ b/src/detectors/detector_factory.h @@ -0,0 +1,32 @@ +#ifndef DETECTOR_FACTORY_H_ +#define DETECTOR_FACTORY_H_ + +namespace vision_utils +{ +class DetectorBase; +struct DetectorParamsBase; +} + +// vision_utils +#include "../common/factory.h" + +namespace vision_utils +{ + +typedef Factory<DetectorBase, + const std::string&, + const ParamsBasePtr> DetectorFactory; +template<> +inline std::string DetectorFactory::getClass() +{ + return "DetectorFactory"; +} + + +#define VU_REGISTER_PROCESSOR(DetectorType, DetectorName) \ + namespace{ const bool DetectorName##Registered = \ + DetectorFactory::get().registerCreator(DetectorType, DetectorName::create); }\ + +} /* namespace vision_utils */ + +#endif /* DETECTOR_FACTORY_H_ */ diff --git a/src/detectors/detector_orb.cpp b/src/detectors/detector_orb.cpp new file mode 100644 index 0000000..216dcdd --- /dev/null +++ b/src/detectors/detector_orb.cpp @@ -0,0 +1,35 @@ +#include "detector_orb.h" + +namespace vision_utils { + +DetectorORB::DetectorORB() +{ + std::cout << "Detector ORB constructred" << std::endl; +} + +DetectorORB::~DetectorORB() +{ + std::cout << "Detector ORB destructed" << std::endl; +} + +DetectorBasePtr DetectorORB::create(const std::string& _unique_name, const ParamsBasePtr _params) +{ + DetectorORBPtr det_ptr = std::make_shared<DetectorORB>(); + std::cout << "Detector ORB destructed" << std::endl; + return det_ptr; +} + +void DetectorORB::detect(const cv::Mat& _image) +{} +void DetectorORB::detect(const cv::Mat& _image, const cv::Mat& _mask) +{} + +} /* namespace vision_utils */ + +// Register in the factory +#include "detector_factory.h" + +namespace vision_utils +{ + VU_REGISTER_PROCESSOR("DETECTOR ORB", DetectorORB) +} diff --git a/src/detectors/detector_orb.h b/src/detectors/detector_orb.h new file mode 100644 index 0000000..ced4cee --- /dev/null +++ b/src/detectors/detector_orb.h @@ -0,0 +1,39 @@ +#ifndef DETECTOR_ORB_H +#define DETECTOR_ORB_H + +// vision_utils +#include "detector_base.h" + +namespace vision_utils { + +VU_PTR_TYPEDEFS(DetectorORB); + +//class +class DetectorORB : public DetectorBase { + + public: + DetectorORB(); + virtual ~DetectorORB(); + + protected: + + + public: + static DetectorBasePtr create(const std::string& _unique_name, const ParamsBasePtr _params); + + void detect(const cv::Mat& _image); + void detect(const cv::Mat& _image, const cv::Mat& _mask); +}; + +} + +///////////////////////////////////////////////////////// +// IMPLEMENTATION. (inline functions) +///////////////////////////////////////////////////////// + +namespace vision_utils{ + + +} /* namespace vision_utils */ + +#endif diff --git a/src/examples/test_factories.cpp b/src/examples/test_factories.cpp new file mode 100644 index 0000000..8f8175a --- /dev/null +++ b/src/examples/test_factories.cpp @@ -0,0 +1,80 @@ +/** + * \file test_wolf_factories.cpp + * + * Created on: Apr 25, 2016 + * \author: jsola + */ + +#include "../detectors/detector_orb" + +#include "../factory.h" + +#include <iostream> +#include <iomanip> +#include <cstdlib> + + +int main(void) +{ + using std::shared_ptr; + using std::make_shared; + using std::static_pointer_cast; + + 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" + + + cout << "\n================== Detector Factory ===================" << endl; + + // Use params factory for camera intrinsics + ParamsBase orb_params; + DetectorBasePtr intr_cam_ptr = DetectorFactory::get().create("ORB", orb_params); + ProcessorParamsBasePtr params_ptr = ProcessorParamsFactory::get().create("IMAGE FEATURE", wolf_config + "/processor_image_ORB.yaml"); +// +// cout << "CAMERA with intrinsics : " << (static_pointer_cast<IntrinsicsCamera>(intr_cam_ptr))->pinhole_model.transpose() << endl; +//// cout << "Processor IMAGE image width : " << (static_pointer_cast<ProcessorParamsImage>(params_ptr))->image.width << endl; +// +// cout << "\n==================== Install Sensors ====================" << endl; +// +// // Install sensors +// problem->installSensor("CAMERA", "front left camera", pq_3d, intr_cam_ptr); +// problem->installSensor("CAMERA", "front right camera", pq_3d, wolf_config + "/camera_params_ueye_sim.yaml"); +// problem->installSensor("ODOM 2D", "main odometer", po_2d, intr_odom2d_ptr); +// problem->installSensor("GPS FIX", "GPS fix", p_3d); +// problem->installSensor("IMU", "inertial", pq_3d); +//// problem->installSensor("GPS", "GPS raw", p_3d); +// problem->installSensor("ODOM 2D", "aux odometer", po_2d, intr_odom2d_ptr); +// problem->installSensor("CAMERA", "rear camera", pq_3d, wolf_root + "/src/examples/camera_params_ueye_sim.yaml"); +// +// // print available sensors +// for (auto sen : problem->getHardwarePtr()->getSensorList()) +// { +// cout << "Sensor " << setw(2) << left << sen->id() +// << " | type " << setw(8) << sen->getType() +// << " | name: " << sen->getName() << endl; +// } +// +// cout << "\n=================== Install Processors ===================" << endl; +// +// // Install processors and bind them to sensors -- by sensor name! +// problem->installProcessor("ODOM 2D", "main odometry", "main odometer"); +// problem->installProcessor("ODOM 2D", "sec. odometry", "aux odometer"); +// problem->installProcessor("IMU", "pre-integrated", "inertial"); +// problem->installProcessor("IMAGE FEATURE", "ORB", "front left camera", wolf_config + "/processor_image_ORB.yaml"); +//// problem->createProcessor("GPS", "GPS pseudoranges", "GPS raw"); +// +// // print installed processors +// for (auto sen : problem->getHardwarePtr()->getSensorList()) +// for (auto prc : sen->getProcessorList()) +// cout << "Processor " << setw(2) << left << prc->id() +// << " | type : " << setw(8) << prc->getType() +// << " | name: " << setw(17) << prc->getName() +// << " | bound to sensor " << setw(2) << prc->getSensorPtr()->id() << ": " << prc->getSensorPtr()->getName() << endl; + + + return 0; +} + diff --git a/src/feature_descriptor/feature_descriptor.h b/src/feature_descriptor/feature_descriptor.h index 3823a98..3cfc3a1 100644 --- a/src/feature_descriptor/feature_descriptor.h +++ b/src/feature_descriptor/feature_descriptor.h @@ -1,7 +1,7 @@ #ifndef _FEATURE_DESCRIPTOR_H #define _FEATURE_DESCRIPTOR_H -#include "../common/common_base.h" +#include "../common/vision_utils.h" typedef cv::Ptr<cv::DescriptorExtractor> FeatureDescriptorPtr; diff --git a/src/feature_detector/feature_detector.h b/src/feature_detector/feature_detector.h index 60420ff..b902750 100644 --- a/src/feature_detector/feature_detector.h +++ b/src/feature_detector/feature_detector.h @@ -1,7 +1,7 @@ #ifndef _FEATURE_DETECTOR_H #define _FEATURE_DETECTOR_H -#include "../common/common_base.h" +#include "../common/vision_utils.h" #define SCALE_FACTOR_LINE_DETECTOR 2 #define NUM_OCTAVE_LINE_DETECTOR 1 diff --git a/src/feature_matcher/feature_matcher.h b/src/feature_matcher/feature_matcher.h index 92be0e7..bc28b73 100644 --- a/src/feature_matcher/feature_matcher.h +++ b/src/feature_matcher/feature_matcher.h @@ -1,7 +1,7 @@ #ifndef _FEATURE_MATCHER_H #define _FEATURE_MATCHER_H -#include "../common/common_base.h" +#include "../common/vision_utils.h" typedef cv::Ptr<cv::DescriptorMatcher> FeatureMatcherPtr; diff --git a/src/vision_utils.cpp b/src/vision_utils.cpp deleted file mode 100644 index 55891ab..0000000 --- a/src/vision_utils.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "vision_utils.h" - -VisionUtils::VisionUtils() { -} - -VisionUtils::~VisionUtils() { -} - -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; -} diff --git a/src/vision_utils.h b/src/vision_utils.h deleted file mode 100644 index 716e4ff..0000000 --- a/src/vision_utils.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _VISION_UTILS_H -#define _VISION_UTILS_H - -#include "cam_utils/cam_utils.h" -#include "feature_detector/feature_detector.h" -#include "feature_descriptor/feature_descriptor.h" -#include "feature_matcher/feature_matcher.h" - -#include <functional> -#include <set> - -class VisionUtils { -public: - VisionUtils(); - ~VisionUtils(); -}; - -template <typename T> -T readFromUser(const T& def_num) -{ - T read = def_num; - std::string input; - std::getline( std::cin, input ); - if ( !input.empty() ) - { - std::istringstream stream( input ); - stream >> read; - } - - return read; -} - -bool LessPoints(const cv::Point2f& lhs, const cv::Point2f& rhs); -std::vector<cv::Point2f> vecIntersec(std::vector<cv::Point2f> v1, std::vector<cv::Point2f> v2); -std::vector<cv::Point2f> vecUnion(std::vector<cv::Point2f> v1, std::vector<cv::Point2f> v2); - - -#endif -- GitLab