Auto-weight-logger1 / ocr_engine.py
Sanjayraju30's picture
Create ocr_engine.py
b8f0bce verified
raw
history blame
350 Bytes
import pytesseract
from PIL import Image
import re
def extract_weight_from_image(image):
"""Extract weight as a decimal number (e.g., 53.76) from the image."""
try:
text = pytesseract.image_to_string(image)
match = re.search(r"\d+.\d{2}", text)
if match:
return match.group()
return "No weight found"
except Exception as e:
return f"Error: {str(e)}"