Spaces:
Build error
Build error
Update ocr_engine.py
Browse files- ocr_engine.py +10 -6
ocr_engine.py
CHANGED
@@ -4,9 +4,13 @@ import numpy as np
|
|
4 |
from PIL import Image
|
5 |
|
6 |
def extract_weight_from_image(image):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
4 |
from PIL import Image
|
5 |
|
6 |
def extract_weight_from_image(image):
|
7 |
+
try:
|
8 |
+
image = np.array(image.convert("RGB")) # Ensure RGB format
|
9 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
10 |
+
blur = cv2.GaussianBlur(gray, (3, 3), 0) # Optional: denoise
|
11 |
+
text = pytesseract.image_to_string(blur, config='--psm 7 digits')
|
12 |
+
weight = ''.join(filter(lambda x: x in '0123456789.', text))
|
13 |
+
confidence = 95 # Placeholder
|
14 |
+
return weight.strip(), confidence
|
15 |
+
except Exception as e:
|
16 |
+
return "", 0
|