From fdb9689f323d1c9ad3cb5d1aa4d25ba050249881 Mon Sep 17 00:00:00 2001 From: Mithibe Irungu Date: Thu, 15 Jun 2023 19:30:51 +0300 Subject: [PATCH] Created projectTheia file --- sorter/projectTheia.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 sorter/projectTheia.py diff --git a/sorter/projectTheia.py b/sorter/projectTheia.py new file mode 100644 index 0000000..8b7570c --- /dev/null +++ b/sorter/projectTheia.py @@ -0,0 +1,26 @@ +import shutil +import cv2 +import pytesseract +from pathlib import Path +import numpy as np + +def recognize_numbers(image_path,pass_folder,reject_folder): + # Load the image using OpenCV + image = cv2.imread(image_path) + + # Preprocess the image (convert to grayscale and apply thresholding) + gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) + _, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) + + # Perform text extraction using Tesseract OCR + text = pytesseract.image_to_string(binary, config='--psm 6') + + # Filter out non-numeric characters + numbers = ''.join(filter(str.isdigit, text)) + + return numbers + +# Usage +image_path = '../InCMSImages' +result = recognize_numbers(image_path) +print('Recognized numbers:', result)