Sanjayraju30 commited on
Commit
de0beca
·
verified ·
1 Parent(s): 9bcd2e4

Rename src/ocr_engine.py to ocr_engine.py

Browse files
Files changed (2) hide show
  1. ocr_engine.py +9 -0
  2. src/ocr_engine.py +0 -9
ocr_engine.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import pytesseract
2
+ import re
3
+
4
+ def extract_weight_from_image(image):
5
+ text = pytesseract.image_to_string(image)
6
+ match = re.search(r"\d+.\d{2}", text)
7
+ if match:
8
+ return match.group()
9
+ return "No weight found"
src/ocr_engine.py DELETED
@@ -1,9 +0,0 @@
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))