mohamed12ahmed commited on
Commit
ee00213
·
verified ·
1 Parent(s): 816321e

Update ocr_processing.py

Browse files
Files changed (1) hide show
  1. ocr_processing.py +8 -6
ocr_processing.py CHANGED
@@ -1,7 +1,7 @@
1
  import cv2
2
  import numpy as np
3
  from PIL import Image
4
- import pytesseract
5
 
6
  # Skew Correction
7
  def deskew(image):
@@ -30,13 +30,15 @@ def correct_lighting(image):
30
  final = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
31
  return final
32
 
33
- # OCR Extraction (Multi-language)
34
- def extract_text(image, langs="eng+ara"):
35
- text = pytesseract.image_to_string(image, lang=langs)
 
 
36
  return text
37
 
38
- # Full Pipeline
39
- def process_image(file, langs="eng+ara"):
40
  img = Image.open(file).convert('RGB')
41
  img_cv = np.array(img)
42
  img_cv = deskew(img_cv)
 
1
  import cv2
2
  import numpy as np
3
  from PIL import Image
4
+ import easyocr
5
 
6
  # Skew Correction
7
  def deskew(image):
 
30
  final = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
31
  return final
32
 
33
+ # OCR Extraction using EasyOCR
34
+ def extract_text(image, langs=['en']):
35
+ reader = easyocr.Reader(langs, gpu=False) # GPU=True لو عندك دعم CUDA
36
+ results = reader.readtext(image, detail=0)
37
+ text = "\n".join(results)
38
  return text
39
 
40
+ # Full pipeline
41
+ def process_image(file, langs=['en']):
42
  img = Image.open(file).convert('RGB')
43
  img_cv = np.array(img)
44
  img_cv = deskew(img_cv)