utils.h 2.11 KB
Newer Older
wester committed
1 2 3
#ifndef __OPENCV_FEATURES_2D_KAZE_UTILS_H__
#define __OPENCV_FEATURES_2D_KAZE_UTILS_H__

a  
Kai Westerkamp committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* ************************************************************************* */
/**
 * @brief This function computes the angle from the vector given by (X Y). From 0 to 2*Pi
 */
inline float getAngle(float x, float y) {

  if (x >= 0 && y >= 0) {
    return atanf(y / x);
  }

  if (x < 0 && y >= 0) {
    return static_cast<float>(CV_PI)-atanf(-y / x);
  }

  if (x < 0 && y < 0) {
    return static_cast<float>(CV_PI)+atanf(y / x);
  }

  if (x >= 0 && y < 0) {
    return static_cast<float>(2.0 * CV_PI) - atanf(-y / x);
  }

  return 0;
}

wester committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/* ************************************************************************* */
/**
 * @brief This function computes the value of a 2D Gaussian function
 * @param x X Position
 * @param y Y Position
 * @param sig Standard Deviation
 */
inline float gaussian(float x, float y, float sigma) {
  return expf(-(x*x + y*y) / (2.0f*sigma*sigma));
}

/* ************************************************************************* */
/**
 * @brief This function checks descriptor limits
 * @param x X Position
 * @param y Y Position
 * @param width Image width
 * @param height Image height
 */
inline void checkDescriptorLimits(int &x, int &y, int width, int height) {

  if (x < 0) {
    x = 0;
  }

  if (y < 0) {
    y = 0;
  }

  if (x > width - 1) {
    x = width - 1;
  }

  if (y > height - 1) {
    y = height - 1;
  }
}

a  
Kai Westerkamp committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
/* ************************************************************************* */
/**
 * @brief This funtion rounds float to nearest integer
 * @param flt Input float
 * @return dst Nearest integer
 */
inline int fRound(float flt) {
  return (int)(flt + 0.5f);
}

/* ************************************************************************* */
/**
 * @brief Exponentiation by squaring
 * @param flt Exponentiation base
 * @return dst Exponentiation value
 */
inline int fastpow(int base, int exp) {
    int res = 1;
    while(exp > 0) {
        if(exp & 1) {
            exp--;
            res *= base;
        } else {
            exp /= 2;
            base *= base;
        }
    }
    return res;
}

wester committed
97
#endif