Sanjayraju30 commited on
Commit
b8f0bce
·
verified ·
1 Parent(s): 6608ec4

Create ocr_engine.py

Browse files
Files changed (1) hide show
  1. ocr_engine.py +14 -0
ocr_engine.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytesseract
2
+ from PIL import Image
3
+ import re
4
+
5
+ def extract_weight_from_image(image):
6
+ """Extract weight as a decimal number (e.g., 53.76) from the image."""
7
+ try:
8
+ text = pytesseract.image_to_string(image)
9
+ match = re.search(r"\d+.\d{2}", text)
10
+ if match:
11
+ return match.group()
12
+ return "No weight found"
13
+ except Exception as e:
14
+ return f"Error: {str(e)}"