Spaces:
Sleeping
Sleeping
Update ocr_processing.py
Browse files- 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
|
| 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
|
| 34 |
-
def extract_text(image, langs=
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
return text
|
| 37 |
|
| 38 |
-
# Full
|
| 39 |
-
def process_image(file, langs=
|
| 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)
|