void _hammingmatch_lowetest_slow(const cv::Mat &_des1, const cv::Mat &_des2, MatchList &_good, const float ratio){ // compute and copmare norms row by row int _n1 = _des1.rows; int _n2 = _des2.rows; int _idx, _mindist1, _mindist2; cv::DMatch _mtch; for ( int _i = 0; _i < _n1; ++_i ){ _idx=-1; _mindist1 = 10000; _mindist2 = 1000000; // some arbirtrary large value for initializing // compute best idx for row _i of _des1 for ( int _j = 0; _j < _n2; ++_j ){ // calculate hamming distance int _val = cv::normHamming(_des1.row(_i).data, _des2.row(_j).data, 4); if ( _val > 8) {continue;} // skip to make it fast _val = cv::normHamming(_des1.row(_i).data, _des2.row(_j).data, _des2.cols); if ( _val < _mindist2 ){ if ( _val < _mindist1 ){ _mindist2 = _mindist1; _mindist1 = _val; _idx = _j; } else _mindist2 = _val; } } // ratio test if ( (_idx != -1) && (_mindist1 < (_mindist2 * ratio ))){ // all is okay printf("distance %d: %d\n", _i, _mindist1); _mtch.distance = _mindist1; _mtch.queryIdx = _i; // the first _mtch.trainIdx = _idx; // the second _good.push_back(_mtch); } } }
void HammingMatchBatch::getResult(MatchList &good) const{ good.clear(); cv::DMatch _mtch; for ( int _i = 0; _i < this->result.rows; ++_i){ _mtch.queryIdx = this->result.at<int>(_i, 0); _mtch.trainIdx = this->result.at<int>(_i, 1); _mtch.distance = this->result.at<int>(_i, 2); if ( _mtch.queryIdx != -1 ) good.push_back(_mtch); } }
MatchList filterPlatformMatches(const Game *g, std::pair<ExtractMap::const_iterator, ExtractMap::const_iterator> range) { bool hasPlatformMatch = false; for (ExtractMap::const_iterator i = range.first; i != range.second; ++i) { if (i->second.desc.platform == g->platform) { hasPlatformMatch = true; break; } } MatchList result; if (hasPlatformMatch) { for (ExtractMap::const_iterator i = range.first; i != range.second; ++i) { if (i->second.desc.platform == g->platform) result.push_back(i); } } else { for (ExtractMap::const_iterator i = range.first; i != range.second; ++i) result.push_back(i); } return result; }
void _hammingmatchserial(const cv::Mat &des1, const cv::Mat &des2, MatchList &good, const float ratio){ int _n1 = des1.rows; int dist, idx; cv::DMatch _mtch; int step = des1.step / sizeof(des1.ptr()[0]); for (int _i = 0; _i < _n1; ++_i){ if ( des2.cols == 64 ){ idx = _bestmatch64(des1.data+step*_i, des2, dist, ratio, FASTHAMMING_FREAK_PARSCORE); } else { idx = _bestmatch64(des1.data+step*_i, des2, dist, ratio); } if ( idx != -1){ _mtch.distance = dist; _mtch.queryIdx = _i; _mtch.trainIdx = idx; good.push_back(_mtch); } } }