/******************************************************* * 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 using af::dim4; using namespace detail; template static void sift(af_features& feat_, af_array& descriptors, const af_array& in, const unsigned n_layers, const float contrast_thr, const float edge_thr, const float init_sigma, const bool double_input, const float img_scale, const float feature_ratio, const bool compute_GLOH) { Array x = createEmptyArray(dim4()); Array y = createEmptyArray(dim4()); Array score = createEmptyArray(dim4()); Array ori = createEmptyArray(dim4()); Array size = createEmptyArray(dim4()); Array desc = createEmptyArray(dim4()); af_features_t feat; feat.n = sift(x, y, score, ori, size, desc, getArray(in), n_layers, contrast_thr, edge_thr, init_sigma, double_input, img_scale, feature_ratio, compute_GLOH); feat.x = getHandle(x); feat.y = getHandle(y); feat.score = getHandle(score); feat.orientation = getHandle(ori); feat.size = getHandle(size); feat_ = getFeaturesHandle(feat); descriptors = getHandle(desc); } af_err af_sift(af_features* feat, af_array* desc, const af_array in, const unsigned n_layers, const float contrast_thr, const float edge_thr, const float init_sigma, const bool double_input, const float img_scale, const float feature_ratio) { try { #ifdef AF_BUILD_NONFREE_SIFT ArrayInfo info = getInfo(in); af::dim4 dims = info.dims(); ARG_ASSERT(2, (dims[0] >= 15 && dims[1] >= 15 && dims[2] == 1 && dims[3] == 1)); ARG_ASSERT(3, n_layers > 0); ARG_ASSERT(4, contrast_thr > 0.0f); ARG_ASSERT(5, edge_thr >= 1.0f); ARG_ASSERT(6, init_sigma > 0.5f); ARG_ASSERT(8, img_scale > 0.0f); ARG_ASSERT(9, feature_ratio > 0.0f); dim_t in_ndims = dims.ndims(); DIM_ASSERT(1, (in_ndims <= 3 && in_ndims >= 2)); af_array tmp_desc; af_dtype type = info.getType(); switch(type) { case f32: sift(*feat, tmp_desc, in, n_layers, contrast_thr, edge_thr, init_sigma, double_input, img_scale, feature_ratio, false); break; case f64: sift(*feat, tmp_desc, in, n_layers, contrast_thr, edge_thr, init_sigma, double_input, img_scale, feature_ratio, false); break; default : TYPE_ERROR(1, type); } std::swap(*desc, tmp_desc); #else AF_ERROR("ArrayFire was not built with nonfree support, SIFT disabled\n", AF_ERR_NONFREE); #endif } CATCHALL; return AF_SUCCESS; } af_err af_gloh(af_features* feat, af_array* desc, const af_array in, const unsigned n_layers, const float contrast_thr, const float edge_thr, const float init_sigma, const bool double_input, const float img_scale, const float feature_ratio) { try { #ifdef AF_BUILD_NONFREE_SIFT ArrayInfo info = getInfo(in); af::dim4 dims = info.dims(); ARG_ASSERT(2, (dims[0] >= 15 && dims[1] >= 15 && dims[2] == 1 && dims[3] == 1)); ARG_ASSERT(3, n_layers > 0); ARG_ASSERT(4, contrast_thr > 0.0f); ARG_ASSERT(5, edge_thr >= 1.0f); ARG_ASSERT(6, init_sigma > 0.5f); ARG_ASSERT(8, img_scale > 0.0f); ARG_ASSERT(9, feature_ratio > 0.0f); dim_t in_ndims = dims.ndims(); DIM_ASSERT(1, (in_ndims <= 3 && in_ndims >= 2)); af_array tmp_desc; af_dtype type = info.getType(); switch(type) { case f32: sift(*feat, tmp_desc, in, n_layers, contrast_thr, edge_thr, init_sigma, double_input, img_scale, feature_ratio, true); break; case f64: sift(*feat, tmp_desc, in, n_layers, contrast_thr, edge_thr, init_sigma, double_input, img_scale, feature_ratio, true); break; default : TYPE_ERROR(1, type); } std::swap(*desc, tmp_desc); #else AF_ERROR("ArrayFire was not built with nonfree support, GLOH disabled\n", AF_ERR_NONFREE); #endif } CATCHALL; return AF_SUCCESS; }