File size: 376 Bytes
975f9c6
b544f2d
e58b1c2
b544f2d
25aa654
b544f2d
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
import cv2
import pytesseract
from PIL import Image
import numpy as np

def extract_weight(img_path):
    """Extract weight from image path using Tesseract OCR."""
    img = cv2.imread(img_path)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    text = pytesseract.image_to_string(gray, config='--psm 7 digits')
    return ''.join(filter(lambda x: x in '0123456789.', text))