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

Add filterByDistance

parent 1e9f9cb2
No related branches found
No related tags found
No related merge requests found
Showing
with 170 additions and 49 deletions
......@@ -30,6 +30,7 @@ matcher:
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
algorithm:
type: "ACTIVESEARCH"
......
......@@ -6,4 +6,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -6,4 +6,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -6,4 +6,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -6,4 +6,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -6,4 +6,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -27,6 +27,7 @@ matcher:
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
algorithm:
type: "TRACKFEATURES"
......
......@@ -32,6 +32,8 @@ static ParamsBasePtr createParamsBRUTEFORCEMatcher(const std::string & _filename
params_ptr->ransac_epipolar_distance = filters["ransac epipolar distance"].as<double>();
if (filters["ransac confidence prob"])
params_ptr->ransac_confidence_prob = filters["ransac confidence prob"].as<double>();
if (filters["max match euclidean dist"])
params_ptr->max_match_euclidean_dist = filters["max match euclidean dist"].as<Scalar>();
}else
{
std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl;
......
......@@ -27,6 +27,13 @@ static ParamsBasePtr createParamsBRUTEFORCE_HAMMINGMatcher(const std::string & _
params_ptr->match_type = d_yaml["match type"].as<int>();
if (d_yaml["min normalized score"])
params_ptr->min_norm_score = d_yaml["min normalized score"].as<double>();
Node filters = d_yaml["filtering"];
if (filters["ransac epipolar distance"])
params_ptr->ransac_epipolar_distance = filters["ransac epipolar distance"].as<double>();
if (filters["ransac confidence prob"])
params_ptr->ransac_confidence_prob = filters["ransac confidence prob"].as<double>();
if (filters["max match euclidean dist"])
params_ptr->max_match_euclidean_dist = filters["max match euclidean dist"].as<Scalar>();
}else
{
std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl;
......
......@@ -27,6 +27,13 @@ static ParamsBasePtr createParamsBRUTEFORCE_HAMMING_2Matcher(const std::string &
params_ptr->match_type = d_yaml["match type"].as<int>();
if (d_yaml["min normalized score"])
params_ptr->min_norm_score = d_yaml["min normalized score"].as<double>();
Node filters = d_yaml["filtering"];
if (filters["ransac epipolar distance"])
params_ptr->ransac_epipolar_distance = filters["ransac epipolar distance"].as<double>();
if (filters["ransac confidence prob"])
params_ptr->ransac_confidence_prob = filters["ransac confidence prob"].as<double>();
if (filters["max match euclidean dist"])
params_ptr->max_match_euclidean_dist = filters["max match euclidean dist"].as<Scalar>();
}else
{
std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl;
......
......@@ -27,6 +27,13 @@ static ParamsBasePtr createParamsBRUTEFORCE_L1Matcher(const std::string & _filen
params_ptr->match_type = d_yaml["match type"].as<int>();
if (d_yaml["min normalized score"])
params_ptr->min_norm_score = d_yaml["min normalized score"].as<double>();
Node filters = d_yaml["filtering"];
if (filters["ransac epipolar distance"])
params_ptr->ransac_epipolar_distance = filters["ransac epipolar distance"].as<double>();
if (filters["ransac confidence prob"])
params_ptr->ransac_confidence_prob = filters["ransac confidence prob"].as<double>();
if (filters["max match euclidean dist"])
params_ptr->max_match_euclidean_dist = filters["max match euclidean dist"].as<Scalar>();
}else
{
std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl;
......
......@@ -27,6 +27,13 @@ static ParamsBasePtr createParamsFLANNBASEDMatcher(const std::string & _filename
params_ptr->match_type = d_yaml["match type"].as<int>();
if (d_yaml["min normalized score"])
params_ptr->min_norm_score = d_yaml["min normalized score"].as<double>();
Node filters = d_yaml["filtering"];
if (filters["ransac epipolar distance"])
params_ptr->ransac_epipolar_distance = filters["ransac epipolar distance"].as<double>();
if (filters["ransac confidence prob"])
params_ptr->ransac_confidence_prob = filters["ransac confidence prob"].as<double>();
if (filters["max match euclidean dist"])
params_ptr->max_match_euclidean_dist = filters["max match euclidean dist"].as<Scalar>();
}else
{
std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl;
......
......@@ -114,48 +114,12 @@ std::vector<Scalar> MatcherBase::match(const cv::Mat& _desc1, const cv::Mat& _de
return normalized_scores;
}
void MatcherBase::filterByDistance(const int& _max_pixel_dist, const float& _img_size_percentage, const KeyPointVector& _kpts1,const KeyPointVector& _kpts2, const std::vector< DMatchVector >& _dirty, const int& _img_width, const int& _img_height, DMatchVector& _filtered_matches, KeyPointVector& _filtered_kpts, KeyPointVector& _filtered_kpts_prev)
{
if (params_base_ptr_->match_type == KNNMATCH || params_base_ptr_->match_type == RADIUSMATCH)
{
double tresholdDist = _img_size_percentage * sqrt(double(_img_height*_img_height + _img_width*_img_width));
std::vector< cv::DMatch > good_matches2;
_filtered_matches.reserve(_dirty.size());
for (size_t ii = 0; ii < _dirty.size(); ++ii)
{
for (unsigned int jj = 0; jj < _dirty[ii].size(); jj++)
{
cv::Point2f from = _kpts1[_dirty[ii][jj].queryIdx].pt;
cv::Point2f to = _kpts2[_dirty[ii][jj].trainIdx].pt;
//calculate local distance for each possible match
double dist = std::sqrt((from.x - to.x) * (from.x - to.x) + (from.y - to.y) * (from.y - to.y));
//save as best match if local distance is in specified area and on same height
if (dist < tresholdDist && std::abs(from.y-to.y)<_max_pixel_dist && std::abs(from.x-to.x)<_max_pixel_dist)
{
_filtered_matches.push_back(_dirty[ii][jj]);
cv::KeyPoint kpt = cv::KeyPoint(to,1);
cv::KeyPoint kpt_prev = cv::KeyPoint(from,1);
_filtered_kpts.push_back(kpt);
_filtered_kpts_prev.push_back(kpt_prev);
jj = _dirty[ii].size();
}
}
}
}
else
std::cerr << "[" << name_ << "]: Wrong input type in filterByDistance method." << std::endl;
}
void MatcherBase::filterByDistance(const int& _max_pixel_dist, const float& _img_size_percentage, const KeyPointVector& _kpts1,const KeyPointVector& _kpts2, const DMatchVector& _dirty, const int& _img_width, const int& _img_height, DMatchVector& _filtered_matches, KeyPointVector& _filtered_kpts, KeyPointVector& _filtered_kpts_prev)
{
if (params_base_ptr_->match_type == MATCH)
{
double tresholdDist = _img_size_percentage * sqrt(double(_img_height*_img_height + _img_width*_img_width));
std::vector< cv::DMatch > good_matches2;
_filtered_matches.reserve(_dirty.size());
for (size_t ii = 0; ii < _dirty.size(); ++ii)
{
......@@ -180,6 +144,106 @@ void MatcherBase::filterByDistance(const int& _max_pixel_dist, const float& _img
std::cerr << "[" << name_ << "]: Wrong input type in filterByDistance method." << std::endl;
}
void MatcherBase::filterByDistance(const int& _max_pixel_dist, const float& _img_size_percentage, const KeyPointVector& _kpts1,const KeyPointVector& _kpts2, const std::vector< DMatchVector >& _dirty, const int& _img_width, const int& _img_height, DMatchVector& _filtered_matches, KeyPointVector& _filtered_kpts, KeyPointVector& _filtered_kpts_prev)
{
if (params_base_ptr_->match_type == KNNMATCH || params_base_ptr_->match_type == RADIUSMATCH)
{
double tresholdDist = _img_size_percentage * sqrt(double(_img_height*_img_height + _img_width*_img_width));
_filtered_matches.reserve(_dirty.size());
for (size_t ii = 0; ii < _dirty.size(); ++ii)
{
for (unsigned int jj = 0; jj < _dirty[ii].size(); jj++)
{
cv::Point2f from = _kpts1[_dirty[ii][jj].queryIdx].pt;
cv::Point2f to = _kpts2[_dirty[ii][jj].trainIdx].pt;
//calculate local distance for each possible match
double dist = std::sqrt((from.x - to.x) * (from.x - to.x) + (from.y - to.y) * (from.y - to.y));
//save as best match if local distance is in specified area and on same height
if (dist < tresholdDist && std::abs(from.y-to.y)<_max_pixel_dist && std::abs(from.x-to.x)<_max_pixel_dist)
{
_filtered_matches.push_back(_dirty[ii][jj]);
cv::KeyPoint kpt = cv::KeyPoint(to,1);
cv::KeyPoint kpt_prev = cv::KeyPoint(from,1);
_filtered_kpts.push_back(kpt);
_filtered_kpts_prev.push_back(kpt_prev);
jj = _dirty[ii].size();
}
}
}
}
else
std::cerr << "[" << name_ << "]: Wrong input type in filterByDistance method." << std::endl;
}
void MatcherBase::filterByDistance(const KeyPointVector& _kpts1,
const KeyPointVector& _kpts2,
const DMatchVector& _raw_matches,
KeyPointVector& _inlier_kpts1,
KeyPointVector& _inlier_kpts2,
DMatchVector& _inlier_matches)
{
if (params_base_ptr_->match_type == MATCH)
{
_inlier_matches.reserve(_raw_matches.size());
for (size_t ii = 0; ii < _raw_matches.size(); ++ii)
{
cv::Point2f p1 = _kpts1[_raw_matches[ii].queryIdx].pt;
cv::Point2f p2 = _kpts2[_raw_matches[ii].trainIdx].pt;
//calculate local distance for each possible match
Scalar dist = std::sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
//save as best match if local distance is in specified area
if (dist < params_base_ptr_->max_match_euclidean_dist)
{
_inlier_matches.push_back(_raw_matches[ii]);
_inlier_kpts1.push_back(cv::KeyPoint(p1,1));
_inlier_kpts2.push_back(cv::KeyPoint(p2,1));
}
}
}
else
std::cerr << "[" << name_ << "]: Wrong input type in filterByDistance method." << std::endl;
}
void MatcherBase::filterByDistance(const KeyPointVector& _kpts1,
const KeyPointVector& _kpts2,
const std::vector< DMatchVector >& _raw_matches,
KeyPointVector& _inlier_kpts1,
KeyPointVector& _inlier_kpts2,
DMatchVector& _inlier_matches)
{
if (params_base_ptr_->match_type == KNNMATCH || params_base_ptr_->match_type == RADIUSMATCH)
{
_inlier_matches.reserve(_raw_matches.size());
for (size_t ii = 0; ii < _raw_matches.size(); ++ii)
{
for (unsigned int jj = 0; jj < _raw_matches[ii].size(); jj++)
{
cv::Point2f p1 = _kpts1[_raw_matches[ii][jj].queryIdx].pt;
cv::Point2f p2 = _kpts2[_raw_matches[ii][jj].trainIdx].pt;
//calculate local distance for each possible match
double dist = std::sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
//save as best match if local distance is in specified area and on same height
if (dist < params_base_ptr_->max_match_euclidean_dist)
{
_inlier_matches.push_back(_raw_matches[ii][jj]);
_inlier_kpts1.push_back(cv::KeyPoint(p2,1));
_inlier_kpts2.push_back(cv::KeyPoint(p1,1));
break;
}
}
}
}
else
std::cerr << "[" << name_ << "]: Wrong input type in filterByDistance method." << std::endl;
}
void MatcherBase::ransacTest(const KeyPointVector& _raw_kps1,
const KeyPointVector& _raw_kps2,
const DMatchVector& _raw_matches,
......
......@@ -36,11 +36,11 @@ enum MATCH_TYPE{
struct MatcherParamsBase: public ParamsBase
{
std::string type;
int match_type = MATCH; //< Type of Match. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
double min_norm_score; //< [-1..0]: awful match; 1: perfect match; out of [-1,1]: error
int match_type = MATCH; //< Type of Match. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
double min_norm_score; //< [-1..0]: awful match; 1: perfect match; out of [-1,1]: error
Scalar ransac_epipolar_distance; //< distance to epipolar line
Scalar ransac_confidence_prob; //< confidence probability
Scalar max_match_euclidean_dist; //< Maximum euclidean distance to consider a match as inlier
MatcherParamsBase(const std::string& _type): type(_type){}
virtual ~MatcherParamsBase(){}
};
......@@ -119,6 +119,20 @@ class MatcherBase : public VUBase, public std::enable_shared_from_this<MatcherBa
KeyPointVector& _filtered_kpts,
KeyPointVector& _filtered_kpts_prev);
void filterByDistance(const KeyPointVector& _kpts1,
const KeyPointVector& _kpts2,
const DMatchVector& _raw_matches,
KeyPointVector& _inlier_kpts1,
KeyPointVector& _inlier_kpts2,
DMatchVector& _inlier_matches);
void filterByDistance(const KeyPointVector& _kpts1,
const KeyPointVector& _kpts2,
const std::vector< DMatchVector >& _raw_matches,
KeyPointVector& _inlier_kpts1,
KeyPointVector& _inlier_kpts2,
DMatchVector& _inlier_matches);
// Factory method
static MatcherBasePtr create(const std::string& _unique_name,
const ParamsBasePtr _params);
......
......@@ -30,6 +30,7 @@ matcher:
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
algorithm:
type: "ACTIVESEARCH"
......
......@@ -5,4 +5,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -5,4 +5,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -5,4 +5,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -5,4 +5,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
......@@ -6,4 +6,5 @@ matcher:
match type: 1 # Match type. MATCH = 1, KNNMATCH = 2, RADIUSMATCH = 3
filtering:
ransac epipolar distance: 3 # Distance to epipolar [pixels]
ransac confidence prob: 0.97 # Confidence probability
\ No newline at end of file
ransac confidence prob: 0.97 # Confidence probability
max match euclidean dist: 20 # Max euclidean distance to consider a match as inlier
\ No newline at end of file
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