sovitrath commited on
Commit
6568a70
1 Parent(s): 419e9e5

Updated for video input

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -60,21 +60,42 @@ interface_image = gr.Interface(
60
  # live=True,
61
  )
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  inputs_video = [
64
  gr.components.Video(type="filepath", label="Input Video"),
65
 
66
  ]
67
  outputs_video = [
68
- gr.components.Video(type="mp4", label="Output Image"),
69
  ]
70
  interface_video = gr.Interface(
71
- fn=show_preds_image,
72
  inputs=inputs_video,
73
  outputs=outputs_video,
74
  title="Pothole detector",
75
- examples=path,
76
  cache_examples=False,
77
  # live=True,
78
  )
79
  # interface_image.launch(debug=True, enable_queue=True)
80
- gr.TabbedInterface([interface_image, interface_video]).launch()
 
60
  # live=True,
61
  )
62
 
63
+
64
+ def show_preds_video(video_path):
65
+ cap = cv2.VideoCapture(video_path)
66
+ while(cap.isOpened()):
67
+ ret, frame = cap.read()
68
+ if ret:
69
+ frame_copy = frame.copy()
70
+ outputs = model.predict(source=frame)
71
+ results = outputs[0].cpu().numpy()
72
+ for i, det in enumerate(results.boxes.xyxy):
73
+ # print(det.xyxy)
74
+ cv2.rectangle(
75
+ frame_copy,
76
+ (int(det[0]), int(det[1])),
77
+ (int(det[2]), int(det[3])),
78
+ color=(0, 0, 255),
79
+ thickness=2,
80
+ lineType=cv2.LINE_AA
81
+ )
82
+ yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
83
+
84
  inputs_video = [
85
  gr.components.Video(type="filepath", label="Input Video"),
86
 
87
  ]
88
  outputs_video = [
89
+ gr.components.Image(type="numpy", label="Output Image"),
90
  ]
91
  interface_video = gr.Interface(
92
+ fn=show_preds_video,
93
  inputs=inputs_video,
94
  outputs=outputs_video,
95
  title="Pothole detector",
96
+ # examples=path,
97
  cache_examples=False,
98
  # live=True,
99
  )
100
  # interface_image.launch(debug=True, enable_queue=True)
101
+ gr.TabbedInterface([interface_image, interface_video]).queue().launch()