Spaces:
Build error
Build error
auto-weight-logger4/ocr_engine.py
Browse files- ocr_engine.py +0 -21
ocr_engine.py
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
from mmocr.utils.ocr import MMOCR
|
2 |
-
|
3 |
-
# Load MMOCR model
|
4 |
-
mmocr = MMOCR(det='DB_r18', recog='CRNN', det_config=None, recog_config=None)
|
5 |
-
|
6 |
-
def extract_weight_from_image(image):
|
7 |
-
result = mmocr.readtext(image, output=None)
|
8 |
-
texts = [item['text'] for item in result]
|
9 |
-
debug_text = "\n".join(texts)
|
10 |
-
|
11 |
-
# Find the first valid float that could represent a weight
|
12 |
-
for text in texts:
|
13 |
-
if any(char.isdigit() for char in text):
|
14 |
-
cleaned = text.replace('kg', '').replace('KG', '').strip()
|
15 |
-
try:
|
16 |
-
weight = float(cleaned)
|
17 |
-
return str(weight), debug_text
|
18 |
-
except:
|
19 |
-
continue
|
20 |
-
|
21 |
-
return None, debug_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|