testmail-gmail commited on
Commit
154dae0
·
1 Parent(s): 46959a4

Adding image to text code

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -9,6 +9,8 @@ from numpy import random
9
  from pathlib import Path
10
  import torch.backends.cudnn as cudnn
11
  from models.experimental import attempt_load
 
 
12
 
13
  from utils.datasets import LoadStreams, LoadImages
14
  from utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier, \
@@ -17,6 +19,7 @@ from utils.plots import plot_one_box
17
  from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
18
  os.system("wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt")
19
  os.system("wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6.pt")
 
20
 
21
  def detect_Custom(img,model,boundedImage):
22
  if model =='Yolo_v7_Custom_trained_By_Owais':
@@ -146,12 +149,18 @@ def detect_Custom(img,model,boundedImage):
146
  vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
147
  vid_writer.write(im0)
148
 
 
 
 
 
 
 
149
  if save_txt or save_img:
150
  s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
151
 
152
  print(f'Done. ({time.time() - t0:.3f}s)')
153
 
154
- return Image.fromarray(im0[:,:,::-1]), boundedImage
155
 
156
 
157
 
 
9
  from pathlib import Path
10
  import torch.backends.cudnn as cudnn
11
  from models.experimental import attempt_load
12
+ import keras_ocr
13
+ import matplotlib.pyplot as plt
14
 
15
  from utils.datasets import LoadStreams, LoadImages
16
  from utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier, \
 
19
  from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
20
  os.system("wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt")
21
  os.system("wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6.pt")
22
+ pipeline = keras_ocr.pipeline.Pipeline()
23
 
24
  def detect_Custom(img,model,boundedImage):
25
  if model =='Yolo_v7_Custom_trained_By_Owais':
 
149
  vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
150
  vid_writer.write(im0)
151
 
152
+ images = [keras_ocr.tools.read(img) for img in [boundedImage]]
153
+ prediction_groups = pipeline.recognize(images)
154
+ plt.figure(figsize = (10,20))
155
+
156
+ fig, ax = plt.subplots(figsize=(10, 20))
157
+ keras_ocr.tools.drawAnnotations(image=images[0], predictions=prediction_groups[0], ax=ax)
158
  if save_txt or save_img:
159
  s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
160
 
161
  print(f'Done. ({time.time() - t0:.3f}s)')
162
 
163
+ return Image.fromarray(im0[:,:,::-1]), plt.imshow(boundedImage)
164
 
165
 
166