/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using af::dim4;
using std::abs;
using std::endl;
using std::string;
using std::vector;
typedef struct {
float f[5];
} feat_t;
static bool feat_cmp(feat_t i, feat_t j) {
for (int k = 0; k < 5; k++)
if (i.f[k] != j.f[k]) return (i.f[k] < j.f[k]);
return false;
}
static void array_to_feat(vector &feat, float *x, float *y,
float *score, float *orientation, float *size,
unsigned nfeat) {
feat.resize(nfeat);
for (unsigned i = 0; i < feat.size(); i++) {
feat[i].f[0] = x[i];
feat[i].f[1] = y[i];
feat[i].f[2] = score[i];
feat[i].f[3] = orientation[i];
feat[i].f[4] = size[i];
}
}
template
class FloatFAST : public ::testing::Test {
public:
virtual void SetUp() {}
};
template
class FixedFAST : public ::testing::Test {
public:
virtual void SetUp() {}
};
typedef ::testing::Types FloatTestTypes;
typedef ::testing::Types FixedTestTypes;
TYPED_TEST_SUITE(FloatFAST, FloatTestTypes);
TYPED_TEST_SUITE(FixedFAST, FixedTestTypes);
template
void fastTest(string pTestFile, bool nonmax) {
SUPPORTED_TYPE_CHECK(T);
IMAGEIO_ENABLED_CHECK();
vector inDims;
vector inFiles;
vector gold;
readImageTests(pTestFile, inDims, inFiles, gold);
size_t testCount = inDims.size();
for (size_t testId = 0; testId < testCount; ++testId) {
dim_t nElems = 0;
af_array inArray_f32 = 0;
af_array inArray = 0;
af_features out;
inFiles[testId].insert(0, string(TEST_DIR "/fast/"));
ASSERT_SUCCESS(
af_load_image(&inArray_f32, inFiles[testId].c_str(), false));
ASSERT_SUCCESS(conv_image(&inArray, inArray_f32));
ASSERT_SUCCESS(af_fast(&out, inArray, 20.0f, 9, nonmax, 0.05f, 3));
dim_t n = 0;
af_array x, y, score, orientation, size;
ASSERT_SUCCESS(af_get_features_num(&n, out));
ASSERT_SUCCESS(af_get_features_xpos(&x, out));
ASSERT_SUCCESS(af_get_features_ypos(&y, out));
ASSERT_SUCCESS(af_get_features_score(&score, out));
ASSERT_SUCCESS(af_get_features_orientation(&orientation, out));
ASSERT_SUCCESS(af_get_features_size(&size, out));
ASSERT_SUCCESS(af_get_elements(&nElems, x));
float *outX = new float[gold[0].size()];
float *outY = new float[gold[1].size()];
float *outScore = new float[gold[2].size()];
float *outOrientation = new float[gold[3].size()];
float *outSize = new float[gold[4].size()];
ASSERT_SUCCESS(af_get_data_ptr((void *)outX, x));
ASSERT_SUCCESS(af_get_data_ptr((void *)outY, y));
ASSERT_SUCCESS(af_get_data_ptr((void *)outScore, score));
ASSERT_SUCCESS(af_get_data_ptr((void *)outOrientation, orientation));
ASSERT_SUCCESS(af_get_data_ptr((void *)outSize, size));
vector out_feat;
array_to_feat(out_feat, outX, outY, outScore, outOrientation, outSize,
n);
vector 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)nElems; elIter++) {
ASSERT_EQ(out_feat[elIter].f[0], gold_feat[elIter].f[0])