Spaces:
Build error
Build error
File size: 397 Bytes
8f557ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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
|