Skip to content
Snippets Groups Projects
Commit 57965e33 authored by Angel Santamaria-Navarro's avatar Angel Santamaria-Navarro
Browse files

compiles but needs check and example

parent 429fdf97
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
# 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)
......
#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
......@@ -30,6 +30,32 @@ 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
*/
......@@ -75,7 +101,7 @@ public:
}
else
{
std::cerr << "[Vision Utils]: Wrong object initialization" << std::cout;
std::cerr << "[Vision Utils]: Wrong object initialization" << std::endl;
}
return 0;
};
......@@ -93,7 +119,7 @@ public:
}
}
else
std::cerr << "[Vision Utils]: Wrong object initialization" << std::cout;
std::cerr << "[Vision Utils]: Wrong object initialization" << std::endl;
return 0;
};
......@@ -130,7 +156,7 @@ class VUBase {
public:
VUBase(void): is_init_(false) {};
VUBase(void){};
virtual ~VUBase(void){};
......@@ -139,68 +165,126 @@ public:
*/
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;
}
// /**
// * \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_;
// 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;
// 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
#include "detector_base.h"
namespace vision_utils {
DetectorBase::DetectorBase(const DetectorParams& _params)
{
}
DetectorBase::DetectorBase(void)
{
}
DetectorBase::~DetectorBase()
{
}
} /* namespace vision_utils */
#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
#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_ */
#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)
}
#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
/**
* \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;
}
#ifndef _FEATURE_DESCRIPTOR_H
#define _FEATURE_DESCRIPTOR_H
#include "../common/common_base.h"
#include "../common/vision_utils.h"
typedef cv::Ptr<cv::DescriptorExtractor> FeatureDescriptorPtr;
......
#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
......
#ifndef _FEATURE_MATCHER_H
#define _FEATURE_MATCHER_H
#include "../common/common_base.h"
#include "../common/vision_utils.h"
typedef cv::Ptr<cv::DescriptorMatcher> FeatureMatcherPtr;
......
#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;
}
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment