From 580439bf8dd33e00f6a668a4828eab01d24d7abf Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 25 Dec 2024 17:46:41 +0530 Subject: Add image preprocessing before ocr --- include/libchelleport.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'include/libchelleport.h') diff --git a/include/libchelleport.h b/include/libchelleport.h index ef693cb..c74058d 100644 --- a/include/libchelleport.h +++ b/include/libchelleport.h @@ -1,3 +1,4 @@ +#include #include #include @@ -8,11 +9,19 @@ struct OCRMatch { const char *text; }; +// OCR configuration #define CONFIDENCE_THRESHOLD 25. -#define MIN_CHARACTER_COUNT 2 - +#define MIN_CHARACTER_COUNT 3 const tesseract::PageIteratorLevel RESULT_ITER_MODE = tesseract::RIL_WORD; +// Preprocessing configuration +const float contrast = 0.3; +const float sharpness = 0.7; +const float scaleFactor = 1; +const float grayscaleWeightRed = 0.114; +const float grayscaleWeightGreen = 0.587; +const float grayscaleWeightBlue = 0.299; + extern "C" { OCRMatch *findWordCoordinates(const char *image_path, /* returns */ int *size); } @@ -20,3 +29,5 @@ OCRMatch *findWordCoordinates(const char *image_path, /* returns */ int *size); std::vector extractTextCoordinates(const char *imagePath); void showMatch(const OCRMatch &match); + +void preprocessImage(Pix **image); -- cgit v1.3.1