/*******************************************************
* 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::array;
using af::dim4;
using af::features;
using af::loadImage;
using std::abs;
using std::cout;
using std::endl;
using std::string;
using std::vector;
typedef struct {
float f[5];
unsigned d[8];
} feat_desc_t;
typedef struct {
float f[5];
} feat_t;
typedef struct {
unsigned d[8];
} desc_t;
static bool feat_cmp(feat_desc_t i, feat_desc_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_desc(vector& feat, float* x, float* y,
float* score, float* ori, float* size,
unsigned* desc, unsigned nfeat) {
feat.resize(nfeat);
for (size_t 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] = ori[i];
feat[i].f[4] = size[i];
for (unsigned j = 0; j < 8; j++) feat[i].d[j] = desc[i * 8 + j];
}
}
static void array_to_feat_desc(vector& feat, float* x, float* y,
float* score, float* ori, float* size,
vector& desc, unsigned nfeat) {
feat.resize(nfeat);
for (size_t 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] = ori[i];
feat[i].f[4] = size[i];
for (unsigned j = 0; j < 8; j++) feat[i].d[j] = desc[i][j];
}
}
static void split_feat_desc(vector& fd, vector& f,
vector& d) {
f.resize(fd.size());
d.resize(fd.size());
for (size_t i = 0; i < fd.size(); i++) {
f[i].f[0] = fd[i].f[0];
f[i].f[1] = fd[i].f[1];
f[i].f[2] = fd[i].f[2];
f[i].f[3] = fd[i].f[3];
f[i].f[4] = fd[i].f[4];
for (unsigned j = 0; j < 8; j++) d[i].d[j] = fd[i].d[j];
}
}
static unsigned popcount(unsigned x) {
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0F0F0F0F;
x = x + (x >> 8);
x = x + (x >> 16);
return x & 0x0000003F;
}
bool compareHamming(int data_size, unsigned* cpu, unsigned* gpu,
unsigned thr = 1) {
bool ret = true;
for (int i = 0; i < data_size; i++) {
unsigned x = (cpu[i] ^ gpu[i]);
if (popcount(x) > thr) {
ret = false;
cout