update after reducing math.h dependency

This commit is contained in:
Dennis Eichhorn 2022-04-05 19:54:39 +02:00
parent 2f3e6def35
commit 2d2ab7632a
5 changed files with 16 additions and 20 deletions

View File

@ -11,12 +11,9 @@
#define IMAGE_BILL_DETECTION_H
#include <stdio.h>
#include <math.h>
#include <opencv2/opencv.hpp>
#include <vector>
#include "../Utils/MathUtils.h"
namespace Image {
class BillDetection {
private:

View File

@ -11,7 +11,6 @@
#define IMAGE_SKEW_H
#include <stdio.h>
#include <math.h>
#include <opencv2/opencv.hpp>
#include <vector>
@ -32,26 +31,26 @@ namespace Image {
cv::threshold(inv, inv, 0, 255, cv::THRESH_BINARY_INV | cv::THRESH_OTSU);
std::vector<cv::Vec4i> 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<float> 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<float> 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) {

View File

@ -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];

View File

@ -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; })

View File

@ -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) { \