Spaces:
Sleeping
Sleeping
Commit ·
6a30f12
1
Parent(s): ceadc69
++++++++++
Browse files- app.py +10 -1
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -9,6 +9,8 @@ import json
|
|
| 9 |
import pywt
|
| 10 |
from skimage.feature import local_binary_pattern
|
| 11 |
from skimage.filters import threshold_otsu
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Ensure poppler-utils and tesseract-ocr are installed
|
| 14 |
def install_dependencies():
|
|
@@ -140,10 +142,17 @@ def process_image(img, method='default'):
|
|
| 140 |
elif method == 'enhance_contrast':
|
| 141 |
return enhance_contrast(resized_image)
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
# Function to extract text from processed image
|
| 144 |
def extract_text_from_image(image, langs='tel+osd+eng'):
|
|
|
|
| 145 |
custom_config = r'--oem 3 --psm 6'
|
| 146 |
-
return pytesseract.image_to_string(
|
|
|
|
| 147 |
|
| 148 |
|
| 149 |
output_dir = "output"
|
|
|
|
| 9 |
import pywt
|
| 10 |
from skimage.feature import local_binary_pattern
|
| 11 |
from skimage.filters import threshold_otsu
|
| 12 |
+
from PIL import Image
|
| 13 |
+
|
| 14 |
|
| 15 |
# Ensure poppler-utils and tesseract-ocr are installed
|
| 16 |
def install_dependencies():
|
|
|
|
| 142 |
elif method == 'enhance_contrast':
|
| 143 |
return enhance_contrast(resized_image)
|
| 144 |
|
| 145 |
+
|
| 146 |
+
def convert_to_pil(image):
|
| 147 |
+
return Image.fromarray(cv.cvtColor(image, cv.COLOR_BGR2RGB))
|
| 148 |
+
|
| 149 |
+
|
| 150 |
# Function to extract text from processed image
|
| 151 |
def extract_text_from_image(image, langs='tel+osd+eng'):
|
| 152 |
+
pil_image = convert_to_pil(image)
|
| 153 |
custom_config = r'--oem 3 --psm 6'
|
| 154 |
+
return pytesseract.image_to_string(pil_image, lang=langs, config=custom_config)
|
| 155 |
+
|
| 156 |
|
| 157 |
|
| 158 |
output_dir = "output"
|
requirements.txt
CHANGED
|
@@ -14,4 +14,5 @@ orjson==3.10.4
|
|
| 14 |
python-json-logger==2.0.7
|
| 15 |
ujson==5.10.0
|
| 16 |
PyWavelets
|
| 17 |
-
scikit-image==0.18.3
|
|
|
|
|
|
| 14 |
python-json-logger==2.0.7
|
| 15 |
ujson==5.10.0
|
| 16 |
PyWavelets
|
| 17 |
+
scikit-image==0.18.3
|
| 18 |
+
Pillow
|