This commit is contained in:
Dennis Eichhorn 2022-08-13 19:16:45 +02:00
parent 5223904077
commit 4d53adb958
8 changed files with 166 additions and 73 deletions

3
.gitignore vendored
View File

@ -3,5 +3,4 @@
*.cmake
CMakeCache.txt
Makefile
CMakeFiles
App
CMakeFiles

14
LICENSE.txt Executable file
View File

@ -0,0 +1,14 @@
The OMS License 1.0
Copyright (c) <Dennis Eichhorn> 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.

67
Stdlib/AssocArray.h Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
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

View File

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

View File

@ -1,61 +0,0 @@
/**
* Karaka
*
* @package App
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://karaka.app
*/
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <vector>
#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;
}

43
Utils/ArrayUtils.h Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#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

View File

@ -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 <unistd.h>
@ -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__

37
Utils/StringUtils.h Normal file
View File

@ -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 <stdio.h>
#include <ctype.h>
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