Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from helpers import OCRD
|
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
-
def run_ocrd_pipeline(img_path,
|
| 7 |
"""
|
| 8 |
Executes the OCRD pipeline on an image from file loading to text overlay creation. This function orchestrates
|
| 9 |
the calling of various OCRD class methods to process the image, extract and recognize text, and then overlay
|
|
@@ -11,12 +11,12 @@ def run_ocrd_pipeline(img_path, status=gr.Progress(), binarize_mode='detailed',
|
|
| 11 |
|
| 12 |
Parameters:
|
| 13 |
img_path (str): Path to the image file.
|
|
|
|
| 14 |
binarize_mode (str): Mode to be used for image binarization. Can be 'detailed', 'fast', or 'no'.
|
| 15 |
min_pixel_sum (int, optional): Minimum sum of pixels to consider a text line segmentation for extraction.
|
| 16 |
If 'default', default values are applied.
|
| 17 |
median_bounds (tuple, optional): Bounds to filter text line segmentations based on size relative to the median.
|
| 18 |
If 'default', default values are applied.
|
| 19 |
-
font_size (int, optional): Font size to be used in text overlay. If 'default', a default size or scaling logic is applied.
|
| 20 |
|
| 21 |
Returns:
|
| 22 |
Image: An image with overlay text, where text is extracted and recognized from the original image.
|
|
@@ -29,6 +29,16 @@ def run_ocrd_pipeline(img_path, status=gr.Progress(), binarize_mode='detailed',
|
|
| 29 |
- Creating an image overlay with recognized text.
|
| 30 |
"""
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# prepare kwargs
|
| 33 |
efadt_kwargs = {}
|
| 34 |
if min_pixel_sum != 'default':
|
|
@@ -41,7 +51,6 @@ def run_ocrd_pipeline(img_path, status=gr.Progress(), binarize_mode='detailed',
|
|
| 41 |
ctoi_kwargs['font_size'] = font_size
|
| 42 |
|
| 43 |
# run pipeline
|
| 44 |
-
#status(0, desc="\nReading image...\n")
|
| 45 |
ocrd = OCRD(img_path)
|
| 46 |
status(0, desc='\nStep 1/5: Binarizing image...\n')
|
| 47 |
binarized = ocrd.binarize_image(ocrd.image, binarize_mode)
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
+
def run_ocrd_pipeline(img_path, font_size=30, binarize_mode='detailed', min_pixel_sum=30, median_bounds=(None, None), status=gr.Progress()):
|
| 7 |
"""
|
| 8 |
Executes the OCRD pipeline on an image from file loading to text overlay creation. This function orchestrates
|
| 9 |
the calling of various OCRD class methods to process the image, extract and recognize text, and then overlay
|
|
|
|
| 11 |
|
| 12 |
Parameters:
|
| 13 |
img_path (str): Path to the image file.
|
| 14 |
+
font_size (int, optional): Font size to be used in text overlay. If 'default', a default size or scaling logic is applied.
|
| 15 |
binarize_mode (str): Mode to be used for image binarization. Can be 'detailed', 'fast', or 'no'.
|
| 16 |
min_pixel_sum (int, optional): Minimum sum of pixels to consider a text line segmentation for extraction.
|
| 17 |
If 'default', default values are applied.
|
| 18 |
median_bounds (tuple, optional): Bounds to filter text line segmentations based on size relative to the median.
|
| 19 |
If 'default', default values are applied.
|
|
|
|
| 20 |
|
| 21 |
Returns:
|
| 22 |
Image: An image with overlay text, where text is extracted and recognized from the original image.
|
|
|
|
| 29 |
- Creating an image overlay with recognized text.
|
| 30 |
"""
|
| 31 |
|
| 32 |
+
# convert gradio app dropdown options
|
| 33 |
+
if font_size == 'small':
|
| 34 |
+
font_size = 30
|
| 35 |
+
if font_size == 'medium':
|
| 36 |
+
font_size = 50
|
| 37 |
+
if font_size == 'large':
|
| 38 |
+
font_size = 70
|
| 39 |
+
elif font_size == 'adjusted':
|
| 40 |
+
font_size = -1
|
| 41 |
+
|
| 42 |
# prepare kwargs
|
| 43 |
efadt_kwargs = {}
|
| 44 |
if min_pixel_sum != 'default':
|
|
|
|
| 51 |
ctoi_kwargs['font_size'] = font_size
|
| 52 |
|
| 53 |
# run pipeline
|
|
|
|
| 54 |
ocrd = OCRD(img_path)
|
| 55 |
status(0, desc='\nStep 1/5: Binarizing image...\n')
|
| 56 |
binarized = ocrd.binarize_image(ocrd.image, binarize_mode)
|