File size: 296 Bytes
79d34b2
b8f0bce
 
 
79d34b2
 
 
 
 
1
2
3
4
5
6
7
8
9
10
import cv2
import pytesseract
from PIL import Image

def extract_weight(img_path):
    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))