Update ocr_engine.py
Browse files- ocr_engine.py +6 -11
ocr_engine.py
CHANGED
@@ -1,14 +1,9 @@
|
|
|
|
1 |
import pytesseract
|
2 |
from PIL import Image
|
3 |
-
import re
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
text = pytesseract.image_to_string(
|
9 |
-
|
10 |
-
if match:
|
11 |
-
return match.group()
|
12 |
-
return "No weight found"
|
13 |
-
except Exception as e:
|
14 |
-
return f"Error: {str(e)}"
|
|
|
1 |
+
import cv2
|
2 |
import pytesseract
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
+
def extract_weight(img_path):
|
6 |
+
img = cv2.imread(img_path)
|
7 |
+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
8 |
+
text = pytesseract.image_to_string(gray, config='--psm 7 digits')
|
9 |
+
return ''.join(filter(lambda x: x in '0123456789.', text))
|
|
|
|
|
|
|
|
|
|