Spaces:
Sleeping
Sleeping
allow client to select video index
Browse files
app.py
CHANGED
@@ -32,19 +32,19 @@ def draw_stats(frame: MatLike, session: Session):
|
|
32 |
"""
|
33 |
|
34 |
y0, dy = 30, 36
|
35 |
-
for i, line in enumerate(text.split(
|
36 |
(text_width, text_height), _ = cv2.getTextSize(line, font, font_scale, thickness)
|
37 |
x = frame.shape[1] - text_width - 10
|
38 |
y = y0 + (i - 1) * dy
|
39 |
cv2.putText(frame, line, (x, y), font, font_scale, color, thickness, cv2.LINE_AA)
|
40 |
|
41 |
-
def process_frame(session_id: str):
|
42 |
global sessions
|
43 |
|
44 |
session: Session = sessions.get(session_id, None)
|
45 |
|
46 |
if session is not None:
|
47 |
-
cap = cv2.VideoCapture(
|
48 |
framerate = cap.get(cv2.CAP_PROP_FPS)
|
49 |
frame_duration = 1 / framerate
|
50 |
|
@@ -107,13 +107,17 @@ def stream_mjpeg(session_id: str):
|
|
107 |
def get_video():
|
108 |
global sessions
|
109 |
|
110 |
-
session_id = request.args.get("
|
111 |
show_stats = request.args.get("show_stats", "1") == "1"
|
112 |
|
|
|
|
|
|
|
|
|
113 |
if session_id not in sessions:
|
114 |
session = Session(session_id)
|
115 |
sessions[session_id] = session
|
116 |
-
threading.Thread(target=process_frame, args=[session_id], daemon=True).start()
|
117 |
else:
|
118 |
session = sessions[session_id]
|
119 |
session.show_stats = show_stats
|
|
|
32 |
"""
|
33 |
|
34 |
y0, dy = 30, 36
|
35 |
+
for i, line in enumerate(text.split("\n")):
|
36 |
(text_width, text_height), _ = cv2.getTextSize(line, font, font_scale, thickness)
|
37 |
x = frame.shape[1] - text_width - 10
|
38 |
y = y0 + (i - 1) * dy
|
39 |
cv2.putText(frame, line, (x, y), font, font_scale, color, thickness, cv2.LINE_AA)
|
40 |
|
41 |
+
def process_frame(session_id: str, video_path: str):
|
42 |
global sessions
|
43 |
|
44 |
session: Session = sessions.get(session_id, None)
|
45 |
|
46 |
if session is not None:
|
47 |
+
cap = cv2.VideoCapture(video_path)
|
48 |
framerate = cap.get(cv2.CAP_PROP_FPS)
|
49 |
frame_duration = 1 / framerate
|
50 |
|
|
|
107 |
def get_video():
|
108 |
global sessions
|
109 |
|
110 |
+
session_id = request.args.get("video_index", "0")
|
111 |
show_stats = request.args.get("show_stats", "1") == "1"
|
112 |
|
113 |
+
video_index = int(request.args.get("video_index", 0)) % 4
|
114 |
+
video_files = sorted([f for f in os.listdir("videos") if f.lower().endswith((".mp4", ".avi", ".mov"))])
|
115 |
+
video_path = os.path.join("videos", video_files[int(video_index)])
|
116 |
+
|
117 |
if session_id not in sessions:
|
118 |
session = Session(session_id)
|
119 |
sessions[session_id] = session
|
120 |
+
threading.Thread(target=process_frame, args=[session_id, video_path], daemon=True).start()
|
121 |
else:
|
122 |
session = sessions[session_id]
|
123 |
session.show_stats = show_stats
|
videos/bottle-detection.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d52ba94aedf8a923c342fe9ea1d2bd85f712c4cc0f49a6de1bac43eebe3a48ff
|
3 |
+
size 504961
|
classroom.mp4 → videos/classroom.mp4
RENAMED
File without changes
|
videos/head-pose-face-detection-female-and-male.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:650166430c4bf9ddc470ac17a86d1fcbd6d76c64e60ed73675fdc6b3e3d3af38
|
3 |
+
size 16788193
|
videos/worker-zone-detection.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b8b58b8100a81600bc42ee7ee082ced777b12a32a3619139ef289d27cbdcd284
|
3 |
+
size 12596893
|