Pose¶
caffe_supported ¶
caffe_supported()
Can this OpenCV build load a Caffe model?
OpenCV 5.0 removed the Caffe importer: cv2.dnn.readNetFromCaffe no
longer exists, and cv2.dnn.readNet raises rather than falling back.
The OpenPose backends here (BODY_25, COCO, MPI) are Caffe models, so they
cannot run on such a build at all. MediaPipe is unaffected.
Source code in musicalgestures/_pose.py
54 55 56 57 58 59 60 61 62 | |
pose ¶
pose(self, model='mediapipe', device='gpu', threshold=0.1, downsampling_factor=2, use_cache=True, save_data=True, data_format='csv', save_video=True, style='both', overlay=True, background='black', convert=None, quiet=True, marker_history=0, save_average_pose=True, save_trajectories=True, transparent_trajectories=None, trajectory_background=None, trajectory_labels=False, target_name_video=None, target_name_data=None, target_name_average=None, target_name_trajectories=None, overwrite=True)
Renders a video with the pose estimation (aka. "keypoint detection" or "skeleton tracking") overlaid on it. Outputs the predictions in a text file containing the normalized x and y coordinates of each keypoint (default format is csv).
Supports two backends:
- MediaPipe (
model='mediapipe'): Uses Google's MediaPipe Pose which detects 33 landmarks. Runs on CPU, or on GPU via MediaPipe's GPU delegate whendevice='gpu'(with automatic CPU fallback if the delegate is unavailable). Requires the optionalmediapipepackage (pip install musicalgestures[pose]). On first use, the model file (~8–28 MB) is downloaded automatically and cached inmusicalgestures/models/. - OpenPose (
model='body_25','coco', or'mpi'): Uses Caffe-based OpenPose models. Model weights (~200 MB) are downloaded on first use. GPU here requires an OpenCV built with CUDA; if unavailable whiledevice='gpu',pose()automatically switches to the MediaPipe backend (when installed) for GPU acceleration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Pose model to use. |
'mediapipe'
|
device
|
str
|
Compute backend ('cpu' or 'gpu'). For OpenPose models this selects the OpenCV DNN backend (GPU needs a CUDA-enabled OpenCV). For MediaPipe it selects the inference delegate (GPU delegate with CPU fallback). Defaults to 'gpu'. |
'gpu'
|
threshold
|
float
|
The normalized confidence threshold that decides whether we keep or discard a predicted point. Discarded points get substituted with (0, 0) in the output data. Defaults to 0.1. |
0.1
|
downsampling_factor
|
int
|
Decides how much we downsample the video before we
pass it to the neural network. Ignored when |
2
|
use_cache
|
bool
|
If True (default), reuse keypoints from a previous pose() run on
this object (same model/threshold) to re-render a different |
True
|
save_data
|
bool
|
Whether we save the predicted pose data to a file. Defaults to True. |
True
|
data_format
|
str
|
Specifies format of pose-data. Accepted values are 'csv', 'tsv',
'txt' and 'c3d' (motion-capture format; requires the optional |
'csv'
|
save_video
|
bool
|
Whether we save the video with the estimated pose overlaid on it. Defaults to True. |
True
|
style
|
str
|
How to draw the pose. |
'both'
|
overlay
|
bool
|
If True, draw the pose on top of the original video frames. If False, draw it on a plain background instead (a "markers only" video with no video underneath). Defaults to True. |
True
|
background
|
str
|
Background colour used when |
'black'
|
marker_history
|
int
|
If greater than 0, draw a motion trail for every marker by joining its
positions over the last |
0
|
convert
|
bool
|
Whether non-AVI input is first converted to an all-intra MJPEG |
None
|
quiet
|
bool
|
MediaPipe only. If True (default), suppress MediaPipe's native C++/GL console logs (EGL init, absl INFO/WARNING, GPU-delegate messages) during inference. Set to False to see them for debugging. |
True
|
target_name_video
|
str
|
Target output name for the video. Defaults to None (which assumes that the input filename with the suffix "_pose" should be used). |
None
|
save_average_pose
|
bool
|
Whether to also render an image of the average pose over the whole video, with each marker coloured/labelled by its average quantity of motion (px/frame) and labelled with its dominant movement frequency (Hz). A CSV of the per-marker statistics is saved alongside it. Defaults to True. |
True
|
save_trajectories
|
bool
|
Whether to also render an image of every marker's spatial trajectory across the whole video. Defaults to True. |
True
|
trajectory_labels
|
bool
|
Whether to annotate the trajectories image with each marker's name. Defaults to False (cleaner image). |
False
|
trajectory_background
|
str
|
Background of the trajectories PNG: |
None
|
target_name_data
|
str
|
Target output name for the data. Defaults to None (which assumes that the input filename with the suffix "_pose" should be used). |
None
|
target_name_average
|
str
|
Target output name for the average-pose image. Defaults to None (input filename with the suffix "_pose_average.png"). |
None
|
target_name_trajectories
|
str
|
Target output name for the trajectories image. Defaults to None (input filename with the suffix "_pose_trajectories.png"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgVideo |
'musicalgestures.MgVideo'
|
An MgVideo pointing to the output video. The average-pose and trajectories images
(when rendered) are attached as |
Source code in musicalgestures/_pose.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
mg_pose_waterfall ¶
mg_pose_waterfall(self, style='trajectories', n_samples=40, markers=None, color_by=None, cmap='hsv', dpi=200, elev=20, azim=-60, lw=1.0, axes=True, crop=False, target_name=None, overwrite=True, **pose_kwargs)
Render a 3D spatio-temporal waterfall of the pose, cascading along the time (depth) axis —
a pose-based counterpart to silhouette_waterfall(). Uses cached pose keypoints from a
previous pose() call when available; otherwise it runs pose estimation first (extra
keyword arguments such as model/device/downsampling_factor are forwarded to
pose()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style
|
str
|
What to draw. |
'trajectories'
|
n_samples
|
int
|
Number of time slices for the marker/skeleton styles.
Defaults to 40 (ignored for |
40
|
markers
|
list
|
Subset of marker names or indices to draw. Defaults to all. |
None
|
color_by
|
str
|
|
None
|
cmap
|
str
|
Matplotlib colormap. Defaults to 'hsv'. |
'hsv'
|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
elev
|
float
|
3D elevation angle. Defaults to 20. |
20
|
azim
|
float
|
3D azimuth angle. Defaults to -60. |
-60
|
lw
|
float
|
Line width. Defaults to 1.0. |
1.0
|
axes
|
bool
|
Draw the axes and tick labels. Set to False for a clean render with all axes and text removed. Defaults to True. |
True
|
crop
|
bool
|
Tighten the spatial limits to the marker extent and trim the surrounding whitespace, so the figure shows mostly the data. Defaults to False. |
False
|
target_name
|
str
|
Output name. Defaults to None ("_pose_waterfall.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
**pose_kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the 3D waterfall figure, or None if there are too few frames. |
Source code in musicalgestures/_pose.py
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 | |
mg_pose_segments ¶
mg_pose_segments(self, segments=None, n_bins=36, cmap='viridis', dpi=200, ncols=6, target_name=None, overwrite=True, **pose_kwargs)
Circular (polar) motion plots and statistics for each body segment.
A segment is the bone between two connected joints (e.g. shoulder–elbow). For every segment
this computes its per-frame orientation angle and draws a polar rose histogram of the angle
distribution with the mean-direction resultant vector, annotated with circular statistics
(mean angle, resultant length R, and range of motion). A CSV of the per-segment statistics —
mean angle, R, circular std, range of motion, and mean angular speed — is saved alongside the
image. Uses cached pose keypoints from a previous pose() call when available; otherwise it
runs pose estimation first (model/device/… are forwarded to pose()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
list
|
Subset of connections as |
None
|
n_bins
|
int
|
Number of angular bins per rose. Defaults to 36 (10° bins). |
36
|
cmap
|
str
|
Matplotlib colormap for the bars. Defaults to 'viridis'. |
'viridis'
|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
ncols
|
int
|
Columns in the subplot grid. Defaults to 6. |
6
|
target_name
|
str
|
Output name. Defaults to None ("_pose_segments.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
**pose_kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the grid of circular plots (per-segment stats in |
Source code in musicalgestures/_pose.py
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | |
mg_pose_center ¶
mg_pose_center(self, save_data=True, dpi=200, target_name=None, overwrite=True, **pose_kwargs)
Centre the pose data on its global centroid — a 2D port of the MoCap Toolbox mccenter.
A single offset per coordinate (the mean of the per-marker temporal means, missing detections
ignored) is subtracted from every marker so the overall spatiotemporal centroid sits at the
origin (0, 0). This removes the performer's absolute position in the frame, leaving relative
posture/movement — useful before comparing or further analysing trajectories. Plots the centred
marker trajectories and (by default) saves a CSV of the centred coordinates. Uses cached pose
keypoints when available, otherwise runs pose() first (**pose_kwargs are forwarded).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_data
|
bool
|
Save a CSV of the centred coordinates. Defaults to True. |
True
|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
target_name
|
str
|
Output name. Defaults to None ("_pose_centered.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
**pose_kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the centred-trajectories figure; |
'MgFigure'
|
coordinates and |
Source code in musicalgestures/_pose.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 | |
mg_pose_distance ¶
mg_pose_distance(self, dpi=200, target_name=None, overwrite=True, **pose_kwargs)
Per-marker distance travelled and the average across markers — a 2D port of the MoCap Toolbox
mccumdist.
Sums each marker's frame-to-frame Euclidean displacement (in pixels) and accumulates it over
time. The figure shows the per-marker cumulative-distance curves and a ranked bar chart of the
total distance per marker with the across-marker average marked; a CSV of the totals (plus the
average) is saved. Uses cached pose keypoints when available, otherwise runs pose() first
(**pose_kwargs are forwarded).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
target_name
|
str
|
Output name. Defaults to None ("_pose_distance.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
**pose_kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
|
'MgFigure'
|
|
Source code in musicalgestures/_pose.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
download_model ¶
download_model(modeltype)
Download the OpenPose Caffe weights (.caffemodel) for the given model type into the package's
pose/ folder.
Uses Python's urllib directly (cross-platform, no external wget / shell scripts /
bundled binary). The .prototxt configs ship with the package; only the large weights file
is fetched.
Returns the downloaded file path on success, or None if download attempts fail.
Source code in musicalgestures/_pose.py
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 | |