TEST_P(EstimateAffinePartial2D, test2Points)
{
    // try more transformations
    for (size_t i = 0; i < 500; ++i)
    {
        Mat aff = rngPartialAffMat();

        // setting points that are no in the same line
        Mat fpts(1, 2, CV_32FC2);
        Mat tpts(1, 2, CV_32FC2);

        fpts.at<Point2f>(0) = Point2f( rngIn(1,2), rngIn(5,6) );
        fpts.at<Point2f>(1) = Point2f( rngIn(3,4), rngIn(3,4) );

        transform(fpts, tpts, aff);

        vector<uchar> inliers;
        Mat aff_est = estimateAffinePartial2D(fpts, tpts, inliers, GetParam() /* method */);

        EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3);

        // all must be inliers
        EXPECT_EQ(countNonZero(inliers), 2);
    }
}
// test conversion from other datatypes than float
TEST_P(EstimateAffinePartial2D, testConversion)
{
    Mat aff = rngPartialAffMat();
    aff.convertTo(aff, CV_32S); // convert to int to transform ints properly

    std::vector<Point> fpts(3);
    std::vector<Point> tpts(3);

    fpts[0] = Point2f( rngIn(1,2), rngIn(5,6) );
    fpts[1] = Point2f( rngIn(3,4), rngIn(3,4) );
    fpts[2] = Point2f( rngIn(1,2), rngIn(3,4) );

    transform(fpts, tpts, aff);

    vector<uchar> inliers;
    Mat aff_est = estimateAffinePartial2D(fpts, tpts, inliers, GetParam() /* method */);

    ASSERT_FALSE(aff_est.empty());

    aff.convertTo(aff, CV_64F); // need to convert back before compare
    EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3);

    // all must be inliers
    EXPECT_EQ(countNonZero(inliers), 3);
}
示例#3
0
PERF_TEST_P( EstimateAffine, EstimateAffinePartial2D, ESTIMATE_PARAMS )
{
    AffineParams params = GetParam();
    const int n = get<0>(params);
    const double confidence = get<1>(params);
    const int method = get<2>(params);
    const size_t refining = get<3>(params);

    Mat aff = rngPartialAffMat();

    int m;
    // LMEDS can't handle more than 50% outliers (by design)
    if (method == LMEDS)
        m = 3*n/5;
    else
        m = 2*n/5;
    const float shift_outl = 15.f;    const float noise_level = 20.f;

    Mat fpts(1, n, CV_32FC2);
    Mat tpts(1, n, CV_32FC2);

    randu(fpts, 0., 100.);
    transform(fpts, tpts, aff);

    /* adding noise*/
    Mat outliers = tpts.colRange(m, n);
    outliers.reshape(1) += shift_outl;

    Mat noise (outliers.size(), outliers.type());
    randu(noise, 0., noise_level);
    outliers += noise;

    Mat aff_est;
    vector<uchar> inliers (n);

    warmup(inliers, WARMUP_WRITE);
    warmup(fpts, WARMUP_READ);
    warmup(tpts, WARMUP_READ);

    TEST_CYCLE()
    {
        aff_est = estimateAffinePartial2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);
    }

    // we already have accuracy tests
    SANITY_CHECK_NOTHING();
}
TEST_P(EstimateAffinePartial2D, testNPoints)
{
    // try more transformations
    for (size_t i = 0; i < 500; ++i)
    {
        Mat aff = rngPartialAffMat();

        const int method = GetParam();
        const int n = 100;
        int m;
        // LMEDS can't handle more than 50% outliers (by design)
        if (method == LMEDS)
            m = 3*n/5;
        else
            m = 2*n/5;
        const float shift_outl = 15.f;
        const float noise_level = 20.f;

        Mat fpts(1, n, CV_32FC2);
        Mat tpts(1, n, CV_32FC2);

        randu(fpts, 0., 100.);
        transform(fpts, tpts, aff);

        /* adding noise to some points */
        Mat outliers = tpts.colRange(m, n);
        outliers.reshape(1) += shift_outl;

        Mat noise (outliers.size(), outliers.type());
        randu(noise, 0., noise_level);
        outliers += noise;

        vector<uchar> inliers;
        Mat aff_est = estimateAffinePartial2D(fpts, tpts, inliers, method);

        EXPECT_FALSE(aff_est.empty());

        EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-4);

        bool inliers_good = count(inliers.begin(), inliers.end(), 1) == m &&
            m == accumulate(inliers.begin(), inliers.begin() + m, 0);

        EXPECT_TRUE(inliers_good);
    }
}