Sakibrumu commited on
Commit
07eed04
·
verified ·
1 Parent(s): f84d408

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -53,41 +53,43 @@ def process_input(input_file):
53
 
54
  if ext in ['.mp4', '.avi', '.mov']:
55
  cap = cv2.VideoCapture(file_path)
56
-
57
  if not cap.isOpened():
58
- return None, "Could not open video file", ""
59
 
60
  fps = cap.get(cv2.CAP_PROP_FPS)
61
- width = 640
62
- height = 640
63
-
64
- # Generate safe output path
65
- output_path = f"annotated_output.mp4"
66
- fourcc = cv2.VideoWriter_fourcc(*'mp4v')
67
- out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
68
 
69
  while True:
70
  ret, frame = cap.read()
71
  if not ret:
72
  break
73
- frame_resized = cv2.resize(frame, (640, 640))
74
- annotated_frame = annotate_frame(frame_resized)
75
- bgr_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_RGB2BGR)
76
- out.write(bgr_frame)
 
 
 
 
77
 
78
  cap.release()
79
  out.release()
80
 
81
- return output_path, "Bangla text in video (see frames)", "OCR confidence displayed on frames"
82
 
83
  else:
84
- # Handle image
85
  frame = cv2.imread(file_path)
86
  if frame is None:
87
- return None, "Invalid image file", ""
88
 
 
89
  annotated = annotate_frame(frame)
90
- return Image.fromarray(annotated), "Bangla text in image", ""
 
 
91
 
92
 
93
  interface = gr.Interface(
 
53
 
54
  if ext in ['.mp4', '.avi', '.mov']:
55
  cap = cv2.VideoCapture(file_path)
 
56
  if not cap.isOpened():
57
+ return None, None, "Could not open video file", ""
58
 
59
  fps = cap.get(cv2.CAP_PROP_FPS)
60
+ frame_skip = 5
61
+ frame_id = 0
62
+ output_path = "annotated_output.mp4"
63
+ out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (640, 640))
 
 
 
64
 
65
  while True:
66
  ret, frame = cap.read()
67
  if not ret:
68
  break
69
+ if frame_id % frame_skip != 0:
70
+ frame_id += 1
71
+ continue
72
+
73
+ frame_id += 1
74
+ frame = cv2.resize(frame, (640, 640))
75
+ annotated = annotate_frame(frame)
76
+ out.write(cv2.cvtColor(annotated, cv2.COLOR_RGB2BGR))
77
 
78
  cap.release()
79
  out.release()
80
 
81
+ return output_path, None, "Bangla text in video (see frames)", "OCR confidence displayed"
82
 
83
  else:
 
84
  frame = cv2.imread(file_path)
85
  if frame is None:
86
+ return None, None, "Invalid image", ""
87
 
88
+ frame = cv2.resize(frame, (640, 640))
89
  annotated = annotate_frame(frame)
90
+ pil_img = Image.fromarray(annotated)
91
+ return None, pil_img, "Bangla text in image", "OCR confidence in image"
92
+
93
 
94
 
95
  interface = gr.Interface(