예제 #1
0
///////////////////////////////////// CPP ////////////////////////////////
//
TEST(Transform, CPP)
{
    if (noImageIOTests()) return;

    vector<dim4>   inDims;
    vector<string> inFiles;
    vector<dim_t>  goldDim;
    vector<string> goldFiles;

    vector<dim4> HDims;
    vector<vector<float> >   HIn;
    vector<vector<float> >   HTests;
    readTests<float, float, float>(TEST_DIR"/transform/tux_tmat.test",HDims,HIn,HTests);

    readImageTests(string(TEST_DIR"/transform/tux_nearest.test"), inDims, inFiles, goldDim, goldFiles);

    inFiles[0].insert(0,string(TEST_DIR"/transform/"));
    inFiles[1].insert(0,string(TEST_DIR"/transform/"));

    goldFiles[0].insert(0,string(TEST_DIR"/transform/"));

    array H = array(HDims[0][0], HDims[0][1], &(HIn[0].front()));
    array IH = array(HDims[0][0], HDims[0][1], &(HIn[0].front()));

    array scene_img = loadImage(inFiles[1].c_str(), false);

    array gold_img = loadImage(goldFiles[0].c_str(), false);

    array out_img = transform(scene_img, IH, inDims[0][0], inDims[0][1], AF_INTERP_NEAREST, false);

    dim4 outDims = out_img.dims();
    dim4 goldDims = gold_img.dims();

    vector<float> h_out_img(outDims[0] * outDims[1]);
    out_img.host(&h_out_img.front());
    vector<float> h_gold_img(goldDims[0] * goldDims[1]);
    gold_img.host(&h_gold_img.front());

    const dim_t n = gold_img.elements();
    const float thr = 1.0f;

    // Maximum number of wrong pixels must be <= 0.01% of number of elements,
    // this metric is necessary due to rounding errors between different
    // backends for AF_INTERP_NEAREST and AF_INTERP_LOWER
    const size_t maxErr = n * 0.0001f;
    size_t err = 0;

    for (dim_t elIter = 0; elIter < n; elIter++) {
        err += fabs((int)h_out_img[elIter] - h_gold_img[elIter]) > thr;
        if (err > maxErr) {
            ASSERT_LE(err, maxErr) << "at: " << elIter << endl;
        }
    }
}
예제 #2
0
파일: susan.cpp 프로젝트: 9prady9/arrayfire
void susanTest(string pTestFile, float t, float g) {
    SUPPORTED_TYPE_CHECK(T);
    if (noImageIOTests()) return;

    vector<dim4> inDims;
    vector<string> inFiles;
    vector<vector<float> > gold;

    readImageTests(pTestFile, inDims, inFiles, gold);

    size_t testCount = inDims.size();

    for (size_t testId = 0; testId < testCount; ++testId) {
        inFiles[testId].insert(0, string(TEST_DIR "/susan/"));

        array in = loadImage(inFiles[testId].c_str(), false);

        features out = susan(in, 3, t, g, 0.05f, 3);

        vector<float> outX(gold[0].size());
        vector<float> outY(gold[1].size());
        vector<float> outScore(gold[2].size());
        vector<float> outOrientation(gold[3].size());
        vector<float> outSize(gold[4].size());
        out.getX().host(outX.data());
        out.getY().host(outY.data());
        out.getScore().host(outScore.data());
        out.getOrientation().host(outOrientation.data());
        out.getSize().host(outSize.data());

        vector<feat_t> out_feat;
        array_to_feat(out_feat, outX.data(), outY.data(), outScore.data(),
                      outOrientation.data(), outSize.data(),
                      out.getNumFeatures());

        vector<feat_t> gold_feat;
        array_to_feat(gold_feat, &gold[0].front(), &gold[1].front(),
                      &gold[2].front(), &gold[3].front(), &gold[4].front(),
                      gold[0].size());

        std::sort(out_feat.begin(), out_feat.end(), feat_cmp);
        std::sort(gold_feat.begin(), gold_feat.end(), feat_cmp);

        for (int elIter = 0; elIter < (int)out.getNumFeatures(); elIter++) {
            ASSERT_EQ(out_feat[elIter].f[0], gold_feat[elIter].f[0])
                << "at: " << elIter << endl;
            ASSERT_EQ(out_feat[elIter].f[1], gold_feat[elIter].f[1])
                << "at: " << elIter << endl;
            ASSERT_LE(fabs(out_feat[elIter].f[2] - gold_feat[elIter].f[2]), 1e2)
                << "at: " << elIter << endl;
            ASSERT_EQ(out_feat[elIter].f[3], gold_feat[elIter].f[3])
                << "at: " << elIter << endl;
            ASSERT_EQ(out_feat[elIter].f[4], gold_feat[elIter].f[4])
                << "at: " << elIter << endl;
        }
    }
}