Yash Chainani | 5458dea | 2022-06-29 21:05:02 -0700 | [diff] [blame] | 1 | #ifndef __OPENCV_FEATURES_2D_KAZE_UTILS_H__ |
| 2 | #define __OPENCV_FEATURES_2D_KAZE_UTILS_H__ |
| 3 | |
| 4 | #include <opencv2/core/cvdef.h> |
| 5 | |
| 6 | #include <cmath> |
| 7 | |
| 8 | /* ************************************************************************* */ |
| 9 | /** |
| 10 | * @brief This function computes the angle from the vector given by (X Y). From |
| 11 | * 0 to 2*Pi |
| 12 | */ |
| 13 | inline float getAngleV2(float x, float y) { |
| 14 | float theta = atan2f(y, x); |
| 15 | |
| 16 | if (theta >= 0) |
| 17 | return theta; |
| 18 | else |
| 19 | return theta + static_cast<float>(2.0f * CV_PI); |
| 20 | } |
| 21 | |
| 22 | /* ************************************************************************* */ |
| 23 | /** |
| 24 | * @brief This function computes the value of a 2D Gaussian function |
| 25 | * @param x X Position |
| 26 | * @param y Y Position |
| 27 | * @param sig Standard Deviation |
| 28 | */ |
| 29 | inline float gaussianV2(float x, float y, float sigma) { |
| 30 | return expf(-(x * x + y * y) / (2.0f * sigma * sigma)); |
| 31 | } |
| 32 | |
| 33 | /* ************************************************************************* */ |
| 34 | /** |
| 35 | * @brief This function checks descriptor limits |
| 36 | * @param x X Position |
| 37 | * @param y Y Position |
| 38 | * @param width Image width |
| 39 | * @param height Image height |
| 40 | */ |
| 41 | inline void checkDescriptorLimitsV2(int &x, int &y, int width, int height) { |
| 42 | if (x < 0) { |
| 43 | x = 0; |
| 44 | } |
| 45 | |
| 46 | if (y < 0) { |
| 47 | y = 0; |
| 48 | } |
| 49 | |
| 50 | if (x > width - 1) { |
| 51 | x = width - 1; |
| 52 | } |
| 53 | |
| 54 | if (y > height - 1) { |
| 55 | y = height - 1; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /* ************************************************************************* */ |
| 60 | /** |
| 61 | * @brief This function rounds float to nearest integer |
| 62 | * @param flt Input float |
| 63 | * @return dst Nearest integer |
| 64 | */ |
| 65 | inline int fRoundV2(float flt) { return (int)(flt + 0.5f); } |
| 66 | |
| 67 | #endif |