~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/modules/features2d/src/kaze/utils.h

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __OPENCV_FEATURES_2D_KAZE_UTILS_H__
 
2
#define __OPENCV_FEATURES_2D_KAZE_UTILS_H__
 
3
 
 
4
/* ************************************************************************* */
 
5
/**
 
6
 * @brief This function computes the angle from the vector given by (X Y). From 0 to 2*Pi
 
7
 */
 
8
inline float getAngle(float x, float y) {
 
9
 
 
10
  if (x >= 0 && y >= 0) {
 
11
    return atanf(y / x);
 
12
  }
 
13
 
 
14
  if (x < 0 && y >= 0) {
 
15
    return static_cast<float>(CV_PI)-atanf(-y / x);
 
16
  }
 
17
 
 
18
  if (x < 0 && y < 0) {
 
19
    return static_cast<float>(CV_PI)+atanf(y / x);
 
20
  }
 
21
 
 
22
  if (x >= 0 && y < 0) {
 
23
    return static_cast<float>(2.0 * CV_PI) - atanf(-y / x);
 
24
  }
 
25
 
 
26
  return 0;
 
27
}
 
28
 
 
29
/* ************************************************************************* */
 
30
/**
 
31
 * @brief This function computes the value of a 2D Gaussian function
 
32
 * @param x X Position
 
33
 * @param y Y Position
 
34
 * @param sig Standard Deviation
 
35
 */
 
36
inline float gaussian(float x, float y, float sigma) {
 
37
  return expf(-(x*x + y*y) / (2.0f*sigma*sigma));
 
38
}
 
39
 
 
40
/* ************************************************************************* */
 
41
/**
 
42
 * @brief This function checks descriptor limits
 
43
 * @param x X Position
 
44
 * @param y Y Position
 
45
 * @param width Image width
 
46
 * @param height Image height
 
47
 */
 
48
inline void checkDescriptorLimits(int &x, int &y, int width, int height) {
 
49
 
 
50
  if (x < 0) {
 
51
    x = 0;
 
52
  }
 
53
 
 
54
  if (y < 0) {
 
55
    y = 0;
 
56
  }
 
57
 
 
58
  if (x > width - 1) {
 
59
    x = width - 1;
 
60
  }
 
61
 
 
62
  if (y > height - 1) {
 
63
    y = height - 1;
 
64
  }
 
65
}
 
66
 
 
67
/* ************************************************************************* */
 
68
/**
 
69
 * @brief This funtion rounds float to nearest integer
 
70
 * @param flt Input float
 
71
 * @return dst Nearest integer
 
72
 */
 
73
inline int fRound(float flt) {
 
74
  return (int)(flt + 0.5f);
 
75
}
 
76
 
 
77
/* ************************************************************************* */
 
78
/**
 
79
 * @brief Exponentiation by squaring
 
80
 * @param flt Exponentiation base
 
81
 * @return dst Exponentiation value
 
82
 */
 
83
inline int fastpow(int base, int exp) {
 
84
    int res = 1;
 
85
    while(exp > 0) {
 
86
        if(exp & 1) {
 
87
            exp--;
 
88
            res *= base;
 
89
        } else {
 
90
            exp /= 2;
 
91
            base *= base;
 
92
        }
 
93
    }
 
94
    return res;
 
95
}
 
96
 
 
97
#endif