Spaces:
Build error
Build error
Create ocr_engine.py
Browse files- ocr_engine.py +12 -0
ocr_engine.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import pytesseract
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
def extract_weight_from_image(image):
|
7 |
+
image = np.array(image)
|
8 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
9 |
+
text = pytesseract.image_to_string(gray, config='--psm 7 digits')
|
10 |
+
weight = ''.join(filter(lambda x: x in '0123456789.', text))
|
11 |
+
confidence = 95 # Placeholder
|
12 |
+
return weight.strip(), confidence
|