Spaces:
Sleeping
Sleeping
Download ocr_engine.py from Sanjayraju30/AutoWeightLogger2: direct link, hf CLI and curl.
- Browser
- Download file 376 Bytes
-
https://huggingface.co/spaces/Sanjayraju30/AutoWeightLogger2/resolve/main/ocr_engine.py
- Command line
-
hf download hf://spaces/Sanjayraju30/AutoWeightLogger2/ocr_engine.py
-
curl -L -o ocr_engine.py https://huggingface.co/spaces/Sanjayraju30/AutoWeightLogger2/resolve/main/ocr_engine.py
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)) |