From 2d2ab7632a53e6c70178799f20d03f7f22d0bc05 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 5 Apr 2022 19:54:39 +0200 Subject: [PATCH] update after reducing math.h dependency --- Image/BillDetection.h | 3 --- Image/Skew.h | 13 ++++++------- Image/Thresholding.h | 8 ++++---- Utils/MathUtils.h | 10 +++++----- Utils/TestUtils.h | 2 +- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Image/BillDetection.h b/Image/BillDetection.h index 6c246c9..4907cf9 100644 --- a/Image/BillDetection.h +++ b/Image/BillDetection.h @@ -11,12 +11,9 @@ #define IMAGE_BILL_DETECTION_H #include -#include #include #include -#include "../Utils/MathUtils.h" - namespace Image { class BillDetection { private: diff --git a/Image/Skew.h b/Image/Skew.h index 90d5ffd..88b8887 100644 --- a/Image/Skew.h +++ b/Image/Skew.h @@ -11,7 +11,6 @@ #define IMAGE_SKEW_H #include -#include #include #include @@ -32,26 +31,26 @@ namespace Image { cv::threshold(inv, inv, 0, 255, cv::THRESH_BINARY_INV | cv::THRESH_OTSU); std::vector lines; - cv::HoughLinesP(inv, lines, 1.0, M_PI / 180, 200, dim.width / 12, dim.width / 150); + cv::HoughLinesP(inv, lines, 1.0, OMS_PI / 180, 200, dim.width / 12, dim.width / 150); - int imageOrientation = 0; // > 0 -> horizontal + int imageOrientation = 0; // > 0 -> image is horizontal std::vector tmpAngles; for (int i = 0; i < lines.size(); ++i) { float angle = atan2(lines[i][3] - lines[i][1], lines[i][2] - lines[i][0]); tmpAngles.push_back(angle); - imageOrientation += abs(angle) > M_PI / 4 ? 1 : -1; + imageOrientation += oms_abs(angle) > OMS_PI / 4 ? 1 : -1; } std::vector angles; for (int i = 0; i < tmpAngles.size(); ++i) { if (imageOrientation > 0) { - if (deg2rad(90 - maxDegree) < abs(tmpAngles[i]) < deg2rad(90 + maxDegree)) { + if (oms_deg2rad(90 - maxDegree) < oms_abs(tmpAngles[i]) < oms_deg2rad(90 + maxDegree)) { angles.push_back(tmpAngles[i]); } } else { - if (abs(tmpAngles[i]) < deg2rad(maxDegree)) { + if (oms_abs(tmpAngles[i]) < oms_deg2rad(maxDegree)) { angles.push_back(tmpAngles[i]); } } @@ -66,7 +65,7 @@ namespace Image { median += angles[i]; } - float angleDeg = rad2deg(median / angles.size()); + float angleDeg = oms_rad2deg(median / angles.size()); cv::Mat orientFix; if (imageOrientation > 0) { diff --git a/Image/Thresholding.h b/Image/Thresholding.h index 4c6d3e3..1a32687 100644 --- a/Image/Thresholding.h +++ b/Image/Thresholding.h @@ -53,11 +53,11 @@ namespace Image { for (int i = 0; i < dim.width; ++i) { for (int j = 0; j < dim.height; ++j) { - x1 = max(1, i - s / 2.0); - x2 = min(i + s / 2.0, dim.width - 1); + x1 = oms_max(1, i - s / 2.0); + x2 = oms_min(i + s / 2.0, dim.width - 1); - y1 = max(1, j - s / 2.0); - y2 = min(j + s / 2.0, dim.height - 1); + y1 = oms_max(1, j - s / 2.0); + y2 = oms_min(j + s / 2.0, dim.height - 1); count = (x2 - x1) * (y2 - y1); sum = intImg[x2][y2] - intImg[x2][y1 - 1] - intImg[x1 - 1][y2] + intImg[x1 - 1][y1 - 1]; diff --git a/Utils/MathUtils.h b/Utils/MathUtils.h index 9e2a59d..f61ea59 100644 --- a/Utils/MathUtils.h +++ b/Utils/MathUtils.h @@ -12,25 +12,25 @@ #define OMS_PI 3.14159265358979323846 -#define max(a, b) \ +#define oms_max(a, b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; }) -#define min(a, b) \ +#define oms_min(a, b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a < _b ? _a : _b; }) -#define abs(a) \ +#define oms_abs(a) \ ({ __typeof__ (a) _a = (a); \ _a > 0 ? _a : -_a; }) -#define deg2rad(angle) \ +#define oms_deg2rad(angle) \ ({ __typeof__ (angle) _angle = (angle); \ (_angle) * OMS_PI / 180.0; }) -#define rad2deg(angle) \ +#define oms_rad2deg(angle) \ ({ __typeof__ (angle) _angle = (angle); \ (_angle) * 180.0 / M_PI; }) diff --git a/Utils/TestUtils.h b/Utils/TestUtils.h index 5d8ec1a..9200b5b 100644 --- a/Utils/TestUtils.h +++ b/Utils/TestUtils.h @@ -25,7 +25,7 @@ return 0; } \ }) -#define ASSERT_EQUALS__DELTA(a, b, delta, t1, t2) \ +#define ASSERT_EQUALS_WITH_DELTA(a, b, delta, t1, t2) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ if (abs(_a - _b) <= delta) { \