mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-02-15 18:08:40 +00:00
reduces class usage and impl. img diff function
This commit is contained in:
parent
65f3b94cdb
commit
200a154874
47
Image/Diff.h
Normal file
47
Image/Diff.h
Normal 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
|
||||||
|
|
@ -14,11 +14,8 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace Image {
|
namespace Image {
|
||||||
class ImageUtils {
|
namespace ImageUtils {
|
||||||
private:
|
inline
|
||||||
|
|
||||||
public:
|
|
||||||
static inline
|
|
||||||
float lightnessFromRgb(int r, int g, int b)
|
float lightnessFromRgb(int r, int g, int b)
|
||||||
{
|
{
|
||||||
float vR = r / 255.0;
|
float vR = r / 255.0;
|
||||||
|
|
@ -35,7 +32,7 @@ namespace Image {
|
||||||
return lStar / 100.0;
|
return lStar / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
inline
|
||||||
int rgbToInt(int r, int g, int b)
|
int rgbToInt(int r, int g, int b)
|
||||||
{
|
{
|
||||||
int rgb = r;
|
int rgb = r;
|
||||||
|
|
@ -44,7 +41,7 @@ namespace Image {
|
||||||
|
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -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},
|
{-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0},
|
||||||
};
|
};
|
||||||
|
|
||||||
class Kernel {
|
namespace Kernel {
|
||||||
private:
|
inline
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
static
|
|
||||||
cv::Mat convolve(cv::Mat in, const float kernel[][3])
|
cv::Mat convolve(cv::Mat in, const float kernel[][3])
|
||||||
{
|
{
|
||||||
cv::Size dim = in.size();
|
cv::Size dim = in.size();
|
||||||
|
|
@ -77,7 +73,7 @@ namespace Image {
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -17,11 +17,7 @@
|
||||||
#include "../Utils/MathUtils.h"
|
#include "../Utils/MathUtils.h"
|
||||||
|
|
||||||
namespace Image {
|
namespace Image {
|
||||||
class Skew {
|
namespace Skew {
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
cv::Mat deskewHoughLines(cv::Mat in, int maxDegree = 45)
|
cv::Mat deskewHoughLines(cv::Mat in, int maxDegree = 45)
|
||||||
{
|
{
|
||||||
cv::Size dim = in.size();
|
cv::Size dim = in.size();
|
||||||
|
|
@ -89,7 +85,7 @@ namespace Image {
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -17,11 +17,7 @@
|
||||||
#include "../Utils/MathUtils.h"
|
#include "../Utils/MathUtils.h"
|
||||||
|
|
||||||
namespace Image {
|
namespace Image {
|
||||||
class Thresholding {
|
namespace Thresholding {
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
static
|
|
||||||
cv::Mat integralThresholding(cv::Mat in)
|
cv::Mat integralThresholding(cv::Mat in)
|
||||||
{
|
{
|
||||||
cv::Size dim = in.size();
|
cv::Size dim = in.size();
|
||||||
|
|
@ -77,7 +73,7 @@ namespace Image {
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -39,6 +39,7 @@ namespace Utils {
|
||||||
return cwd;
|
return cwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
void chdir_application(char *cwd, char *arg)
|
void chdir_application(char *cwd, char *arg)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
@ -80,6 +81,7 @@ namespace Utils {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
const char *compile_arg_line(int argc, char **argv)
|
const char *compile_arg_line(int argc, char **argv)
|
||||||
{
|
{
|
||||||
size_t max = 512;
|
size_t max = 512;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,9 @@
|
||||||
#ifndef UTILS_FILE_UTILS_H
|
#ifndef UTILS_FILE_UTILS_H
|
||||||
#define UTILS_FILE_UTILS_H
|
#define UTILS_FILE_UTILS_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -88,6 +91,7 @@ namespace Utils {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
const char* file_extension (const char *filename)
|
const char* file_extension (const char *filename)
|
||||||
{
|
{
|
||||||
char *dot = strrchr((char *) filename, '.');
|
char *dot = strrchr((char *) filename, '.');
|
||||||
|
|
@ -104,7 +108,6 @@ namespace Utils {
|
||||||
int size;
|
int size;
|
||||||
} file_body;
|
} file_body;
|
||||||
|
|
||||||
inline
|
|
||||||
file_body read_file (const char *filename)
|
file_body read_file (const char *filename)
|
||||||
{
|
{
|
||||||
file_body file = {0};
|
file_body file = {0};
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
namespace WebUtils {
|
namespace WebUtils {
|
||||||
static
|
|
||||||
int write_download_data (void *ptr, size_t size, size_t nmeb, void *stream)
|
int write_download_data (void *ptr, size_t size, size_t nmeb, void *stream)
|
||||||
{
|
{
|
||||||
Utils::FileUtils::file_body *out = (Utils::FileUtils::file_body *) stream;
|
Utils::FileUtils::file_body *out = (Utils::FileUtils::file_body *) stream;
|
||||||
|
|
@ -42,7 +41,7 @@ namespace Utils {
|
||||||
return out->size;
|
return out->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
inline
|
||||||
Utils::FileUtils::file_body download (char *url)
|
Utils::FileUtils::file_body download (char *url)
|
||||||
{
|
{
|
||||||
Utils::FileUtils::file_body page = {0};
|
Utils::FileUtils::file_body page = {0};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user