Spaces:
Build error
Build error
import cv2 | |
import pytesseract | |
import numpy as np | |
from PIL import Image | |
def extract_weight_from_image(image): | |
image = np.array(image) | |
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) | |
text = pytesseract.image_to_string(gray, config='--psm 7 digits') | |
weight = ''.join(filter(lambda x: x in '0123456789.', text)) | |
confidence = 95 # Placeholder | |
return weight.strip(), confidence | |