DSatishchandra commited on
Commit
e07d304
Β·
verified Β·
1 Parent(s): 189f24f

Update services/video_service.py

Browse files
Files changed (1) hide show
  1. services/video_service.py +27 -18
services/video_service.py CHANGED
@@ -21,24 +21,33 @@ class VideoService:
21
  return Image.fromarray(frame_rgb)
22
 
23
  def draw_detections(self, frame, detections):
24
- """Draw bounding boxes and labels on frame."""
25
- frame_copy = frame.copy()
26
- for detection in detections:
27
- score = detection["score"]
28
- label = detection["label"]
29
- box = detection["box"]
30
- x1, y1, x2, y2 = box["xmin"], box["ymin"], box["xmax"], box["ymax"]
31
- cv2.rectangle(frame_copy, (x1, y1), (x2, y2), (0, 255, 0), 2)
32
- cv2.putText(
33
- frame_copy,
34
- f"{label}: {score:.2f}",
35
- (x1, y1 - 10),
36
- cv2.FONT_HERSHEY_SIMPLEX,
37
- 0.5,
38
- (0, 255, 0),
39
- 2
40
- )
41
- return frame_copy
 
 
 
 
 
 
 
 
 
42
 
43
  def save_video(self, frames, output_path, fps=30):
44
  """Save frames as a video."""
 
21
  return Image.fromarray(frame_rgb)
22
 
23
  def draw_detections(self, frame, detections):
24
+ frame_copy = frame.copy()
25
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
26
+ cv2.putText(
27
+ frame_copy,
28
+ timestamp,
29
+ (10, 30),
30
+ cv2.FONT_HERSHEY_SIMPLEX,
31
+ 1,
32
+ (255, 255, 255),
33
+ 2
34
+ )
35
+ for detection in detections:
36
+ score = detection["score"]
37
+ label = detection["label"]
38
+ box = detection["box"]
39
+ x1, y1, x2, y2 = box["xmin"], box["ymin"], box["xmax"], box["ymax"]
40
+ cv2.rectangle(frame_copy, (x1, y1), (x2, y2), (0, 255, 0), 2)
41
+ cv2.putText(
42
+ frame_copy,
43
+ f"{label}: {score:.2f}",
44
+ (x1, y1 - 10),
45
+ cv2.FONT_HERSHEY_SIMPLEX,
46
+ 0.5,
47
+ (0, 255, 0),
48
+ 2
49
+ )
50
+ return frame_copy
51
 
52
  def save_video(self, frames, output_path, fps=30):
53
  """Save frames as a video."""