File size: 350 Bytes
b8f0bce
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)}"