Esempio n. 1
0
void QDescriptorMatcher::match(QMat* queryDescriptors, QDMatchVector* matches){
    if ( m_knn != -1 ){
        knnMatch(queryDescriptors, matches, m_knn);
    } else {
        if ( m_matcher ){
            try{
                if ( matches->matches().size() != 1)
                    matches->matches().resize(1);
                if ( queryDescriptors->cvMat()->cols == 0 )
                    return;
                m_matcher->match(*queryDescriptors->cvMat(), matches->matches()[0] );
                m_matches->setType(QDMatchVector::BEST_MATCH);
            } catch ( cv::Exception& e ){
                qCritical("Descriptor matcher: %s", e.what());
            }
        }
    }
}
bool
OrbLocationRecognition::detectSimilarLocations(const FrameConstPtr& frame, int k,
                                               std::vector<FrameConstPtr>& matches)
{
    std::vector<DVision::ORB::bitset> features = frameToFeatures(frame);

    FrameTag tag;
    tag.frameSetSegmentId = 0;
    tag.frameSetId = frame->frameSet()->seq();
    tag.frameId = frame->cameraId();

    m_dbMutex.lock();

    m_frameTagMap.insert(std::make_pair(tag, m_frameTagMap.size()));
    m_frameTags.push_back(tag);
    m_frames.push_back(frame);

    m_dbMutex.unlock();

    std::vector<FrameConstPtr> rawMatches;
    knnMatch(frame, k, rawMatches);

    matches.reserve(rawMatches.size());
    for (size_t i = 0; i < rawMatches.size(); ++i)
    {
        FrameConstPtr& match = rawMatches.at(i);

        if (std::abs(tag.frameSetId - match->frameSet()->seq()) < 10)
        {
            continue;
        }

        matches.push_back(match);
    }

    m_dbMutex.lock();

    m_db.add(features);

    m_dbMutex.unlock();

    return !matches.empty();
}