Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -168,7 +168,7 @@ def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8)
|
|
168 |
|
169 |
pbar.close() # 关闭进度条
|
170 |
video_writer.release()
|
171 |
-
logger.info(f"
|
172 |
|
173 |
# 生成分析报告
|
174 |
confidences = [float(det['confidence'].strip('%'))/100 for info in detection_info for det in info['detections']]
|
@@ -299,7 +299,7 @@ def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8)
|
|
299 |
base_trajectory = np.zeros((height, width, 3), dtype=np.uint8) + 255
|
300 |
base_heatmap = np.zeros((height, width), dtype=np.float32)
|
301 |
|
302 |
-
frame_interval = max(1, len(filtered_points) //
|
303 |
|
304 |
for i in range(0, len(filtered_points), frame_interval):
|
305 |
current_points = filtered_points[:i+1]
|
@@ -343,6 +343,10 @@ def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8)
|
|
343 |
trajectory_path = output_path.replace('.mp4', '_trajectory.png')
|
344 |
heatmap_path = output_path.replace('.mp4', '_heatmap.png')
|
345 |
cv2.imwrite(trajectory_path, trajectory_img)
|
|
|
|
|
|
|
|
|
346 |
cv2.imwrite(heatmap_path, heatmap_colored)
|
347 |
|
348 |
logger.info("轨迹图和热力图生成完成")
|
@@ -490,4 +494,15 @@ with gr.Blocks() as demo:
|
|
490 |
)
|
491 |
|
492 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
168 |
|
169 |
pbar.close() # 关闭进度条
|
170 |
video_writer.release()
|
171 |
+
logger.info(f"视频处理完成,共处理 {frame_count} 帧")
|
172 |
|
173 |
# 生成分析报告
|
174 |
confidences = [float(det['confidence'].strip('%'))/100 for info in detection_info for det in info['detections']]
|
|
|
299 |
base_trajectory = np.zeros((height, width, 3), dtype=np.uint8) + 255
|
300 |
base_heatmap = np.zeros((height, width), dtype=np.float32)
|
301 |
|
302 |
+
frame_interval = max(1, len(filtered_points) // 30)
|
303 |
|
304 |
for i in range(0, len(filtered_points), frame_interval):
|
305 |
current_points = filtered_points[:i+1]
|
|
|
343 |
trajectory_path = output_path.replace('.mp4', '_trajectory.png')
|
344 |
heatmap_path = output_path.replace('.mp4', '_heatmap.png')
|
345 |
cv2.imwrite(trajectory_path, trajectory_img)
|
346 |
+
if np.max(heatmap) > 0:
|
347 |
+
heatmap_normalized = cv2.normalize(heatmap, None, 0, 255, cv2.NORM_MINMAX)
|
348 |
+
heatmap_colored = cv2.applyColorMap(heatmap_normalized.astype(np.uint8), cv2.COLORMAP_JET)
|
349 |
+
heatmap_colored = cv2.addWeighted(heatmap_colored, 0.7, np.full_like(heatmap_colored, 255), 0.3, 0)
|
350 |
cv2.imwrite(heatmap_path, heatmap_colored)
|
351 |
|
352 |
logger.info("轨迹图和热力图生成完成")
|
|
|
494 |
)
|
495 |
|
496 |
if __name__ == "__main__":
|
497 |
+
try:
|
498 |
+
# GPU相关操作
|
499 |
+
if torch.cuda.is_available():
|
500 |
+
logger.info("使用GPU进行轨迹和热力图计算")
|
501 |
+
# ... GPU操作 ...
|
502 |
+
else:
|
503 |
+
logger.info("使用CPU进行轨迹和热力图计算")
|
504 |
+
# ... CPU操作 ...
|
505 |
+
except Exception as e:
|
506 |
+
logger.error(f"处理轨迹和热力图时出错: {str(e)}")
|
507 |
+
raise
|
508 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|