kinemotion 0.45.0__py3-none-any.whl → 0.45.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kinemotion might be problematic. Click here for more details.

kinemotion/api.py CHANGED
@@ -78,6 +78,69 @@ class DropJumpVideoConfig:
78
78
  tracking_confidence: float | None = None
79
79
 
80
80
 
81
+ def _generate_debug_video(
82
+ output_video: str,
83
+ frames: list,
84
+ frame_indices: list[int],
85
+ video_fps: float,
86
+ smoothed_landmarks: list,
87
+ contact_states: list,
88
+ metrics: DropJumpMetrics,
89
+ timer: PerformanceTimer | None,
90
+ verbose: bool,
91
+ ) -> None:
92
+ """Generate debug video with overlay."""
93
+ if verbose:
94
+ print(f"Generating debug video: {output_video}")
95
+
96
+ if not frames:
97
+ return
98
+
99
+ debug_h, debug_w = frames[0].shape[:2]
100
+
101
+ if video_fps > 30:
102
+ debug_fps = video_fps / (video_fps / 30.0)
103
+ else:
104
+ debug_fps = video_fps
105
+
106
+ if len(frames) < len(smoothed_landmarks):
107
+ step = max(1, int(video_fps / 30.0))
108
+ debug_fps = video_fps / step
109
+
110
+ def _render_frames(renderer: DebugOverlayRenderer) -> None:
111
+ for frame, idx in zip(frames, frame_indices, strict=True):
112
+ annotated = renderer.render_frame(
113
+ frame,
114
+ smoothed_landmarks[idx],
115
+ contact_states[idx],
116
+ idx,
117
+ metrics,
118
+ use_com=False,
119
+ )
120
+ renderer.write_frame(annotated)
121
+
122
+ renderer_context = DebugOverlayRenderer(
123
+ output_video,
124
+ debug_w,
125
+ debug_h,
126
+ debug_w,
127
+ debug_h,
128
+ debug_fps,
129
+ timer=timer,
130
+ )
131
+
132
+ if timer:
133
+ with timer.measure("debug_video_generation"):
134
+ with renderer_context as renderer:
135
+ _render_frames(renderer)
136
+ else:
137
+ with renderer_context as renderer:
138
+ _render_frames(renderer)
139
+
140
+ if verbose:
141
+ print(f"Debug video saved: {output_video}")
142
+
143
+
81
144
  def process_dropjump_video(
82
145
  video_path: str,
83
146
  quality: str = "balanced",
@@ -285,64 +348,17 @@ def process_dropjump_video(
285
348
  print()
286
349
 
287
350
  if output_video:
288
- if verbose:
289
- print(f"Generating debug video: {output_video}")
290
-
291
- debug_h, debug_w = frames[0].shape[:2]
292
- if video.fps > 30:
293
- debug_fps = video.fps / (video.fps / 30.0)
294
- else:
295
- debug_fps = video.fps
296
- if len(frames) < len(landmarks_sequence):
297
- step = max(1, int(video.fps / 30.0))
298
- debug_fps = video.fps / step
299
-
300
- if timer:
301
- with timer.measure("debug_video_generation"):
302
- with DebugOverlayRenderer(
303
- output_video,
304
- debug_w,
305
- debug_h,
306
- debug_w,
307
- debug_h,
308
- debug_fps,
309
- timer=timer,
310
- ) as renderer:
311
- for frame, idx in zip(frames, frame_indices, strict=True):
312
- annotated = renderer.render_frame(
313
- frame,
314
- smoothed_landmarks[idx],
315
- contact_states[idx],
316
- idx,
317
- metrics,
318
- use_com=False,
319
- )
320
- renderer.write_frame(annotated)
321
- with timer.measure("debug_video_reencode"):
322
- pass
323
- else:
324
- with DebugOverlayRenderer(
325
- output_video,
326
- debug_w,
327
- debug_h,
328
- debug_w,
329
- debug_h,
330
- debug_fps,
331
- timer=timer,
332
- ) as renderer:
333
- for frame, idx in zip(frames, frame_indices, strict=True):
334
- annotated = renderer.render_frame(
335
- frame,
336
- smoothed_landmarks[idx],
337
- contact_states[idx],
338
- idx,
339
- metrics,
340
- use_com=False,
341
- )
342
- renderer.write_frame(annotated)
343
-
344
- if verbose:
345
- print(f"Debug video saved: {output_video}")
351
+ _generate_debug_video(
352
+ output_video,
353
+ frames,
354
+ frame_indices,
355
+ video.fps,
356
+ smoothed_landmarks,
357
+ contact_states,
358
+ metrics,
359
+ timer,
360
+ verbose,
361
+ )
346
362
 
347
363
  with timer.measure("metrics_validation"):
348
364
  validator = DropJumpMetricsValidator()
@@ -738,8 +754,6 @@ def process_cmj_video(
738
754
  frame, smoothed_landmarks[idx], idx, metrics
739
755
  )
740
756
  renderer.write_frame(annotated)
741
- with timer.measure("debug_video_reencode"):
742
- pass
743
757
  else:
744
758
  with CMJDebugOverlayRenderer(
745
759
  output_video,
kinemotion/cmj/cli.py CHANGED
@@ -3,11 +3,10 @@
3
3
  import json
4
4
  import sys
5
5
  from dataclasses import dataclass
6
- from typing import Any
7
6
 
8
7
  import click
9
8
 
10
- from ..api import process_cmj_video
9
+ from ..api import CMJMetrics, process_cmj_video
11
10
  from ..core.auto_tuning import QualityPreset
12
11
  from ..core.cli_utils import (
13
12
  collect_video_files,
@@ -287,7 +286,7 @@ def _process_single(
287
286
  sys.exit(1)
288
287
 
289
288
 
290
- def _output_results(metrics: Any, json_output: str | None) -> None:
289
+ def _output_results(metrics: CMJMetrics, json_output: str | None) -> None:
291
290
  """Output analysis results."""
292
291
  results = metrics.to_dict()
293
292
 
@@ -5,6 +5,7 @@ import shutil
5
5
  import subprocess
6
6
  import time
7
7
  from pathlib import Path
8
+ from typing import Self
8
9
 
9
10
  import cv2
10
11
  import numpy as np
@@ -251,7 +252,7 @@ class BaseDebugOverlayRenderer:
251
252
  if temp_path and os.path.exists(temp_path):
252
253
  os.remove(temp_path)
253
254
 
254
- def __enter__(self) -> "BaseDebugOverlayRenderer":
255
+ def __enter__(self) -> Self:
255
256
  return self
256
257
 
257
258
  def __exit__(self, _exc_type, _exc_val, _exc_tb) -> None: # type: ignore[no-untyped-def]
@@ -1,4 +1,4 @@
1
- """Shared pipeline utilities for kinematic analysis."""
1
+ "Shared pipeline utilities for kinematic analysis."
2
2
 
3
3
  from collections.abc import Callable
4
4
  from concurrent.futures import ProcessPoolExecutor, as_completed
@@ -140,6 +140,44 @@ def print_verbose_parameters(
140
140
  print("=" * 60 + "\n")
141
141
 
142
142
 
143
+ def _process_frames_loop(
144
+ video: VideoProcessor,
145
+ tracker: PoseTracker,
146
+ step: int,
147
+ should_resize: bool,
148
+ debug_w: int,
149
+ debug_h: int,
150
+ ) -> tuple[list, list, list]:
151
+ """Internal loop for processing frames to reduce complexity."""
152
+ landmarks_sequence = []
153
+ debug_frames = []
154
+ frame_indices = []
155
+ frame_idx = 0
156
+
157
+ while True:
158
+ frame = video.read_frame()
159
+ if frame is None:
160
+ break
161
+
162
+ landmarks = tracker.process_frame(frame)
163
+ landmarks_sequence.append(landmarks)
164
+
165
+ if frame_idx % step == 0:
166
+ if should_resize:
167
+ processed_frame = cv2.resize(
168
+ frame, (debug_w, debug_h), interpolation=cv2.INTER_LINEAR
169
+ )
170
+ else:
171
+ processed_frame = frame
172
+
173
+ debug_frames.append(processed_frame)
174
+ frame_indices.append(frame_idx)
175
+
176
+ frame_idx += 1
177
+
178
+ return debug_frames, landmarks_sequence, frame_indices
179
+
180
+
143
181
  def process_all_frames(
144
182
  video: VideoProcessor,
145
183
  tracker: PoseTracker,
@@ -169,10 +207,6 @@ def process_all_frames(
169
207
  if verbose:
170
208
  print("Tracking pose landmarks...")
171
209
 
172
- landmarks_sequence = []
173
- debug_frames = []
174
- frame_indices = []
175
-
176
210
  step = max(1, int(video.fps / target_debug_fps))
177
211
 
178
212
  w, h = video.display_width, video.display_height
@@ -184,51 +218,15 @@ def process_all_frames(
184
218
  debug_h = int(h * scale) // 2 * 2
185
219
  should_resize = (debug_w != video.width) or (debug_h != video.height)
186
220
 
187
- frame_idx = 0
188
-
189
221
  if timer:
190
222
  with timer.measure("pose_tracking"):
191
- while True:
192
- frame = video.read_frame()
193
- if frame is None:
194
- break
195
-
196
- landmarks = tracker.process_frame(frame)
197
- landmarks_sequence.append(landmarks)
198
-
199
- if frame_idx % step == 0:
200
- if should_resize:
201
- processed_frame = cv2.resize(
202
- frame, (debug_w, debug_h), interpolation=cv2.INTER_LINEAR
203
- )
204
- else:
205
- processed_frame = frame
206
-
207
- debug_frames.append(processed_frame)
208
- frame_indices.append(frame_idx)
209
-
210
- frame_idx += 1
223
+ debug_frames, landmarks_sequence, frame_indices = _process_frames_loop(
224
+ video, tracker, step, should_resize, debug_w, debug_h
225
+ )
211
226
  else:
212
- while True:
213
- frame = video.read_frame()
214
- if frame is None:
215
- break
216
-
217
- landmarks = tracker.process_frame(frame)
218
- landmarks_sequence.append(landmarks)
219
-
220
- if frame_idx % step == 0:
221
- if should_resize:
222
- processed_frame = cv2.resize(
223
- frame, (debug_w, debug_h), interpolation=cv2.INTER_LINEAR
224
- )
225
- else:
226
- processed_frame = frame
227
-
228
- debug_frames.append(processed_frame)
229
- frame_indices.append(frame_idx)
230
-
231
- frame_idx += 1
227
+ debug_frames, landmarks_sequence, frame_indices = _process_frames_loop(
228
+ video, tracker, step, should_resize, debug_w, debug_h
229
+ )
232
230
 
233
231
  if close_tracker:
234
232
  tracker.close()
@@ -256,22 +254,19 @@ def apply_smoothing(
256
254
  Returns:
257
255
  Smoothed landmarks sequence
258
256
  """
259
- if params.outlier_rejection or params.bilateral_filter:
260
- if verbose:
257
+ use_advanced = params.outlier_rejection or params.bilateral_filter
258
+
259
+ if verbose:
260
+ if use_advanced:
261
261
  if params.outlier_rejection:
262
262
  print("Smoothing landmarks with outlier rejection...")
263
263
  if params.bilateral_filter:
264
264
  print("Using bilateral temporal filter...")
265
- if timer:
266
- with timer.measure("smoothing"):
267
- return smooth_landmarks_advanced(
268
- landmarks_sequence,
269
- window_length=params.smoothing_window,
270
- polyorder=params.polyorder,
271
- use_outlier_rejection=params.outlier_rejection,
272
- use_bilateral=params.bilateral_filter,
273
- )
274
265
  else:
266
+ print("Smoothing landmarks...")
267
+
268
+ def _run_smoothing() -> list:
269
+ if use_advanced:
275
270
  return smooth_landmarks_advanced(
276
271
  landmarks_sequence,
277
272
  window_length=params.smoothing_window,
@@ -279,16 +274,6 @@ def apply_smoothing(
279
274
  use_outlier_rejection=params.outlier_rejection,
280
275
  use_bilateral=params.bilateral_filter,
281
276
  )
282
- else:
283
- if verbose:
284
- print("Smoothing landmarks...")
285
- if timer:
286
- with timer.measure("smoothing"):
287
- return smooth_landmarks(
288
- landmarks_sequence,
289
- window_length=params.smoothing_window,
290
- polyorder=params.polyorder,
291
- )
292
277
  else:
293
278
  return smooth_landmarks(
294
279
  landmarks_sequence,
@@ -296,6 +281,11 @@ def apply_smoothing(
296
281
  polyorder=params.polyorder,
297
282
  )
298
283
 
284
+ if timer:
285
+ with timer.measure("smoothing"):
286
+ return _run_smoothing()
287
+ return _run_smoothing()
288
+
299
289
 
300
290
  def calculate_foot_visibility(frame_landmarks: dict) -> float:
301
291
  """Calculate average visibility of foot landmarks.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kinemotion
3
- Version: 0.45.0
3
+ Version: 0.45.1
4
4
  Summary: Video-based kinematic analysis for athletic performance
5
5
  Project-URL: Homepage, https://github.com/feniix/kinemotion
6
6
  Project-URL: Repository, https://github.com/feniix/kinemotion
@@ -1,9 +1,9 @@
1
1
  kinemotion/__init__.py,sha256=wPItmyGJUOFM6GPRVhAEvRz0-ErI7e2qiUREYJ9EfPQ,943
2
- kinemotion/api.py,sha256=ltOsxG9QGFqkBW15czaQ0Rn_Ed9Nh_qKYXBTiSBopXU,33181
2
+ kinemotion/api.py,sha256=AWURqiz0SI1BGh6mTlywTOWKFGrXyoZJbmo_t6sRkjQ,32538
3
3
  kinemotion/cli.py,sha256=cqYV_7URH0JUDy1VQ_EDLv63FmNO4Ns20m6s1XAjiP4,464
4
4
  kinemotion/cmj/__init__.py,sha256=Ynv0-Oco4I3Y1Ubj25m3h9h2XFqeNwpAewXmAYOmwfU,127
5
5
  kinemotion/cmj/analysis.py,sha256=qtULzp9uYzm5M0_Qu5YGJpuwjg9fz1VKAg6xg4NJxvM,21639
6
- kinemotion/cmj/cli.py,sha256=d3_lX-zstch52BxDZUQJyTBpkr2YKwkOE0gUW6nAUb0,9908
6
+ kinemotion/cmj/cli.py,sha256=HpZgLWoLjcgsfOZu6EQ_26tg6QwTgFjR-Ly8WCBg24c,9904
7
7
  kinemotion/cmj/debug_overlay.py,sha256=fXmWoHhqMLGo4vTtB6Ezs3yLUDOLw63zLIgU2gFlJQU,15892
8
8
  kinemotion/cmj/joint_angles.py,sha256=HmheIEiKcQz39cRezk4h-htorOhGNPsqKIR9RsAEKts,9960
9
9
  kinemotion/cmj/kinematics.py,sha256=Lq9m9MNQxnXv31VhKmXVrlM7rRkhi8PxW50N_CC8_8Y,11860
@@ -12,13 +12,13 @@ kinemotion/cmj/validation_bounds.py,sha256=9ZTo68fl3ooyWjXXyTMRLpK9tFANa_rQf3oHh
12
12
  kinemotion/core/__init__.py,sha256=GTLnE_gGIk7HC51epWUXVuNxcvS5lf7UL6qeWRlgMV0,1352
13
13
  kinemotion/core/auto_tuning.py,sha256=wtCUMOhBChVJNXfEeku3GCMW4qED6MF-O_mv2sPTiVQ,11324
14
14
  kinemotion/core/cli_utils.py,sha256=sQPbT6XWWau-sm9yuN5c3eS5xNzoQGGXwSz6hQXtRvM,1859
15
- kinemotion/core/debug_overlay_utils.py,sha256=vOoWv3vlNdNgPI2R-UwAZKtSpugUUsiokR_kvaz1UWg,9025
15
+ kinemotion/core/debug_overlay_utils.py,sha256=Eu4GXm8VeaDhU7voDjPJ4JvR-7ypT1mYmCz0d-M39N4,9027
16
16
  kinemotion/core/determinism.py,sha256=NwVrHqJiVxxFHTBPVy8aDBJH2SLIcYIpdGFp7glblB8,2515
17
17
  kinemotion/core/experimental.py,sha256=IK05AF4aZS15ke85hF3TWCqRIXU1AlD_XKzFz735Ua8,3640
18
18
  kinemotion/core/filtering.py,sha256=GsC9BB71V07LJJHgS2lsaxUAtJsupcUiwtZFDgODh8c,11417
19
19
  kinemotion/core/formatting.py,sha256=G_3eqgOtym9RFOZVEwCxye4A2cyrmgvtQ214vIshowU,2480
20
20
  kinemotion/core/metadata.py,sha256=bJAVa4nym__zx1hNowSZduMGKBSGOPxTbBQkjm6N0D0,7207
21
- kinemotion/core/pipeline_utils.py,sha256=s-2AJEt_beugjbCsiNyKVSc7YBdlgc9aocR_ZSX9PfQ,14783
21
+ kinemotion/core/pipeline_utils.py,sha256=n6ee90xOYfBGkDCM1_F2rpYVsC3wWyKSTtWpAFz0Fh0,14161
22
22
  kinemotion/core/pose.py,sha256=Tq4VS0YmMzrprVUsELm6FQczyLhP8UKurM9ccYn1LLU,8959
23
23
  kinemotion/core/quality.py,sha256=dPGQp08y8DdEUbUdjTThnUOUsALgF0D2sdz50cm6wLI,13098
24
24
  kinemotion/core/smoothing.py,sha256=GAfC-jxu1eqNyDjsUXqUBicKx9um5hrk49wz1FxfRNM,15219
@@ -33,8 +33,8 @@ kinemotion/dropjump/kinematics.py,sha256=kH-XM66wlOCYMpjvyb6_Qh5ZebyOfFZ47rmhgE1
33
33
  kinemotion/dropjump/metrics_validator.py,sha256=CrTlGup8q2kyPXtA6HNwm7_yq0AsBaDllG7RVZdXmYA,9342
34
34
  kinemotion/dropjump/validation_bounds.py,sha256=5b4I3CKPybuvrbn-nP5yCcGF_sH4Vtyw3a5AWWvWnBk,4645
35
35
  kinemotion/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
- kinemotion-0.45.0.dist-info/METADATA,sha256=pzhaPBL4rK6K3JJvLgFSQDL4rzS0cDRY77yke4iV7b4,26020
37
- kinemotion-0.45.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
- kinemotion-0.45.0.dist-info/entry_points.txt,sha256=zaqnAnjLvcdrk1Qvj5nvXZCZ2gp0prS7it1zTJygcIY,50
39
- kinemotion-0.45.0.dist-info/licenses/LICENSE,sha256=KZajvqsHw0NoOHOi2q0FZ4NBe9HdV6oey-IPYAtHXfg,1088
40
- kinemotion-0.45.0.dist-info/RECORD,,
36
+ kinemotion-0.45.1.dist-info/METADATA,sha256=MwXnUwq8AHXBwGJkLbfzc956Bwr15ZfANbyaCMCstDQ,26020
37
+ kinemotion-0.45.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
+ kinemotion-0.45.1.dist-info/entry_points.txt,sha256=zaqnAnjLvcdrk1Qvj5nvXZCZ2gp0prS7it1zTJygcIY,50
39
+ kinemotion-0.45.1.dist-info/licenses/LICENSE,sha256=KZajvqsHw0NoOHOi2q0FZ4NBe9HdV6oey-IPYAtHXfg,1088
40
+ kinemotion-0.45.1.dist-info/RECORD,,