kinemotion 0.1.0__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.

@@ -0,0 +1,381 @@
1
+ Metadata-Version: 2.4
2
+ Name: kinemotion
3
+ Version: 0.1.0
4
+ Summary: Video-based kinematic analysis for athletic performance
5
+ Project-URL: Homepage, https://github.com/feniix/kinemetry
6
+ Project-URL: Repository, https://github.com/feniix/kinemetry
7
+ Project-URL: Issues, https://github.com/feniix/kinemetry/issues
8
+ Author-email: Sebastian Otaegui <feniix@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: athletic-performance,drop-jump,kinemetry,mediapipe,pose-tracking,video-analysis
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Multimedia :: Video
20
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
21
+ Requires-Python: <3.13,>=3.10
22
+ Requires-Dist: click>=8.1.7
23
+ Requires-Dist: mediapipe>=0.10.9
24
+ Requires-Dist: numpy>=1.26.0
25
+ Requires-Dist: opencv-python>=4.9.0
26
+ Requires-Dist: scipy>=1.11.0
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Kinemetry
30
+
31
+ A video-based kinematic analysis tool for athletic performance. Analyzes side-view drop-jump videos to estimate key performance metrics: ground contact time, flight time, and jump height. Uses MediaPipe pose tracking and advanced kinematics.
32
+
33
+ ## Features
34
+
35
+ - **Automatic pose tracking** using MediaPipe Pose landmarks
36
+ - **Ground contact detection** based on foot velocity and position
37
+ - **Derivative-based velocity** - smooth velocity calculation from position trajectory
38
+ - **Trajectory curvature analysis** - acceleration patterns for refined event detection
39
+ - **Sub-frame interpolation** - precise timing beyond frame boundaries for improved accuracy
40
+ - **Automatic drop jump detection** - identifies box → drop → landing → jump phases
41
+ - **Kinematic calculations** for jump metrics:
42
+ - Ground contact time (ms)
43
+ - Flight time (ms)
44
+ - Jump height (m) - with optional calibration using drop box height
45
+ - **Calibrated measurements** - use known drop height for ~88% accuracy (vs 71% uncalibrated)
46
+ - **JSON output** for easy integration with other tools
47
+ - **Optional debug video** with visual overlays showing contact states and landmarks
48
+ - **Configurable parameters** for smoothing, thresholds, and detection
49
+
50
+ ## Setup
51
+
52
+ ### Prerequisites
53
+
54
+ - [asdf](https://asdf-vm.com/) version manager
55
+ - asdf plugins for Python and uv
56
+
57
+ ### Installation
58
+
59
+ 1. **Install asdf plugins** (if not already installed):
60
+
61
+ ```bash
62
+ asdf plugin add python
63
+ asdf plugin add uv
64
+ ```
65
+
66
+ 2. **Install versions specified in `.tool-versions`**:
67
+
68
+ ```bash
69
+ asdf install
70
+ ```
71
+
72
+ 3. **Install project dependencies using uv**:
73
+
74
+ ```bash
75
+ uv sync
76
+ ```
77
+
78
+ This will install all dependencies and make the `kinemetry` command available.
79
+
80
+ ## Usage
81
+
82
+ ### Basic Analysis
83
+
84
+ Analyze a video and output metrics to stdout as JSON:
85
+
86
+ ```bash
87
+ kinemetry dropjump-analyze video.mp4
88
+ ```
89
+
90
+ ### Save Metrics to File
91
+
92
+ ```bash
93
+ kinemetry dropjump-analyze video.mp4 --json-output metrics.json
94
+ ```
95
+
96
+ ### Generate Debug Video
97
+
98
+ Create an annotated video showing pose tracking and contact detection:
99
+
100
+ ```bash
101
+ kinemetry dropjump-analyze video.mp4 --output debug.mp4
102
+ ```
103
+
104
+ ### Calibrated Drop Jump Analysis
105
+
106
+ For most accurate measurements, provide the drop box height in meters:
107
+
108
+ ```bash
109
+ # 40cm drop box
110
+ kinemetry dropjump-analyze drop-jump.mp4 --drop-height 0.40
111
+
112
+ # 60cm drop box with full outputs
113
+ kinemetry dropjump-analyze drop-jump.mp4 \
114
+ --drop-height 0.60 \
115
+ --json-output metrics.json \
116
+ --output debug.mp4
117
+ ```
118
+
119
+ ### Full Example
120
+
121
+ ```bash
122
+ kinemetry dropjump-analyze jump.mp4 \
123
+ --json-output results.json \
124
+ --output debug.mp4 \
125
+ --drop-height 0.40 \
126
+ --smoothing-window 7 \
127
+ --velocity-threshold 0.015
128
+ ```
129
+
130
+ ## Configuration Options
131
+
132
+ > **📖 For detailed explanations of all parameters, see [docs/PARAMETERS.md](docs/PARAMETERS.md)**
133
+ >
134
+ > This section provides a quick reference. The full guide includes:
135
+ > - How each parameter works internally
136
+ > - When and why to adjust them
137
+ > - Scenario-based recommendations
138
+ > - Debugging workflows
139
+ > - Parameter interaction effects
140
+
141
+ ### Smoothing
142
+
143
+ - `--smoothing-window <int>` (default: 5)
144
+ - Window size for Savitzky-Golay smoothing filter
145
+ - Must be odd and >= 3
146
+ - Larger values = smoother trajectories but less responsive
147
+ - **Tip**: Increase for noisy videos, decrease for high-quality stable footage
148
+
149
+ ### Contact Detection
150
+
151
+ - `--velocity-threshold <float>` (default: 0.02)
152
+ - Vertical velocity threshold for detecting stationary feet
153
+ - In normalized coordinates (0-1 range)
154
+ - Lower values = more sensitive (may detect false contacts)
155
+ - Higher values = less sensitive (may miss brief contacts)
156
+ - **Tip**: Start with default, decrease if missing contacts, increase if detecting false contacts
157
+
158
+ - `--min-contact-frames <int>` (default: 3)
159
+ - Minimum consecutive frames to confirm ground contact
160
+ - Filters out momentary tracking glitches
161
+ - **Tip**: Increase for noisy videos with jittery tracking
162
+
163
+ ### Visibility
164
+
165
+ - `--visibility-threshold <float>` (default: 0.5)
166
+ - Minimum MediaPipe visibility score (0-1) to trust a landmark
167
+ - Higher values require more confident tracking
168
+ - **Tip**: Lower if landmarks are frequently obscured but tracking seems reasonable
169
+
170
+ ### Pose Tracking
171
+
172
+ - `--detection-confidence <float>` (default: 0.5)
173
+ - MediaPipe pose detection confidence threshold
174
+ - **Tip**: Increase if getting false pose detections
175
+
176
+ - `--tracking-confidence <float>` (default: 0.5)
177
+ - MediaPipe pose tracking confidence threshold
178
+ - **Tip**: Increase if tracking is jumping between different people/objects
179
+
180
+ ### Calibration
181
+
182
+ - `--drop-height <float>` (optional)
183
+ - Height of drop box/platform in meters (e.g., 0.40 for 40cm)
184
+ - Enables calibrated jump height measurement using known drop height
185
+ - Improves accuracy from ~71% to ~88%
186
+ - Only applicable for drop jumps (box → drop → landing → jump)
187
+ - **Tip**: Measure your box height accurately for best results
188
+
189
+ ## Output Format
190
+
191
+ ### JSON Metrics
192
+
193
+ ```json
194
+ {
195
+ "ground_contact_time_ms": 245.67,
196
+ "flight_time_ms": 456.78,
197
+ "jump_height_m": 0.339,
198
+ "jump_height_kinematic_m": 0.256,
199
+ "jump_height_trajectory_normalized": 0.0845,
200
+ "contact_start_frame": 45,
201
+ "contact_end_frame": 67,
202
+ "flight_start_frame": 68,
203
+ "flight_end_frame": 95,
204
+ "peak_height_frame": 82
205
+ }
206
+ ```
207
+
208
+ **Fields**:
209
+ - `jump_height_m`: Primary jump height measurement (calibrated if --drop-height provided, otherwise corrected kinematic)
210
+ - `jump_height_kinematic_m`: Kinematic estimate from flight time: h = (g × t²) / 8
211
+ - `jump_height_trajectory_normalized`: Position-based measurement in normalized coordinates (0-1 range)
212
+ - `contact_start_frame_precise`, `contact_end_frame_precise`: Sub-frame timing (fractional frames)
213
+ - `flight_start_frame_precise`, `flight_end_frame_precise`: Sub-frame timing (fractional frames)
214
+
215
+ **Note**: Integer frame indices (e.g., `contact_start_frame`) are provided for visualization in debug videos. Precise fractional frames (e.g., `contact_start_frame_precise`) are used for all timing calculations and provide higher accuracy.
216
+
217
+ ### Debug Video
218
+
219
+ The debug video includes:
220
+ - **Green circle**: Average foot position when on ground
221
+ - **Red circle**: Average foot position when in air
222
+ - **Yellow circles**: Individual foot landmarks (ankles, heels)
223
+ - **State indicator**: Current contact state (on_ground/in_air)
224
+ - **Phase labels**: "GROUND CONTACT" and "FLIGHT PHASE" during relevant periods
225
+ - **Peak marker**: "PEAK HEIGHT" at maximum jump height
226
+ - **Frame number**: Current frame index
227
+
228
+ ## Troubleshooting
229
+
230
+ ### Poor Tracking Quality
231
+
232
+ **Symptoms**: Erratic landmark positions, missing detections, incorrect contact states
233
+
234
+ **Solutions**:
235
+ 1. **Check video quality**: Ensure the athlete is clearly visible in profile view
236
+ 2. **Increase smoothing**: Use `--smoothing-window 7` or higher
237
+ 3. **Adjust detection confidence**: Try `--detection-confidence 0.6` or `--tracking-confidence 0.6`
238
+ 4. **Generate debug video**: Use `--output` to visualize what's being tracked
239
+
240
+ ### No Pose Detected
241
+
242
+ **Symptoms**: "No frames processed" error or all null landmarks
243
+
244
+ **Solutions**:
245
+ 1. **Verify video format**: OpenCV must be able to read the video
246
+ 2. **Check framing**: Ensure full body is visible in side view
247
+ 3. **Lower confidence thresholds**: Try `--detection-confidence 0.3 --tracking-confidence 0.3`
248
+ 4. **Test video playback**: Verify video opens correctly with standard video players
249
+
250
+ ### Incorrect Contact Detection
251
+
252
+ **Symptoms**: Wrong ground contact times, flight phases not detected
253
+
254
+ **Solutions**:
255
+ 1. **Generate debug video**: Visualize contact states to diagnose the issue
256
+ 2. **Adjust velocity threshold**:
257
+ - If missing contacts: decrease to `--velocity-threshold 0.01`
258
+ - If false contacts: increase to `--velocity-threshold 0.03`
259
+ 3. **Adjust minimum frames**: `--min-contact-frames 5` for longer required contact
260
+ 4. **Check visibility**: Lower `--visibility-threshold 0.3` if feet are partially obscured
261
+
262
+ ### Jump Height Seems Wrong
263
+
264
+ **Symptoms**: Unrealistic jump height values
265
+
266
+ **Solutions**:
267
+ 1. **Use calibration**: For drop jumps, add `--drop-height` parameter with box height in meters (e.g., `--drop-height 0.40`)
268
+ - This improves accuracy from ~71% to ~88%
269
+ 2. **Verify flight time detection**: Check `flight_start_frame` and `flight_end_frame` in JSON
270
+ 3. **Compare measurements**: JSON output includes both `jump_height_m` (primary) and `jump_height_kinematic_m` (kinematic-only)
271
+ 4. **Check for drop jump detection**: If doing a drop jump, ensure first phase is elevated enough (>5% of frame height)
272
+
273
+ ### Video Codec Issues
274
+
275
+ **Symptoms**: Cannot write debug video or corrupted output
276
+
277
+ **Solutions**:
278
+ 1. **Install additional codecs**: Ensure OpenCV has proper video codec support
279
+ 2. **Try different output format**: Use `.avi` extension instead of `.mp4`
280
+ 3. **Check output path**: Ensure write permissions for output directory
281
+
282
+ ## How It Works
283
+
284
+ 1. **Pose Tracking**: MediaPipe extracts 2D pose landmarks (ankles, heels, foot indices) from each frame
285
+ 2. **Smoothing**: Savitzky-Golay filter reduces tracking jitter while preserving motion dynamics
286
+ 3. **Contact Detection**: Analyzes vertical foot velocity to identify ground contact vs. flight phases
287
+ 4. **Phase Identification**: Finds continuous ground contact and flight periods
288
+ - Automatically detects drop jumps vs regular jumps
289
+ - For drop jumps: identifies box → drop → ground contact → jump sequence
290
+ 5. **Sub-Frame Interpolation**: Estimates exact transition times between frames
291
+ - Uses Savitzky-Golay derivative for smooth velocity calculation
292
+ - Linear interpolation of velocity to find threshold crossings
293
+ - Achieves sub-millisecond timing precision (at 30fps: ±10ms vs ±33ms)
294
+ - Reduces timing error by 60-70% for contact and flight measurements
295
+ - Smoother velocity curves eliminate false threshold crossings
296
+ 6. **Trajectory Curvature Analysis**: Refines transitions using acceleration patterns
297
+ - Computes second derivative (acceleration) from position trajectory
298
+ - Detects landing impact by acceleration spike
299
+ - Identifies takeoff by acceleration change patterns
300
+ - Provides independent validation and refinement of velocity-based detection
301
+ 7. **Metric Calculation**:
302
+ - Ground contact time = contact phase duration (using fractional frames)
303
+ - Flight time = flight phase duration (using fractional frames)
304
+ - Jump height = calibrated position-based measurement (if --drop-height provided)
305
+ - Fallback: corrected kinematic estimate (g × t²) / 8 × 1.35
306
+
307
+ ## Development
308
+
309
+ ### Code Quality Standards
310
+
311
+ This project enforces strict code quality standards:
312
+ - **Type safety**: Full mypy strict mode compliance with complete type annotations
313
+ - **Linting**: Comprehensive ruff checks (pycodestyle, pyflakes, isort, pep8-naming, etc.)
314
+ - **Formatting**: Black code style
315
+ - **Testing**: pytest with 9 unit tests
316
+
317
+ ### Development Commands
318
+
319
+ ```bash
320
+ # Run the tool
321
+ uv run kinemetry dropjump-analyze <video_path>
322
+
323
+ # Run all tests
324
+ uv run pytest
325
+
326
+ # Run tests with verbose output
327
+ uv run pytest -v
328
+
329
+ # Format code
330
+ uv run black src/
331
+
332
+ # Lint code
333
+ uv run ruff check
334
+
335
+ # Auto-fix linting issues
336
+ uv run ruff check --fix
337
+
338
+ # Type check
339
+ uv run mypy src/dropjump
340
+
341
+ # Run all checks
342
+ uv run ruff check && uv run mypy src/dropjump && uv run pytest
343
+ ```
344
+
345
+ ### Contributing
346
+
347
+ Before committing code, ensure all checks pass:
348
+
349
+ 1. Format with Black
350
+ 2. Fix linting issues with ruff
351
+ 3. Ensure type safety with mypy
352
+ 4. Run all tests with pytest
353
+
354
+ See [CLAUDE.md](CLAUDE.md) for detailed development guidelines.
355
+
356
+ ## Limitations
357
+
358
+ - **2D Analysis**: Only analyzes motion in the camera's view plane
359
+ - **Calibration accuracy**: With drop height calibration, achieves ~88% accuracy; without calibration ~71% accuracy
360
+ - **Side View Required**: Must film from the side to accurately track vertical motion
361
+ - **Single Athlete**: Designed for analyzing one athlete at a time
362
+ - **Timing precision**:
363
+ - 30fps videos: ±10ms with sub-frame interpolation (vs ±33ms without)
364
+ - 60fps videos: ±5ms with sub-frame interpolation (vs ±17ms without)
365
+ - Higher frame rates still beneficial for better temporal resolution
366
+ - **Drop jump detection**: Requires first ground phase to be >5% higher than second ground phase
367
+
368
+ ## Future Enhancements
369
+
370
+ - Advanced camera calibration (intrinsic parameters, lens distortion)
371
+ - Multi-angle analysis support
372
+ - Automatic camera orientation detection
373
+ - Batch processing for multiple videos
374
+ - Real-time analysis from webcam
375
+ - Export to CSV/Excel formats
376
+ - Comparison with reference values
377
+ - Force plate integration for validation
378
+
379
+ ## License
380
+
381
+ MIT License - feel free to use for personal experiments and research.
@@ -0,0 +1,12 @@
1
+ dropjump/__init__.py,sha256=3os3CgjXm09srnAvsNIjA_KpHHfsu4ioRY0_oVDaX0w,60
2
+ dropjump/cli.py,sha256=mW_wUaAb1mzQks8oFcZHre50U0pbTacJZg3x-VUdLtY,9563
3
+ dropjump/contact_detection.py,sha256=cHqQ_nR9mbKyHeb90iuGjE8Hq34S01VURBMF8x5oHeM,15015
4
+ dropjump/kinematics.py,sha256=x2SB_4Pj-kJUFCI-KSMjr5PypCmh9FkRR9dorvMq8zI,14983
5
+ dropjump/pose_tracker.py,sha256=JDHK7di6-ObxwVR3TzERUmwCXeCFZWua1kUp1W9W55c,2367
6
+ dropjump/smoothing.py,sha256=FCAk6PnMs7v8dzh98cteLaCvHOuYtfWDVI3X51MxEqs,7836
7
+ dropjump/video_io.py,sha256=Cw_dYRgwybN1gIj4P88tedWAjwmQ4UxkRDztdpRD1hQ,11614
8
+ kinemotion-0.1.0.dist-info/METADATA,sha256=VpBdG6PQcEdjskv-oQssggqltnuDgxvmfd0-1nTj5oA,13737
9
+ kinemotion-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ kinemotion-0.1.0.dist-info/entry_points.txt,sha256=yRp0CWopxkd5fjbnhQ9OjI9gELPmpcCSMCDvWidatD4,47
11
+ kinemotion-0.1.0.dist-info/licenses/LICENSE,sha256=KZajvqsHw0NoOHOi2q0FZ4NBe9HdV6oey-IPYAtHXfg,1088
12
+ kinemotion-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kinemetry = dropjump.cli:cli
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Drop-Jump Analysis Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.