Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -66,20 +66,26 @@ def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8)
|
|
66 |
(width, height)
|
67 |
)
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
# 设置推理参数并处理视频
|
70 |
results = model.predict(
|
71 |
source=video_path,
|
72 |
device=device,
|
73 |
-
conf=conf_threshold,
|
74 |
save=False,
|
75 |
show=False,
|
76 |
stream=True,
|
77 |
-
line_width=
|
78 |
show_boxes=True,
|
79 |
show_labels=True,
|
80 |
show_conf=True,
|
81 |
vid_stride=1,
|
82 |
-
max_det=max_det,
|
83 |
)
|
84 |
|
85 |
# 处理结果
|
@@ -90,6 +96,19 @@ def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8)
|
|
90 |
# 获取绘制了预测结果的帧
|
91 |
frame = r.plot()
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
# 收集检测信息
|
94 |
frame_info = {
|
95 |
"frame": frame_count + 1,
|
|
|
66 |
(width, height)
|
67 |
)
|
68 |
|
69 |
+
# 计算点的大小
|
70 |
+
# 基于视频分辨率计算合适的点大小
|
71 |
+
base_size = min(width, height)
|
72 |
+
point_size = max(1, int(base_size * 0.005)) # 0.5% 的最小边长作为点大小
|
73 |
+
line_thickness = max(1, int(base_size * 0.002)) # 0.2% 的最小边长作为线宽
|
74 |
+
|
75 |
# 设置推理参数并处理视频
|
76 |
results = model.predict(
|
77 |
source=video_path,
|
78 |
device=device,
|
79 |
+
conf=conf_threshold,
|
80 |
save=False,
|
81 |
show=False,
|
82 |
stream=True,
|
83 |
+
line_width=line_thickness, # 使用计算出的线宽
|
84 |
show_boxes=True,
|
85 |
show_labels=True,
|
86 |
show_conf=True,
|
87 |
vid_stride=1,
|
88 |
+
max_det=max_det,
|
89 |
)
|
90 |
|
91 |
# 处理结果
|
|
|
96 |
# 获取绘制了预测结果的帧
|
97 |
frame = r.plot()
|
98 |
|
99 |
+
# 如果需要自定义绘制姿态点
|
100 |
+
if hasattr(r, 'keypoints') and r.keypoints is not None:
|
101 |
+
for kpts in r.keypoints:
|
102 |
+
for x, y, conf in kpts:
|
103 |
+
if conf > conf_threshold:
|
104 |
+
cv2.circle(
|
105 |
+
frame,
|
106 |
+
(int(x), int(y)),
|
107 |
+
point_size, # 使用计算出的点大小
|
108 |
+
(0, 255, 0),
|
109 |
+
-1 # -1 表示填充圆
|
110 |
+
)
|
111 |
+
|
112 |
# 收集检测信息
|
113 |
frame_info = {
|
114 |
"frame": frame_count + 1,
|