Sanjayraju30 commited on
Commit
6d93c4d
·
verified ·
1 Parent(s): cddca10

Update src/ocr_engine.py

Browse files
Files changed (1) hide show
  1. src/ocr_engine.py +8 -8
src/ocr_engine.py CHANGED
@@ -1,12 +1,12 @@
1
- def extract_weight_from_image(pil_img):
2
- import os
3
- os.system("apt-get update && apt-get install -y libgl1-mesa-glx")
4
 
5
- import cv2
6
- import numpy as np
7
- import pytesseract
8
- from PIL import Image
9
 
 
10
  image = np.array(pil_img.convert("RGB"))
11
  gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
12
  blur = cv2.GaussianBlur(gray, (3, 3), 0)
@@ -17,6 +17,6 @@ def extract_weight_from_image(pil_img):
17
 
18
  extracted_text = ''.join(filter(lambda x: x in '0123456789.', ''.join(data['text'])))
19
  confidences = [int(conf) for conf in data['conf'] if conf.isdigit()]
20
- avg_conf = sum(confidences) / len(confidences) if confidences else 0
21
 
22
  return extracted_text.strip(), avg_conf
 
1
+ import os
2
+ os.system("apt-get update && apt-get install -y libgl1-mesa-glx")
 
3
 
4
+ import cv2
5
+ import numpy as np
6
+ import pytesseract
7
+ from PIL import Image
8
 
9
+ def extract_weight_from_image(pil_img):
10
  image = np.array(pil_img.convert("RGB"))
11
  gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
12
  blur = cv2.GaussianBlur(gray, (3, 3), 0)
 
17
 
18
  extracted_text = ''.join(filter(lambda x: x in '0123456789.', ''.join(data['text'])))
19
  confidences = [int(conf) for conf in data['conf'] if conf.isdigit()]
20
+ avg_conf = sum(confidences)/len(confidences) if confidences else 0
21
 
22
  return extracted_text.strip(), avg_conf