47 template<
typename MATCHING_ALGORITHM_T>
 
   50     MATCHING_ALGORITHM_T& matchingAlgorithm) {
 
   52   std::mutex* locks = 
new std::mutex[matchingAlgorithm.sizeB()];
 
   57   std::vector<std::vector<pairing_t> > vMyBest;
 
   59   vMyBest.resize(matchingAlgorithm.sizeA());
 
   62   vpairs.resize(matchingAlgorithm.sizeB(),
 
   63                 pairing_t(-1, std::numeric_limits<distance_t>::max()));
 
   68     jobs[i].iThreadID = i;
 
   69     jobs[i].vpairs = &vpairs;
 
   70     jobs[i].vMyBest = &vMyBest;
 
   71     jobs[i].mutexes = locks;
 
   92   matchingAlgorithm.reserveMatches(vpairs.size());
 
   95   const distance_t& const_distratiothres = matchingAlgorithm.distanceRatioThreshold();
 
   96   const distance_t& const_distthres = matchingAlgorithm.distanceThreshold();
 
   97   for (
size_t i = 0; i < vpairs.size(); ++i) {
 
   99       const std::vector<pairing_t>& best_matches_list =
 
  100           vMyBest[vpairs[i].indexA];
 
  104       if (best_matches_list[1].indexA != -1) {
 
  105         const distance_t& best_match_distance = best_matches_list[0].distance;
 
  106         const distance_t& second_best_match_distance = best_matches_list[1]
 
  109         if (best_match_distance == 0
 
  110             || second_best_match_distance / best_match_distance
 
  111                 > const_distratiothres) {
 
  112           matchingAlgorithm.setBestMatch(vpairs[i].indexA, i,
 
  117         matchingAlgorithm.setBestMatch(vpairs[i].indexA, i, vpairs[i].distance);
 
  119     } 
else if (vpairs[i].distance < const_distthres) {
 
  120       matchingAlgorithm.setBestMatch(vpairs[i].indexA, i, vpairs[i].distance);
 
  128 template<
typename MATCHING_ALGORITHM_T>
 
  130   typedef MATCHING_ALGORITHM_T matching_algorithm_t;
 
  131   matchingAlgorithm.doSetup();
 
  134   matchBody(&DenseMatcher::template doWorkLinearMatching<matching_algorithm_t>,
 
  139 template<
typename MATCHING_ALGORITHM_T>
 
  141   typedef MATCHING_ALGORITHM_T matching_algorithm_t;
 
  142   matchingAlgorithm.doSetup();
 
  146       &DenseMatcher::template doWorkImageSpaceMatching<matching_algorithm_t>,
 
  152 template<
typename MATCHING_ALGORITHM_T>
 
  154     MATCHING_ALGORITHM_T* matchingAlgorithm, std::vector<pairing_t>& aiBest,
 
  155     size_t shortindexA, 
size_t i) {
 
  157                     "matching algorithm is NULL");
 
  161   tmpdist = matchingAlgorithm->distance(shortindexA, i);
 
  162   if (tmpdist < aiBest[
numBest_ - 1].distance) {
 
  163     pairing_t tmp(static_cast<int>(i), tmpdist);
 
  164     typename std::vector<pairing_t>::iterator lb = std::lower_bound(
 
  165         aiBest.begin(), aiBest.end(), tmp);  
 
  166     typename std::vector<pairing_t>::iterator it, it_next;
 
  167     it = it_next = aiBest.end();
 
  172     while (it_next != lb) {
 
  182 template<
typename MATCHING_ALGORITHM_T>
 
  184     MatchJob & my_job, MATCHING_ALGORITHM_T * matchingAlgorithm) {
 
  186                     "matching algorithm is NULL");
 
  189     distance_t const_distthres = matchingAlgorithm->distanceThreshold();
 
  193       const_distthres = std::numeric_limits<distance_t>::max();
 
  196     size_t sizeA = matchingAlgorithm->sizeA();
 
  197     for (
size_t shortindexA = start; shortindexA < sizeA; shortindexA +=
 
  199       if (matchingAlgorithm->skipA(shortindexA))
 
  203       std::vector<pairing_t> & aiBest = (*my_job.
vMyBest)[shortindexA];
 
  209       size_t numElementsInListB = matchingAlgorithm->sizeB();
 
  210       for (
size_t i = 0; i < numElementsInListB; ++i) {
 
  211         if (matchingAlgorithm->skipB(i)) {
 
  221   } 
catch (
const std::exception & e) {
 
  223     std::cout << 
"\033[31mException in matching thread:\033[0m " << e.what();
 
  230 template<
typename MATCHING_ALGORITHM_T>
 
  232     MatchJob & my_job, MATCHING_ALGORITHM_T* matchingAlgorithm) {
 
  234                     "matching algorithm is NULL");
 
  238     size_t numElementsInListB = matchingAlgorithm->sizeB();
 
  239     size_t numElementsInListA = matchingAlgorithm->sizeA();
 
  241     distance_t const_distthres = matchingAlgorithm->distanceThreshold();
 
  245       const_distthres = std::numeric_limits<distance_t>::max();
 
  248     for (
size_t shortindexA = start; shortindexA < matchingAlgorithm->sizeA();
 
  250       if (matchingAlgorithm->skipA(shortindexA))
 
  254       std::vector<pairing_t>& aiBest = (*my_job.
vMyBest)[shortindexA];
 
  260       typename MATCHING_ALGORITHM_T::listB_tree_structure_t::iterator itBegin =
 
  261           matchingAlgorithm->getListBStartIterator(shortindexA);
 
  262       typename MATCHING_ALGORITHM_T::listB_tree_structure_t::iterator itEnd =
 
  263           matchingAlgorithm->getListBEndIterator(shortindexA);
 
  265       for (
typename MATCHING_ALGORITHM_T::listB_tree_structure_t::iterator it =
 
  266           itBegin; it != itEnd; ++it) {
 
  267         size_t i = it->second;
 
  269         if (matchingAlgorithm->skipB(i)) {
 
  281   } 
catch (
const std::exception & e) {
 
  283     std::cout << 
"\033[31mException in matching thread:\033[0m " << e.what();
 
unsigned char numBest_
The set number of best pairings to save. 
Definition: DenseMatcher.hpp:208
 
void doWorkLinearMatching(MatchJob &my_job, MATCHING_ALGORITHM_T *matchingAlgorithm)
The threading worker. This matches a keypoint with every other keypoint to find the best match...
Definition: DenseMatcher.hpp:183
 
A struct to save an index and distance pair. 
Definition: DenseMatcher.hpp:95
 
std::vector< std::vector< pairing_t > > * vMyBest
The list of best matches so far. 
Definition: DenseMatcher.hpp:134
 
std::unique_ptr< okvis::ThreadPool > matcherThreadPool_
The threads. 
Definition: DenseMatcher.hpp:211
 
void match(MATCHING_ALGORITHM_T &matchingAlgorithm)
Execute a matching algorithm. This is the fast, templated version. Use this. 
Definition: DenseMatcher.hpp:129
 
void assignbest(int myIndexScored, pairing_list_t &vPairsWithScore, std::vector< std::vector< pairing_t > > &aiBestList, std::mutex *locks, int startidx)
A recursive function that reassigns weak matches, if a stronger match is found for a particular point...
Definition: DenseMatcher.cpp:69
 
std::mutex * mutexes
Mutexes for read/write synchronization in assignment of best match. 
Definition: DenseMatcher.hpp:143
 
DenseMatcher::Pairing pairing_t
Definition: DenseMatcher.hpp:121
 
float distance_t
Definition: DenseMatcher.hpp:92
 
unsigned char numMatcherThreads_
The set number of threads. 
Definition: DenseMatcher.hpp:207
 
bool useDistanceRatioThreshold_
Use ratio of best and second best match instead of absolute threshold. 
Definition: DenseMatcher.hpp:209
 
A data struct for the worker thread. 
Definition: DenseMatcher.hpp:127
 
void matchInImageSpace(MATCHING_ALGORITHM_T &matchingAlgorithm)
Execute a matching algorithm implementing image space matching (i.e. match landmarks with features in...
Definition: DenseMatcher.hpp:140
 
int iThreadID
The thread ID of this job. 
Definition: DenseMatcher.hpp:137
 
std::vector< pairing_t > pairing_list_t
Definition: DenseMatcher.hpp:122
 
This class matches keypoints from two frames in parallel. 
Definition: DenseMatcher.hpp:59
 
DenseMatcher::pairing_list_t * vpairs
The list of pairs for this thread. 
Definition: DenseMatcher.hpp:140
 
void doWorkImageSpaceMatching(MatchJob &my_job, MATCHING_ALGORITHM_T *matchingAlgorithm)
The threading worker. This matches a keypoint with only a subset of the other keypoints to find the b...
Definition: DenseMatcher.hpp:231
 
void matchBody(void(DenseMatcher::*doWorkPtr)(MatchJob &, MATCHING_ALGORITHM_T *), MATCHING_ALGORITHM_T &matchingAlgorithm)
This function creates all the matching threads and assigns the best matches afterwards. 
Definition: DenseMatcher.hpp:48
 
#define OKVIS_ASSERT_TRUE_DBG(exceptionType, condition, message)
Definition: assert_macros.hpp:211
 
void listBIteration(MATCHING_ALGORITHM_T *matchingAlgorithm, std::vector< pairing_t > &aiBest, size_t shortindexA, size_t i)
This calculates the distance between to keypoint descriptors. If it is better than the /e numBest_ fo...
Definition: DenseMatcher.hpp:153
 
#define OKVIS_ASSERT_TRUE(exceptionType, condition, message)
Definition: assert_macros.hpp:111