Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,11 @@ classification_model_id = "MCG-NJU/videomae-base"
|
|
9 |
|
10 |
# Object detection model (you can replace this with a more accurate one if needed)
|
11 |
object_detection_model = "yolov5s"
|
|
|
|
|
12 |
TARGET_FRAME_COUNT = 16
|
13 |
-
FRAME_SIZE = (224, 224)
|
|
|
14 |
def analyze_video(video):
|
15 |
# Extract key frames from the video using OpenCV
|
16 |
frames = extract_key_frames(video)
|
@@ -52,9 +55,12 @@ def extract_key_frames(video):
|
|
52 |
frames = []
|
53 |
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
54 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
|
|
|
|
55 |
for i in range(frame_count):
|
56 |
ret, frame = cap.read()
|
57 |
-
if ret and i %
|
|
|
58 |
frames.append(frame)
|
59 |
cap.release()
|
60 |
return frames
|
|
|
9 |
|
10 |
# Object detection model (you can replace this with a more accurate one if needed)
|
11 |
object_detection_model = "yolov5s"
|
12 |
+
|
13 |
+
# Parameters for frame extraction
|
14 |
TARGET_FRAME_COUNT = 16
|
15 |
+
FRAME_SIZE = (224, 224) # Expected frame size for the model
|
16 |
+
|
17 |
def analyze_video(video):
|
18 |
# Extract key frames from the video using OpenCV
|
19 |
frames = extract_key_frames(video)
|
|
|
55 |
frames = []
|
56 |
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
57 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
58 |
+
interval = max(1, frame_count // TARGET_FRAME_COUNT)
|
59 |
+
|
60 |
for i in range(frame_count):
|
61 |
ret, frame = cap.read()
|
62 |
+
if ret and i % interval == 0: # Extract frames at regular intervals
|
63 |
+
frame = cv2.resize(frame, FRAME_SIZE) # Resize frame
|
64 |
frames.append(frame)
|
65 |
cap.release()
|
66 |
return frames
|