Spaces:
Sleeping
Sleeping
WebashalarForML
commited on
Commit
•
f1e58f7
1
Parent(s):
84d7e55
Update utility/utils.py
Browse files- utility/utils.py +9 -7
utility/utils.py
CHANGED
@@ -96,7 +96,7 @@ def process_image(image_path, scale=2):
|
|
96 |
return final_image
|
97 |
|
98 |
# Function for OCR with PaddleOCR, returning both text and bounding boxes
|
99 |
-
def ocr_with_paddle(
|
100 |
final_text = ''
|
101 |
boxes = []
|
102 |
|
@@ -109,11 +109,13 @@ def ocr_with_paddle(img_path):
|
|
109 |
cls_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/cls/ch_ppocr_mobile_v2.0_cls_infer')
|
110 |
)
|
111 |
|
112 |
-
#
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
117 |
|
118 |
# Iterate through OCR results
|
119 |
for line in result[0]:
|
@@ -128,7 +130,7 @@ def ocr_with_paddle(img_path):
|
|
128 |
# Save the image with drawn boxes in memory (as a variable)
|
129 |
img_with_boxes = img # This image can be used later or saved to disk if needed
|
130 |
|
131 |
-
return final_text, img_with_boxes
|
132 |
|
133 |
# Function to draw bounding boxes around text
|
134 |
#def draw_boxes(image, boxes):
|
|
|
96 |
return final_image
|
97 |
|
98 |
# Function for OCR with PaddleOCR, returning both text and bounding boxes
|
99 |
+
def ocr_with_paddle(img):
|
100 |
final_text = ''
|
101 |
boxes = []
|
102 |
|
|
|
109 |
cls_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/cls/ch_ppocr_mobile_v2.0_cls_infer')
|
110 |
)
|
111 |
|
112 |
+
# Check if img is a file path or an image array
|
113 |
+
if isinstance(img, str):
|
114 |
+
# If img is a file path, load the image
|
115 |
+
img = cv2.imread(img)
|
116 |
+
|
117 |
+
# Perform OCR (Note: You might need to adapt this based on how PaddleOCR handles input images)
|
118 |
+
result = ocr.ocr(img)
|
119 |
|
120 |
# Iterate through OCR results
|
121 |
for line in result[0]:
|
|
|
130 |
# Save the image with drawn boxes in memory (as a variable)
|
131 |
img_with_boxes = img # This image can be used later or saved to disk if needed
|
132 |
|
133 |
+
return final_text, boxes, img_with_boxes
|
134 |
|
135 |
# Function to draw bounding boxes around text
|
136 |
#def draw_boxes(image, boxes):
|