Hakureirm commited on
Commit
d080468
·
verified ·
1 Parent(s): 72f5340

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -103,14 +103,22 @@ def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8)
103
  for kpts in r.keypoints:
104
  if isinstance(kpts, torch.Tensor):
105
  kpts = kpts.cpu().numpy()
106
- # 使用第一个关键点(比如头部)作为位置参考
107
- if len(kpts) > 0:
108
- pos = kpts[0][:2] # 取x,y坐标
109
- all_positions.append(pos)
110
- # 更新热图
111
- x, y = int(pos[0]), int(pos[1])
112
- if 0 <= x < width and 0 <= y < height:
113
- heatmap[y, x] += 1
 
 
 
 
 
 
 
 
114
 
115
  # 收集检测信息
116
  frame_info = {
 
103
  for kpts in r.keypoints:
104
  if isinstance(kpts, torch.Tensor):
105
  kpts = kpts.cpu().numpy()
106
+ # 打印关键点格式以便调试
107
+ # print(f"Keypoints shape: {kpts.shape}")
108
+
109
+ # 确保关键点数据是正确的格式
110
+ if isinstance(kpts, np.ndarray):
111
+ if len(kpts.shape) == 2: # [n_points, 2/3]
112
+ if kpts.shape[0] > 0: # 确保有关键点
113
+ # 使用第一个关键点
114
+ if kpts.shape[1] >= 2: # 确保有x,y坐标
115
+ x, y = kpts[0, 0], kpts[0, 1]
116
+ if isinstance(x, (int, float)) and isinstance(y, (int, float)):
117
+ x, y = int(x), int(y)
118
+ all_positions.append([x, y])
119
+ # 更新热图
120
+ if 0 <= x < width and 0 <= y < height:
121
+ heatmap[y, x] += 1
122
 
123
  # 收集检测信息
124
  frame_info = {