[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/arrayfire/arrayfire/feature/optional-graphics/test/gloh.cpp [Back]  [Original]

/*******************************************************
 * Copyright (c) 2015, 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[272];
} feat_desc_t;

typedef struct {
    float f[5];
} feat_t;

typedef struct {
    float d[272];
} desc_t;

static bool feat_cmp(feat_desc_t i, feat_desc_t j) {
    for (int k = 0; k < 5; k++)
        if (round(i.f[k] * 1e1f) != round(j.f[k] * 1e1f))
            return (round(i.f[k] * 1e1f) < round(j.f[k] * 1e1f));

    return false;
}

static void array_to_feat_desc(vector& feat, float* x, float* y,
                               float* score, float* ori, float* size,
                               float* 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 < 272; j++) feat[i].d[j] = desc[i * 272 + 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 < 272; 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 < 272; j++) d[i].d[j] = fd[i].d[j];
    }
}

static bool compareEuclidean(dim_t desc_len, dim_t ndesc, float* cpu,
                             float* gpu, float unit_thr = 1.f,
                             float euc_thr = 1.f) {
    bool ret  = true;
    float sum = 0.0f;

    for (dim_t i = 0; i < ndesc; i++) {
        sum = 0.0f;
        for (dim_t l = 0; l < desc_len; l++) {
            dim_t idx = i * desc_len + l;
            float x   = (cpu[idx] - gpu[idx]);
            sum += x * x;
            if (abs(x) > (float)unit_thr) {
                ret = false;
                cout 

Web Proxy Viewer  |  New URL  |  Original Page