neelamdev commited on
Commit
233f2a9
·
verified ·
1 Parent(s): 7326046

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import cv2
2
  import numpy as np
 
 
3
 
4
  class VideoPlayer:
5
  def __init__(self, video_path):
@@ -8,6 +10,25 @@ class VideoPlayer:
8
  self.is_stopped = False
9
  self.frame = None
10
  self.playback_speed = 1.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def play(self):
13
  while True:
@@ -20,6 +41,9 @@ class VideoPlayer:
20
  print("End of video")
21
  break
22
 
 
 
 
23
  # Show the current frame
24
  cv2.imshow('Video Player', self.frame)
25
 
 
1
  import cv2
2
  import numpy as np
3
+ import torch
4
+ from transformers import pipeline
5
 
6
  class VideoPlayer:
7
  def __init__(self, video_path):
 
10
  self.is_stopped = False
11
  self.frame = None
12
  self.playback_speed = 1.0
13
+ self.detector = pipeline("object-detection") # Hugging Face Object Detection Pipeline
14
+
15
+ def process_frame(self, frame):
16
+ # Convert the frame to RGB (Hugging Face models expect RGB input)
17
+ rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
18
+
19
+ # Perform object detection (can be changed to any other Hugging Face task)
20
+ results = self.detector(rgb_frame)
21
+
22
+ # Annotate the frame with detection results
23
+ for result in results:
24
+ box = result['box']
25
+ label = result['label']
26
+ score = result['score']
27
+ x1, y1, x2, y2 = box
28
+ cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
29
+ cv2.putText(frame, f"{label}: {score:.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
30
+
31
+ return frame
32
 
33
  def play(self):
34
  while True:
 
41
  print("End of video")
42
  break
43
 
44
+ # Process the frame using Hugging Face (can be changed to any other task)
45
+ self.frame = self.process_frame(self.frame)
46
+
47
  # Show the current frame
48
  cv2.imshow('Video Player', self.frame)
49