reduces class usage and impl. img diff function

This commit is contained in:
Dennis Eichhorn 2022-11-20 15:46:44 +01:00
parent 65f3b94cdb
commit 200a154874
8 changed files with 196 additions and 160 deletions

47
Image/Diff.h Normal file
View File

@ -0,0 +1,47 @@
/**
* Karaka
*
* @package Image
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://karaka.app
*/
#ifndef IMAGE_DIFF_H
#define IMAGE_DIFF_H
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "../Utils/MathUtils.h"
namespace Image {
namespace ImageUtils {
cv::Mat find_diff (cv::Mat in1, cv::Mat in2)
{
cv::Mat diff;
cv::absdiff(in1, in2, diff);
int th = 10;
cv::Mat mask(in1.size(), CV_8UC1);
for (int i = 0; i < diff.rows; ++i) {
for (int j = 0; j < diff.cols; ++j) {
cv::Vec3b px = diff.at<cv::Vec3b>(i, j);
int value = px[0] + px[1] + px[2];
if (value > th) {
mask.at<unsigned char>(i, j) = 255;
}
}
}
cv::Mat out;
cv::bitwise_and(in2, in2, out, mask);
return out;
}
}
}
#endif

View File

@ -14,11 +14,8 @@
#include <math.h>
namespace Image {
class ImageUtils {
private:
public:
static inline
namespace ImageUtils {
inline
float lightnessFromRgb(int r, int g, int b)
{
float vR = r / 255.0;
@ -35,7 +32,7 @@ namespace Image {
return lStar / 100.0;
}
static inline
inline
int rgbToInt(int r, int g, int b)
{
int rgb = r;
@ -44,7 +41,7 @@ namespace Image {
return rgb;
}
};
}
}
#endif

View File

@ -61,12 +61,8 @@ namespace Image {
{-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0},
};
class Kernel {
private:
public:
static
namespace Kernel {
inline
cv::Mat convolve(cv::Mat in, const float kernel[][3])
{
cv::Size dim = in.size();
@ -77,7 +73,7 @@ namespace Image {
return out;
}
};
}
}
#endif

View File

@ -17,11 +17,7 @@
#include "../Utils/MathUtils.h"
namespace Image {
class Skew {
private:
public:
static
namespace Skew {
cv::Mat deskewHoughLines(cv::Mat in, int maxDegree = 45)
{
cv::Size dim = in.size();
@ -89,7 +85,7 @@ namespace Image {
return out;
}
};
}
}
#endif

View File

@ -17,11 +17,7 @@
#include "../Utils/MathUtils.h"
namespace Image {
class Thresholding {
private:
public:
static
namespace Thresholding {
cv::Mat integralThresholding(cv::Mat in)
{
cv::Size dim = in.size();
@ -77,7 +73,7 @@ namespace Image {
return out;
}
};
}
}
#endif

View File

@ -39,6 +39,7 @@ namespace Utils {
return cwd;
}
inline
void chdir_application(char *cwd, char *arg)
{
#ifdef _WIN32
@ -80,6 +81,7 @@ namespace Utils {
#endif
}
inline
const char *compile_arg_line(int argc, char **argv)
{
size_t max = 512;

View File

@ -10,6 +10,9 @@
#ifndef UTILS_FILE_UTILS_H
#define UTILS_FILE_UTILS_H
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
@ -88,6 +91,7 @@ namespace Utils {
#endif
}
inline
const char* file_extension (const char *filename)
{
char *dot = strrchr((char *) filename, '.');
@ -104,7 +108,6 @@ namespace Utils {
int size;
} file_body;
inline
file_body read_file (const char *filename)
{
file_body file = {0};

View File

@ -19,7 +19,6 @@
namespace Utils {
namespace WebUtils {
static
int write_download_data (void *ptr, size_t size, size_t nmeb, void *stream)
{
Utils::FileUtils::file_body *out = (Utils::FileUtils::file_body *) stream;
@ -42,7 +41,7 @@ namespace Utils {
return out->size;
}
static
inline
Utils::FileUtils::file_body download (char *url)
{
Utils::FileUtils::file_body page = {0};