AutoWeightLogger2 / ocr_engine.py
Sanjayraju30's picture
Update ocr_engine.py
b544f2d verified
raw
history blame contribute delete
376 Bytes
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))