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

Add projectPoints fc

parent 5acc5bf5
No related branches found
No related tags found
No related merge requests found
# Specific definitions # Specific definitions
ADD_DEFINITIONS(-DPRINT_INFO_VU) #ADD_DEFINITIONS(-DPRINT_INFO_VU)
# library source files # library source files
SET(sources SET(sources
......
#ifndef _ALGORITHM_ACTIVESEARCH_H_ #ifndef _ALGORITHM_ACTIVESEARCH_H_
#define _ALGORITHM_ACTIVESEARCH_H_ #define _ALGORITHM_ACTIVESEARCH_H_
#include "../../vision_utils.h"
#include "../algorithm_base.h" #include "../algorithm_base.h"
#include "../algorithm_factory.h" #include "../algorithm_factory.h"
#include "../../common_class/buffer.h" #include "../../common_class/buffer.h"
...@@ -9,15 +10,6 @@ ...@@ -9,15 +10,6 @@
#include "../../descriptors/descriptor_base.h" #include "../../descriptors/descriptor_base.h"
#include "../../matchers/matcher_base.h" #include "../../matchers/matcher_base.h"
//OpenCV
#include <opencv2/core.hpp>
#include <opencv2/features2d.hpp>
// Eigen
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Geometry>
#include <eigen3/Eigen/Sparse>
namespace vision_utils { namespace vision_utils {
// Create all pointers // Create all pointers
......
#ifndef _ALGORITHM_OPTFLOWPYRLK_H_ #ifndef _ALGORITHM_OPTFLOWPYRLK_H_
#define _ALGORITHM_OPTFLOWPYRLK_H_ #define _ALGORITHM_OPTFLOWPYRLK_H_
#include "../../vision_utils.h"
#include "../algorithm_base.h" #include "../algorithm_base.h"
#include "../algorithm_factory.h" #include "../algorithm_factory.h"
#include "../../common_class/buffer.h" #include "../../common_class/buffer.h"
......
#ifndef _ALGORITHM_TRACKFEATURES_H_ #ifndef _ALGORITHM_TRACKFEATURES_H_
#define _ALGORITHM_TRACKFEATURES_H_ #define _ALGORITHM_TRACKFEATURES_H_
#include "../../vision_utils.h"
#include "../algorithm_base.h" #include "../algorithm_base.h"
#include "../algorithm_factory.h" #include "../algorithm_factory.h"
#include "../../common_class/buffer.h" #include "../../common_class/buffer.h"
...@@ -9,15 +10,6 @@ ...@@ -9,15 +10,6 @@
#include "../../descriptors/descriptor_base.h" #include "../../descriptors/descriptor_base.h"
#include "../../matchers/matcher_base.h" #include "../../matchers/matcher_base.h"
//OpenCV
#include <opencv2/core.hpp>
#include "opencv2/features2d.hpp"
// Eigen
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Geometry>
#include <eigen3/Eigen/Sparse>
namespace vision_utils { namespace vision_utils {
// Create all pointers // Create all pointers
......
...@@ -10,25 +10,17 @@ DetectorBase::~DetectorBase(void) ...@@ -10,25 +10,17 @@ DetectorBase::~DetectorBase(void)
{ {
} }
KeyPointVector DetectorBase::detect(const cv::Mat& _image) KeyPointVector DetectorBase::detect(const cv::Mat& _image, const cv::InputArray& _mask)
{
cv::Mat mask = cv::Mat::ones(_image.size(), CV_8U);
return detect(_image, mask);
}
KeyPointVector DetectorBase::detect(const cv::Mat& _image, const cv::Mat& _mask)
{ {
KeyPointVector kpts; KeyPointVector kpts;
clock_t tStart = clock(); clock_t tStart = clock();
detector_->detect(_image, kpts, _mask); detector_->detect(_image, kpts, _mask);
comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC; comp_time_ = (double)(clock() - tStart) / CLOCKS_PER_SEC;
return kpts; return kpts;
} }
KeyPointVector DetectorBase::detect(const cv::Mat& _image, cv::Rect& _roi) KeyPointVector DetectorBase::detect(const cv::Mat& _image, cv::Rect& _roi)
{ {
// FIX this
KeyPointVector kpts; KeyPointVector kpts;
if (!_image.empty()) if (!_image.empty())
{ {
......
...@@ -34,8 +34,7 @@ class DetectorBase : public VUBase, public std::enable_shared_from_this<Detector ...@@ -34,8 +34,7 @@ class DetectorBase : public VUBase, public std::enable_shared_from_this<Detector
*/ */
virtual ~DetectorBase(void); virtual ~DetectorBase(void);
KeyPointVector detect(const cv::Mat& _image); KeyPointVector detect(const cv::Mat& _image, const cv::InputArray& _mask=cv::noArray() );
KeyPointVector detect(const cv::Mat& _image, const cv::Mat& _mask);
KeyPointVector detect(const cv::Mat& _image, cv::Rect& _roi); KeyPointVector detect(const cv::Mat& _image, cv::Rect& _roi);
std::string getName(void); std::string getName(void);
......
...@@ -15,10 +15,10 @@ VU_PTR_TYPEDEFS(DetectorParamsORB); ...@@ -15,10 +15,10 @@ VU_PTR_TYPEDEFS(DetectorParamsORB);
*/ */
struct DetectorParamsORB: public ParamsBase struct DetectorParamsORB: public ParamsBase
{ {
int nfeatures = 500; // The maximum number of features to retain. int nfeatures = 20; // The maximum number of features to retain.
float scaleFactor = 2.0f; // Pyramid decimation ratio, greater than 1. scaleFactor==2 means the classical pyramid, where each next level has 4x less pixels than the previous, but such a big scale factor will degrade feature matching scores dramatically. On the other hand, too close to 1 scale factor will mean that to cover certain scale range you will need more pyramid levels and so the speed will suffer. float scaleFactor = 1.2f; // Pyramid decimation ratio, greater than 1. scaleFactor==2 means the classical pyramid, where each next level has 4x less pixels than the previous, but such a big scale factor will degrade feature matching scores dramatically. On the other hand, too close to 1 scale factor will mean that to cover certain scale range you will need more pyramid levels and so the speed will suffer.
int nlevels = 8; // The number of pyramid levels. The smallest level will have linear size equal to input_image_linear_size/pow(scaleFactor, nlevels). int nlevels = 8; // The number of pyramid levels. The smallest level will have linear size equal to input_image_linear_size/pow(scaleFactor, nlevels).
int edgeThreshold = 31; // This is size of the border where the features are not detected. It should roughly match the patchSize parameter. int edgeThreshold = 16; // This is size of the border where the features are not detected. It should roughly match the patchSize parameter.
int firstLevel = 0; // It should be 0 in the current implementation. int firstLevel = 0; // It should be 0 in the current implementation.
int WTA_K = 2; // The number of points that produce each element of the oriented BRIEF descriptor. The default value 2 means the BRIEF where we take a random point pair and compare their brightnesses, so we get 0/1 response. Other possible values are 3 and 4. For example, 3 means that we take 3 random points (of course, those point coordinates are random, but they are generated from the pre-defined seed, so each element of BRIEF descriptor is computed deterministically from the pixel rectangle), find point of maximum brightness and output index of the winner (0, 1 or 2). Such output will occupy 2 bits, and therefore it will need a special variant of Hamming distance, denoted as NORM_HAMMING2 (2 bits per bin). When WTA_K=4, we take 4 random points to compute each bin (that will also occupy 2 bits with possible values 0, 1, 2 or 3). int WTA_K = 2; // The number of points that produce each element of the oriented BRIEF descriptor. The default value 2 means the BRIEF where we take a random point pair and compare their brightnesses, so we get 0/1 response. Other possible values are 3 and 4. For example, 3 means that we take 3 random points (of course, those point coordinates are random, but they are generated from the pre-defined seed, so each element of BRIEF descriptor is computed deterministically from the pixel rectangle), find point of maximum brightness and output index of the winner (0, 1 or 2). Such output will occupy 2 bits, and therefore it will need a special variant of Hamming distance, denoted as NORM_HAMMING2 (2 bits per bin). When WTA_K=4, we take 4 random points to compute each bin (that will also occupy 2 bits with possible values 0, 1, 2 or 3).
int scoreType = cv::ORB::HARRIS_SCORE; // The default HARRIS_SCORE means that Harris algorithm is used to rank features (the score is written to KeyPoint::score and is used to retain best nfeatures features); FAST_SCORE is alternative value of the parameter that produces slightly less stable keypoints, but it is a little faster to compute. int scoreType = cv::ORB::HARRIS_SCORE; // The default HARRIS_SCORE means that Harris algorithm is used to rank features (the score is written to KeyPoint::score and is used to retain best nfeatures features); FAST_SCORE is alternative value of the parameter that produces slightly less stable keypoints, but it is a little faster to compute.
......
...@@ -227,6 +227,39 @@ void retainBest(KeyPointVector& _kpts, int n) ...@@ -227,6 +227,39 @@ void retainBest(KeyPointVector& _kpts, int n)
} }
} }
Eigen::MatrixXf projectPoints(const Eigen::MatrixXf& _points3D, const Eigen::Vector3f& _rot_mat, const Eigen::Vector3f& _trans_mat, const Eigen::MatrixXf& _cam_mat, const Eigen::VectorXf& _dist_coef)
{
// Check row-wise points
assert(_points3D.cols()!=3 && "[Vision Utils]: The 3D points are expected to be stored row-wise");
cv::Mat cv_3Dpoints;
cv::eigen2cv(_points3D, cv_3Dpoints);
cv::Vec3f cv_rot_mat;
cv::eigen2cv(_rot_mat, cv_rot_mat);
cv::Vec3f cv_trans_mat;
cv::eigen2cv(_trans_mat, cv_trans_mat);
cv::Mat cv_cam_mat;
cv::eigen2cv(_cam_mat, cv_cam_mat);
cv::Mat cv_distcoeff_mat;
cv::eigen2cv(_dist_coef, cv_distcoeff_mat);
std::vector<cv::Point2f> cv_2Dpoints;
cv::projectPoints(cv_3Dpoints,cv_rot_mat,cv_trans_mat,cv_cam_mat,cv_distcoeff_mat,cv_2Dpoints);
Eigen::MatrixXf _points2D(cv_2Dpoints.size(),2);
for (int ii = 0; ii < cv_2Dpoints.size(); ++ii)
{
_points2D(ii,0) = cv_2Dpoints[ii].x;
_points2D(ii,1) = cv_2Dpoints[ii].y;
}
return _points2D;
}
#ifdef USING_YAML #ifdef USING_YAML
std::string readYamlType(const std::string& _filename_dot_yaml, const std::string& _type) std::string readYamlType(const std::string& _filename_dot_yaml, const std::string& _type)
{ {
......
...@@ -18,9 +18,15 @@ ...@@ -18,9 +18,15 @@
#include <boost/assign/std/vector.hpp> // for 'operator+=()' #include <boost/assign/std/vector.hpp> // for 'operator+=()'
using namespace boost::assign; // bring 'operator+=()' into scope using namespace boost::assign; // bring 'operator+=()' into scope
// Eigen
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Geometry>
#include <eigen3/Eigen/Sparse>
// OpenCV // OpenCV
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/core/types.hpp> #include <opencv2/core/types.hpp>
#include <opencv2/core/eigen.hpp>
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp> #include <opencv2/features2d/features2d.hpp>
...@@ -180,6 +186,8 @@ std::string readYamlType(const std::string& _filename_dot_yaml, const std::strin ...@@ -180,6 +186,8 @@ std::string readYamlType(const std::string& _filename_dot_yaml, const std::strin
void retainBest(KeyPointVector& _kpts, int n); void retainBest(KeyPointVector& _kpts, int n);
Eigen::MatrixXf projectPoints(const Eigen::MatrixXf& _points3D, const Eigen::Vector3f& _rot_mat, const Eigen::Vector3f& _trans_mat, const Eigen::MatrixXf& _cam_mat, const Eigen::VectorXf& _dist_coef);
} /* namespace vision_utils */ } /* namespace vision_utils */
#endif #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