Ramzan0553 commited on
Commit
ee9e3d5
·
verified ·
1 Parent(s): 35f3afd

Update EasyOpticalCharacterRecognition.py

Browse files
Files changed (1) hide show
  1. EasyOpticalCharacterRecognition.py +1 -13
EasyOpticalCharacterRecognition.py CHANGED
@@ -5,7 +5,6 @@ from tensorflow.keras.models import load_model
5
  from tensorflow.keras.preprocessing.image import img_to_array
6
  import pickle
7
  import os
8
- from google.colab import drive
9
 
10
  # === Load model and label encoder ===
11
  model_path = 'MobileNetBest_Model.h5'
@@ -14,15 +13,6 @@ pkl_path = 'MobileNet_Label_Encoder.pkl'
14
  model = load_model(model_path)
15
  print("✅ Model loaded.")
16
 
17
- if os.path.exists(pkl_path):
18
- with open(pkl_path, 'rb') as f:
19
- label_map = pickle.load(f)
20
- index_to_label = {v: k for k, v in label_map.items()}
21
- print("✅ Label encoder loaded.")
22
- else:
23
- index_to_label = {0: "Handwritten", 1: "Computerized"}
24
- print("⚠️ Label encoder not found, using default mapping.")
25
-
26
  # === Classification function ===
27
  def classify_text_region(region_img):
28
  try:
@@ -73,6 +63,4 @@ def AnnotatedTextDetection_EasyOCR_from_array(img):
73
  def process_image(input_image):
74
  img = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
75
  result_img, text_result = AnnotatedTextDetection_EasyOCR_from_array(img)
76
- return result_img, text_result
77
-
78
-
 
5
  from tensorflow.keras.preprocessing.image import img_to_array
6
  import pickle
7
  import os
 
8
 
9
  # === Load model and label encoder ===
10
  model_path = 'MobileNetBest_Model.h5'
 
13
  model = load_model(model_path)
14
  print("✅ Model loaded.")
15
 
 
 
 
 
 
 
 
 
 
16
  # === Classification function ===
17
  def classify_text_region(region_img):
18
  try:
 
63
  def process_image(input_image):
64
  img = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
65
  result_img, text_result = AnnotatedTextDetection_EasyOCR_from_array(img)
66
+ return result_img, text_result