From 4d53adb9585c0327025fdf959db4d50206af6292 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 13 Aug 2022 19:16:45 +0200 Subject: [PATCH] update --- .gitignore | 3 +- LICENSE.txt | 14 +++++ Stdlib/AssocArray.h | 67 +++++++++++++++++++++++ Tools/InvoicePreprocessing/CMakeLists.txt | 7 --- Tools/InvoicePreprocessing/main.cpp | 61 --------------------- Utils/ArrayUtils.h | 43 +++++++++++++++ Utils/FileUtils.h | 7 ++- Utils/StringUtils.h | 37 +++++++++++++ 8 files changed, 166 insertions(+), 73 deletions(-) create mode 100755 LICENSE.txt create mode 100644 Stdlib/AssocArray.h delete mode 100644 Tools/InvoicePreprocessing/CMakeLists.txt delete mode 100644 Tools/InvoicePreprocessing/main.cpp create mode 100644 Utils/ArrayUtils.h create mode 100644 Utils/StringUtils.h diff --git a/.gitignore b/.gitignore index 29d9ff6..070942b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ *.cmake CMakeCache.txt Makefile -CMakeFiles -App \ No newline at end of file +CMakeFiles \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100755 index 0000000..56d5426 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,14 @@ +The OMS License 1.0 + +Copyright (c) All Rights Reserved + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +BY CONTRIBUTING YOU AUTOMATICALLY ACCEPT THE INDIVIDUAL CONTRIBUTOR LICENSE +AGREEMENT 1.0 ("CLA") INCLUDED IN THIS REPOSITORY. \ No newline at end of file diff --git a/Stdlib/AssocArray.h b/Stdlib/AssocArray.h new file mode 100644 index 0000000..986bc22 --- /dev/null +++ b/Stdlib/AssocArray.h @@ -0,0 +1,67 @@ +/** + * Karaka + * + * @package Stdlib + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link https://karaka.app + */ +#ifndef STDLIB_ASSOC_ARRAY_H +#define STDLIB_ASSOC_ARRAY_H + +#include +#include + +namespace Stdlib { + class AssocArray { + private: + + public: + typedef struct { + int size; + void **keys; + void **values; + } assoc_arr; + + static + assoc_arr *hash_new(int size) + { + assoc_arr *h = (assoc_arr *) calloc(1, sizeof(assoc_arr)); + h->keys = (void **) calloc(size, sizeof(void *)); + h->values = (void **) calloc(size, sizeof(void *)); + h->size = size; + + return h; + } + + static + int hash_index(assoc_arr *h, void *key) + { + int i = (int) key % h->size; + while (h->keys[i] && h->keys[i] != key) { + i = (i + 1) % h->size; + } + + return i; + } + + static + void hash_insert(assoc_arr *h, void *key, void *value) + { + int i = hash_index(h, key); + h->keys[i] = key; + h->values[i] = value; + } + + static + void *hash_lookup(assoc_arr *h, void *key) + { + int i = hash_index(h, key); + + return h->values[i]; + } + }; +} + +#endif \ No newline at end of file diff --git a/Tools/InvoicePreprocessing/CMakeLists.txt b/Tools/InvoicePreprocessing/CMakeLists.txt deleted file mode 100644 index df4bfd5..0000000 --- a/Tools/InvoicePreprocessing/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -project( App ) -find_package( OpenCV REQUIRED ) -include_directories( ${OpenCV_INCLUDE_DIRS} ) -set( CMAKE_BUILD_TYPE Debug ) -add_executable( App main.cpp ) -target_link_libraries( App ${OpenCV_LIBS} ) \ No newline at end of file diff --git a/Tools/InvoicePreprocessing/main.cpp b/Tools/InvoicePreprocessing/main.cpp deleted file mode 100644 index 626a1ab..0000000 --- a/Tools/InvoicePreprocessing/main.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Karaka - * - * @package App - * @copyright Dennis Eichhorn - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://karaka.app - */ -#include -#include -#include - -#include "../../Utils/FileUtils.h" -#include "../../Image/Skew.h" -#include "../../Image/Thresholding.h" -#include "../../Image/BillDetection.h" - -const bool DEBUG = false; - -int main(int argc, char** argv) -{ - if (argc != 3) { - printf("A input image and a output image is required\n"); - - return -1; - } - - if (!Utils::FileUtils::file_exists(argv[1])) { - printf("Image file doesn't exist.\n"); - - return -1; - } - - cv::Mat in; - in = cv::imread(argv[1], cv::IMREAD_UNCHANGED); - if (!in.data) { - printf("Couldn't read image.\n"); - - return -1; - } - - cv::Mat out = in.clone(); - - out = Image::BillDetection::highlightBill(out); - if (DEBUG) cv::imshow("bill_detection", out); - - out = Image::Thresholding::integralThresholding(out); - if (DEBUG) cv::imshow("thresholding", out); - - out = Image::Skew::deskewHoughLines(out); - if (DEBUG) cv::imshow("rotation", out); - - if (DEBUG) cv::imshow("original", in); - - cv::imwrite(argv[2], out); - - if (DEBUG) cv::waitKey(0); - - return 0; -} \ No newline at end of file diff --git a/Utils/ArrayUtils.h b/Utils/ArrayUtils.h new file mode 100644 index 0000000..844f274 --- /dev/null +++ b/Utils/ArrayUtils.h @@ -0,0 +1,43 @@ +/** + * Karaka + * + * @package Utils + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link https://karaka.app + */ +#ifndef UTILS_ARRAY_UTILS_H +#define UTILS_ARRAY_UTILS_H + +#include +#include +#include + +#include "../Stdlib/AssocArray.h" +#include "StringUtils.h" + +namespace Utils { + class ArrayUtils { + private: + + public: + static inline + char* get_arg (char *id, Stdlib::AssocArray::assoc_arr *args) + { + if (Utils::StringUtils::is_number(id)) { + return (char *) args->values[atoi(id)]; + } + + return (char *) Stdlib::AssocArray::hash_lookup(args, id); + } + + static inline + bool has_arg (char *id, Stdlib::AssocArray::assoc_arr *args) + { + return Stdlib::AssocArray::hash_lookup(args, id) == NULL; + } + }; +} + +#endif \ No newline at end of file diff --git a/Utils/FileUtils.h b/Utils/FileUtils.h index 680372c..01024b8 100644 --- a/Utils/FileUtils.h +++ b/Utils/FileUtils.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://karaka.app */ -#ifndef UTILS_TEST_UTILS_H -#define UTILS_TEST_UTILS_H +#ifndef UTILS_FILE_UTILS_H +#define UTILS_FILE_UTILS_H #ifdef _WIN32 #include @@ -23,7 +23,8 @@ namespace Utils { public: static inline - bool file_exists (char *filename) { + bool file_exists (char *filename) + { #ifdef _WIN32 return access(filename, F_OK) == 0; #elif defined __linux__ diff --git a/Utils/StringUtils.h b/Utils/StringUtils.h new file mode 100644 index 0000000..08bbba9 --- /dev/null +++ b/Utils/StringUtils.h @@ -0,0 +1,37 @@ +/** + * Karaka + * + * @package Utils + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link https://karaka.app + */ +#ifndef UTILS_STRING_UTILS_H +#define UTILS_STRING_UTILS_H + +#include +#include + +namespace Utils { + class StringUtils { + private: + + public: + static inline + bool is_number (char *s) + { + while (*s != '\0') { + if (!isdigit(*s)) { + return false; + } + + ++s; + } + + return true; + } + }; +} + +#endif \ No newline at end of file