yeswanthvarma commited on
Commit
436a6c3
·
verified ·
1 Parent(s): 0212afc

Update utils/image_processor.py

Browse files
Files changed (1) hide show
  1. utils/image_processor.py +8 -5
utils/image_processor.py CHANGED
@@ -1,23 +1,26 @@
1
  import cv2
2
  import numpy as np
3
  import os
4
- os.environ["EASYOCR_HOME"] = "/tmp/.easyocr" # ✅ add this before using easyocr
5
- import easyocr
6
- reader = easyocr.Reader(['en'])
7
  from PIL import Image
8
 
 
 
9
 
10
- # Ensure model downloads go to a writable directory
 
 
11
  try:
12
  reader = easyocr.Reader(['en'], download_enabled=True, model_storage_directory="/tmp/.easyocr")
13
  ocr_available = True
14
-
15
  except Exception as e:
16
  print(f"Warning: EasyOCR initialization failed: {str(e)}")
17
  print("Text extraction may not work properly.")
18
  ocr_available = False
19
 
20
 
 
 
 
21
  def preprocess_image(image):
22
  """
23
  Preprocess image to improve OCR accuracy
 
1
  import cv2
2
  import numpy as np
3
  import os
 
 
 
4
  from PIL import Image
5
 
6
+ # ✅ Make sure the EasyOCR model path is writable
7
+ os.environ["EASYOCR_HOME"] = "/tmp/.easyocr"
8
 
9
+ import easyocr
10
+
11
+ # ✅ Safe EasyOCR initialization
12
  try:
13
  reader = easyocr.Reader(['en'], download_enabled=True, model_storage_directory="/tmp/.easyocr")
14
  ocr_available = True
 
15
  except Exception as e:
16
  print(f"Warning: EasyOCR initialization failed: {str(e)}")
17
  print("Text extraction may not work properly.")
18
  ocr_available = False
19
 
20
 
21
+ # Ensure model downloads go to a writable directory
22
+
23
+
24
  def preprocess_image(image):
25
  """
26
  Preprocess image to improve OCR accuracy