Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,10 @@ def count_unique_trucks(video_path):
|
|
28 |
unique_truck_ids = set()
|
29 |
truck_history = {}
|
30 |
|
31 |
-
|
|
|
|
|
|
|
32 |
frame_count = 0
|
33 |
|
34 |
while True:
|
@@ -38,7 +41,7 @@ def count_unique_trucks(video_path):
|
|
38 |
|
39 |
frame_count += 1
|
40 |
if frame_count % frame_skip != 0:
|
41 |
-
continue # Skip frames to
|
42 |
|
43 |
# Run YOLOv12x inference
|
44 |
results = model(frame, verbose=False)
|
@@ -84,22 +87,3 @@ def count_unique_trucks(video_path):
|
|
84 |
cap.release()
|
85 |
|
86 |
return {"Total Unique Trucks": len(unique_truck_ids)}
|
87 |
-
|
88 |
-
# Gradio UI function
|
89 |
-
def analyze_video(video_file):
|
90 |
-
result = count_unique_trucks(video_file)
|
91 |
-
return "\n".join([f"{key}: {value}" for key, value in result.items()])
|
92 |
-
|
93 |
-
# Define Gradio interface
|
94 |
-
import gradio as gr
|
95 |
-
iface = gr.Interface(
|
96 |
-
fn=analyze_video,
|
97 |
-
inputs=gr.Video(label="Upload Video"),
|
98 |
-
outputs=gr.Textbox(label="Analysis Result"),
|
99 |
-
title="YOLOv12x Unique Truck Counter",
|
100 |
-
description="Upload a video to count unique trucks using YOLOv12x and SORT tracking."
|
101 |
-
)
|
102 |
-
|
103 |
-
# Launch the Gradio app
|
104 |
-
if __name__ == "__main__":
|
105 |
-
iface.launch()
|
|
|
28 |
unique_truck_ids = set()
|
29 |
truck_history = {}
|
30 |
|
31 |
+
# Get FPS of the video
|
32 |
+
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
33 |
+
frame_skip = fps * 7 # Skip frames every 5 seconds
|
34 |
+
|
35 |
frame_count = 0
|
36 |
|
37 |
while True:
|
|
|
41 |
|
42 |
frame_count += 1
|
43 |
if frame_count % frame_skip != 0:
|
44 |
+
continue # Skip frames to process only every 5 seconds
|
45 |
|
46 |
# Run YOLOv12x inference
|
47 |
results = model(frame, verbose=False)
|
|
|
87 |
cap.release()
|
88 |
|
89 |
return {"Total Unique Trucks": len(unique_truck_ids)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|