Exemplo n.º 1
0
inline void quality_test(cv::Ptr<quality::QualityBase> ptr, const TMat& cmp, const Scalar& expected, const std::size_t quality_maps_expected = 1, const bool empty_expected = false )
{
    std::vector<cv::Mat> qMats = {};
    ptr->getQualityMaps(qMats);
    EXPECT_TRUE( qMats.empty());

    quality_expect_near( expected, ptr->compute(cmp));

    if (empty_expected)
        EXPECT_TRUE(ptr->empty());
    else
        EXPECT_FALSE(ptr->empty());

    ptr->getQualityMaps(qMats);

    EXPECT_EQ( qMats.size(), quality_maps_expected);
    for (auto& qm : qMats)
    {
        EXPECT_GT(qm.rows, 0);
        EXPECT_GT(qm.cols, 0);
    }

    ptr->clear();
    EXPECT_TRUE(ptr->empty());
}
Exemplo n.º 2
0
  std::vector< cv::DMatch > SequenceAnalyzer::simple_matching(
    cv::Ptr<PointsMatcher> point_matcher,
    cv::Ptr<PointsMatcher> point_matcher1,
    unsigned int mininum_points_matches)
  {
    vector< cv::DMatch > matches_i_j;
    point_matcher->crossMatch( point_matcher1, matches_i_j );

    //First compute points matches:
    unsigned int size_match=matches_i_j.size( );
    vector<cv::Point2f> srcP;
    vector<cv::Point2f> destP;
    vector<uchar> status;

    //vector<KeyPoint> points1 = point_matcher->;
    for( size_t cpt = 0; cpt < size_match; ++cpt ){
      const cv::KeyPoint &key1 = point_matcher1->getKeypoint(
        matches_i_j[ cpt ].queryIdx );
      const cv::KeyPoint &key2 = point_matcher->getKeypoint(
        matches_i_j[ cpt ].trainIdx );
      srcP.push_back( cv::Point2f( key1.pt.x,key1.pt.y ) );
      destP.push_back( cv::Point2f( key2.pt.x,key2.pt.y ) );
      status.push_back( 1 );
    }

    //free some memory:
    point_matcher->clear();
    point_matcher1->clear();

    if( srcP.size()< mininum_points_matches )
      return matches_i_j;
    cv::Mat fundam = cv::findFundamentalMat( srcP, destP, status, cv::FM_RANSAC, 1 );

    unsigned int nbErrors = 0, nb_iter=0;
    //refine the mathing :
    size_match = status.size( );
    for( size_t cpt = 0; cpt < size_match; ++cpt ){
      if( status[ cpt ] == 0 )
      {
        size_match--;
        status[ cpt ] = status[ size_match ];
        status.pop_back( );
        srcP[ cpt ] = srcP[ size_match ];
        srcP.pop_back( );
        destP[ cpt ] = destP[ size_match ];
        destP.pop_back( );
        matches_i_j[ cpt ] = matches_i_j[ size_match ];
        matches_i_j.pop_back( );
        cpt--;
        ++nbErrors;
      }
    }

    if( srcP.size()< mininum_points_matches )
      return matches_i_j;

    //refine the mathing:
    fundam = cv::findFundamentalMat( srcP, destP, status, cv::FM_LMEDS );

    size_match = status.size( );
    for( size_t cpt = 0; cpt < size_match; ++cpt ){
      if( status[ cpt ] == 0 )
      {
        size_match--;
        status[ cpt ] = status[ size_match ];
        status.pop_back( );
        srcP[ cpt ] = srcP[ size_match ];
        srcP.pop_back( );
        destP[ cpt ] = destP[ size_match ];
        destP.pop_back( );
        matches_i_j[ cpt ] = matches_i_j[ size_match ];
        matches_i_j.pop_back( );
        cpt--;
        ++nbErrors;
      }
    }
    return matches_i_j;
  };