Video¶
Bases: MgAudio
This is the class for working with video files in the Musical Gestures Toolbox. It inherites from the class MgAudio for working with audio files as well. There is a set of preprocessing tools you can use when you load a video, such as: - trimming: to extract a section of the video, - skipping: to shrink the video by skipping N frames after keeping one, - rotating: to rotate the video by N degrees, - applying brightness and contrast - cropping: to crop the video either automatically (by assessing the area of motion) or manually with a pop-up user interface, - converting to grayscale
These preprocesses will apply upon creating the MgVideo. Further processes are available as class methods.
Initializes Musical Gestures data structure from a video file, and applies preprocesses if desired.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Union[str, List[str]]
|
Path to the video file. If input is a list, will merge all videos into one. |
required |
array
|
ndarray
|
Generates an MgVideo object from a video array. Defaults to None. |
None
|
fps
|
float
|
The frequency at which consecutive images from the video array are captured or displayed. Defaults to None. |
None
|
path
|
str
|
Path to save the output video file generated from a video array. Defaults to None. |
None
|
filtertype
|
str
|
The |
'Regular'
|
threshold
|
float
|
The |
0.05
|
starttime
|
int or float
|
Trims the video from this start time (s). Defaults to 0. |
0
|
endtime
|
int or float
|
Trims the video until this end time (s). Defaults to 0 (which means the full length). |
0
|
blur
|
str
|
The |
'None'
|
skip
|
int
|
Time-shrinks the video by skipping (discarding) every n frames determined by |
0
|
frames
|
int
|
Specify a fixed target number of frames to extract from the video. Defaults to 0. |
0
|
rotate
|
int
|
Rotates the video by a |
0
|
color
|
bool
|
If False, converts the video to grayscale and sets every method in grayscale mode. Defaults to True. |
True
|
contrast
|
int
|
Applies +/- 100 contrast to video. Defaults to 0. |
0
|
brightness
|
int
|
Applies +/- 100 brightness to video. Defaults to 0. |
0
|
crop
|
str
|
If 'manual', opens a window displaying the first frame of the input video file, where the user can draw a rectangle to which cropping is applied. If 'auto' the cropping function attempts to determine the area of significant motion and applies the cropping to that area. Defaults to 'None'. |
'None'
|
keep_all
|
bool
|
If True, preserves an output video file after each used preprocessing stage. Defaults to False. |
False
|
returned_by_process
|
bool
|
This parameter is only for internal use, do not use it. Defaults to False. |
False
|
sr
|
int
|
Sampling rate of the audio file. Defaults to 22050. |
22050
|
n_fft
|
int
|
Length of the FFT window. Defaults to 2048. |
2048
|
hop_length
|
int
|
Number of samples between successive frames. Defaults to 512. |
512
|
Source code in musicalgestures/_video.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
motion_plot
class-attribute
instance-attribute
¶
motion_plot = deprecated_alias('motion_plot', 'motion_plot_image')
motiongram_x
class-attribute
instance-attribute
¶
motiongram_x = deprecated_alias('motiongram_x', 'motiongram_x_image')
motiongram_y
class-attribute
instance-attribute
¶
motiongram_y = deprecated_alias('motiongram_y', 'motiongram_y_image')
motiongram_vertical_image
class-attribute
instance-attribute
¶
motiongram_vertical_image = deprecated_alias('motiongram_vertical_image', 'motiongram_x_image')
motiongram_horizontal_image
class-attribute
instance-attribute
¶
motiongram_horizontal_image = deprecated_alias('motiongram_horizontal_image', 'motiongram_y_image')
movement_beat_statistics
class-attribute
instance-attribute
¶
movement_beat_statistics = deprecated_alias('movement_beat_statistics', 'movement_beat_statistics_figure')
body_audio_coupling_figure
class-attribute
instance-attribute
¶
body_audio_coupling_figure = deprecated_alias('body_audio_coupling_figure', 'motion_audio_coupling_figure')
pose_average
class-attribute
instance-attribute
¶
pose_average = deprecated_alias('pose_average', 'pose_average_image')
pose_trajectories
class-attribute
instance-attribute
¶
pose_trajectories = deprecated_alias('pose_trajectories', 'pose_trajectories_image')
ssm_combined
class-attribute
instance-attribute
¶
ssm_combined = deprecated_alias('ssm_combined', 'ssm_combined_image')
videogram_x
class-attribute
instance-attribute
¶
videogram_x = deprecated_alias('videogram_x', 'videogram_x_image')
videogram_y
class-attribute
instance-attribute
¶
videogram_y = deprecated_alias('videogram_y', 'videogram_y_image')
videogram_vertical_image
class-attribute
instance-attribute
¶
videogram_vertical_image = deprecated_alias('videogram_vertical_image', 'videogram_x_image')
videogram_horizontal_image
class-attribute
instance-attribute
¶
videogram_horizontal_image = deprecated_alias('videogram_horizontal_image', 'videogram_y_image')
duration
property
¶
duration
Video duration in seconds (length / fps).
Note self.length is the frame count for an MgVideo (it is the duration in
seconds for an MgAudio); use this property when you want seconds.
motion_mp ¶
motion_mp(*args, **kwargs)
Retired. Use :meth:motion instead.
This rendered a motion video across several processes, coordinating them
with a socket server and an argparse child process. It raised on its first
call --- two fields were read as one between the parent and the workers,
and behind that failure it called save_txt and save_analysis with
arguments in the wrong positions --- so it produced nothing for anyone who
tried it. See issue #370.
motion() does the same work in one process and is tested.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in musicalgestures/_video.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
warp_audiovisual_beats ¶
warp_audiovisual_beats(*args, **kwargs)
Retired name: use :meth:warp_audiomotion_beats.
Source code in musicalgestures/_video.py
278 279 280 281 282 | |
body_audio_coupling ¶
body_audio_coupling(*args, **kwargs)
Retired name: use :meth:motion_audio_coupling.
Source code in musicalgestures/_video.py
284 285 286 287 288 | |
motion ¶
motion(filtertype='Regular', threshold=0.05, blur='None', kernel_size=5, use_median=False, unit='seconds', atadenoise=False, motion_analysis='all', inverted_motionvideo=False, inverted_motiongram=False, equalize_motiongram=False, audio_descriptors=False, save_plot=True, title=None, save_data=True, data_format='csv', save_motiongrams=True, save_video=True, target_name_video=None, target_name_plot=None, target_name_data=None, target_name_mgx=None, target_name_mgy=None, overwrite=True, normalize=None)
Finds the difference in pixel value from one frame to the next in an input video, and saves the frames into a new video. Describes the motion in the recording. Outputs: a motion video, a plot describing the centroid of motion and the quantity of motion, the y- and x-motiongrams, and a text file containing the quantity of motion and the centroid of motion for each frame with timecodes in milliseconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtertype
|
str
|
'Regular' turns all values below |
'Regular'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
blur
|
str
|
'Average' to apply a 10px * 10px blurring filter, 'None' otherwise. Defaults to 'None'. |
'None'
|
kernel_size
|
int
|
Size of structuring element. Defaults to 5. |
5
|
use_median
|
bool
|
If True the algorithm applies a median filter on the thresholded frame-difference stream. Defaults to False. |
False
|
unit
|
str
|
Unit in QoM plot. Accepted values are 'seconds' or 'samples'. Defaults to 'seconds'. |
'seconds'
|
atadenoise
|
bool
|
If True, applies an adaptive temporal averaging denoiser every 129 frames. Defaults to False. |
False
|
normalize
|
bool | None
|
Chooses between data for looking at and data for
measuring with. True (and None, the long-standing default) writes a |
None
|
motion_analysis
|
str
|
Specify which motion analysis to process or all. 'AoM' renders the Area of Motion. 'CoM' renders the Centroid of Motion. 'QoM' renders the Quantity of Motion. 'all' renders all the motion analysis available. Defaults to 'all'. |
'all'
|
inverted_motionvideo
|
bool
|
If True, inverts colors of the motion video. Defaults to False. |
False
|
inverted_motiongram
|
bool
|
If True, inverts colors of the motiongrams. Defaults to False. |
False
|
equalize_motiongram
|
bool
|
If True, converts the motiongrams to hsv-color space and flattens the value channel (v). Defaults to True. |
False
|
save_plot
|
bool
|
If True, outputs motion-plot. Defaults to True. |
True
|
title
|
str
|
Optionally add title to the plot. Defaults to None, which uses the file name as a title. |
None
|
save_data
|
bool
|
If True, outputs motion-data. Defaults to True. |
True
|
data_format
|
str / list
|
Specifies format of motion-data. Accepted values are 'csv', 'tsv' and 'txt'. For multiple output formats, use list, eg. ['csv', 'txt']. Defaults to 'csv'. |
'csv'
|
save_motiongrams
|
bool
|
If True, outputs motiongrams. Defaults to True. |
True
|
save_video
|
bool
|
If True, outputs the motion video. Defaults to True. |
True
|
target_name_video
|
str
|
Target output name for the video. Defaults to None (which assumes that the input filename with the suffix "_motion" should be used). |
None
|
target_name_plot
|
str
|
Target output name for the plot. Defaults to None (which assumes that the input filename with the suffix "_motion_com_aom_qom" should be used). |
None
|
target_name_data
|
str
|
Target output name for the data. Defaults to None (which assumes that the input filename with the suffix "_motion" should be used). |
None
|
target_name_mgx
|
str
|
Target output name for the x-motiongram (the tall picture). Defaults to None (which assumes that the input filename with the suffix "_mgv" should be used). |
None
|
target_name_mgy
|
str
|
Target output name for the y-motiongram (the wide picture). Defaults to None (which assumes that the input filename with the suffix "_mgh" should be used). |
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'
|
A new MgVideo pointing to the output video file. If |
Source code in musicalgestures/_motionvideo.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
motiongrams ¶
motiongrams(filtertype='Regular', threshold=0.05, blur='None', use_median=False, atadenoise=False, kernel_size=5, inverted_motiongram=False, equalize_motiongram=True, target_name_mgx=None, target_name_mgy=None, overwrite=True, normalize=None)
Shortcut for mg_motion to only render motiongrams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtertype
|
str
|
'Regular' turns all values below |
'Regular'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
blur
|
str
|
'Average' to apply a 10px * 10px blurring filter, 'None' otherwise. Defaults to 'None'. |
'None'
|
use_median
|
bool
|
If True the algorithm applies a median filter on the thresholded frame-difference stream. Defaults to False. |
False
|
atadenoise
|
bool
|
If True, applies an adaptive temporal averaging denoiser every 129 frames. Defaults to False. |
False
|
kernel_size
|
int
|
Size of the median filter (if |
5
|
inverted_motiongram
|
bool
|
If True, inverts colors of the motiongrams. Defaults to False. |
False
|
equalize_motiongram
|
bool
|
If True, converts the motiongrams to hsv-color space and flattens the value channel (v). Defaults to True. |
True
|
target_name_mgx
|
str
|
Target output name for the x-motiongram (the tall picture). Defaults to None (which assumes that the input filename with the suffix "_mgv" should be used). |
None
|
target_name_mgy
|
str
|
Target output name for the y-motiongram (the wide picture). Defaults to None (which assumes that the input filename with the suffix "_mgh" should be used). |
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 |
|---|---|---|
MgList |
'MgList'
|
An MgList pointing to the output motiongram images (as MgImages). |
Source code in musicalgestures/_motionvideo.py
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 | |
motiondata ¶
motiondata(filtertype='Regular', threshold=0.05, blur='None', kernel_size=5, atadenoise=False, use_median=False, motion_analysis='all', data_format='csv', target_name=None, overwrite=True)
Shortcut for mg_motion to only render motion data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtertype
|
str
|
'Regular' turns all values below |
'Regular'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
blur
|
str
|
'Average' to apply a 10px * 10px blurring filter, 'None' otherwise. Defaults to 'None'. |
'None'
|
kernel_size
|
int
|
Size of structuring element. Defaults to 5. |
5
|
atadenoise
|
bool
|
If True, applies an adaptive temporal averaging denoiser every 129 frames. Defaults to False. |
False
|
use_median
|
bool
|
If True the algorithm applies a median filter on the thresholded frame-difference stream. Defaults to False. |
False
|
motion_analysis
|
str
|
Specify which motion analysis to process or all. 'AoM' renders the Area of Motion. 'CoM' renders the Centroid of Motion. 'QoM' renders the Quantity of Motion. 'all' renders all the motion analysis available. Defaults to 'all'. |
'all'
|
data_format
|
str / list
|
Specifies format of motion-data. Accepted values are 'csv', 'tsv' and 'txt'. For multiple output formats, use list, eg. ['csv', 'txt']. Defaults to 'csv'. |
'csv'
|
target_name
|
str
|
Target output name for the data. Defaults to None (which assumes that the input filename with the suffix "_motion" should be used). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
'str | list'
|
str/list: The path(s) to the rendered data file(s). |
Source code in musicalgestures/_motionvideo.py
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 | |
motionplots ¶
motionplots(filtertype='Regular', threshold=0.05, blur='None', kernel_size=5, use_median=False, atadenoise=False, motion_analysis='all', audio_descriptors=False, unit='seconds', title=None, target_name=None, overwrite=True)
Shortcut for mg_motion to only render motion plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtertype
|
str
|
'Regular' turns all values below |
'Regular'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
blur
|
str
|
'Average' to apply a 10px * 10px blurring filter, 'None' otherwise. Defaults to 'None'. |
'None'
|
kernel_size
|
int
|
Size of structuring element. Defaults to 5. |
5
|
use_median
|
bool
|
If True the algorithm applies a median filter on the thresholded frame-difference stream. Defaults to False. |
False
|
atadenoise
|
bool
|
If True, applies an adaptive temporal averaging denoiser every 129 frames. Defaults to False. |
False
|
motion_analysis
|
str
|
Specify which motion analysis to process or all. 'AoM' renders the Area of Motion. 'CoM' renders the Centroid of Motion. 'QoM' renders the Quantity of Motion. 'all' renders all the motion analysis available. Defaults to 'all'. |
'all'
|
audio_descriptors
|
bool
|
Whether to plot motion plots together with audio descriptors in order to see possible correlations in the data. Defaults to False. |
False
|
unit
|
str
|
Unit in QoM plot. Accepted values are 'seconds' or 'samples'. Defaults to 'seconds'. |
'seconds'
|
title
|
str
|
Optionally add title to the plot. Defaults to None, which uses the file name as a title. |
None
|
target_name
|
str
|
Target output name for the plot. Defaults to None (which assumes that the input filename with the suffix "_motion_com_aom_qom" should be used). |
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 |
|---|---|---|
MgImage |
'MgImage'
|
An MgImage pointing to the exported image (png) of the motion plots. |
Source code in musicalgestures/_motionvideo.py
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 | |
motionvideo ¶
motionvideo(filtertype='Regular', threshold=0.05, blur='None', use_median=False, kernel_size=5, inverted_motionvideo=False, target_name=None, overwrite=True)
Shortcut to only render the motion video. Uses musicalgestures._utils.motionvideo_ffmpeg. Note that this does not apply median filter by default. If you need it use use_median=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtertype
|
str
|
'Regular' turns all values below |
'Regular'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
blur
|
str
|
'Average' to apply a 10px * 10px blurring filter, 'None' otherwise. Defaults to 'None'. |
'None'
|
use_median
|
bool
|
If True the algorithm applies a median filter on the thresholded frame-difference stream. Defaults to False. |
False
|
kernel_size
|
int
|
Size of the median filter (if |
5
|
inverted_motionvideo
|
bool
|
If True, inverts colors of the motion video. Defaults to False. |
False
|
target_name
|
str
|
Target output name for the video. Defaults to None (which assumes that the input filename with the suffix "_motion" should be used). |
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'
|
A new MgVideo pointing to the output '_motion' video file. |
Source code in musicalgestures/_motionvideo.py
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 | |
motionscore ¶
motionscore()
Computes the average VMAF motion score of the video using FFmpeg.
Returns:
| Name | Type | Description |
|---|---|---|
float |
'float | None'
|
The average VMAF motion score, or None if unavailable. |
Source code in musicalgestures/_motionvideo.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | |
subtract ¶
subtract(color=True, filtertype=None, threshold=0.05, blur=False, curves=0.15, use_median=False, kernel_size=5, bg_img=None, bg_color='#000000', target_name=None, overwrite=True)
Renders background subtraction using ffmpeg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
bool
|
If False the input is converted to grayscale at the start of the process. This can significantly reduce render time. Defaults to True. |
True
|
filtertype
|
str
|
'Regular' turns all values below |
None
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
blur
|
bool
|
Whether to apply a smartblur ffmpeg filter or not. Defaults to False. |
False
|
curves
|
int
|
Apply curves and equalisation threshold filter to subtract the background. Ranges from 0 to 1. Defaults to 0.15. |
0.15
|
use_median
|
bool
|
If True the algorithm applies a median filter on the thresholded frame-difference stream. Defaults to False. |
False
|
kernel_size
|
int
|
Size of the median filter (if |
5
|
bg_img
|
str
|
Path to a background image (.png) that needs to be subtracted from the video. If set to None, it uses an average image of all frames in the video. Defaults to None. |
None
|
bg_color
|
str
|
Set the background color in the video file in hex value. Defaults to '#000000' (black). |
'#000000'
|
target_name
|
str
|
Target output name for the subtracted video. Defaults to None. |
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 |
MgVideo
|
A MgVideo pointing to the subtracted video, also stored as |
Source code in musicalgestures/_subtract.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
ssm ¶
ssm(features='motiongrams', filtertype='Regular', threshold=0.05, blur='None', norm=np.inf, norm_threshold=0.001, cmap='gray_r', use_median=False, kernel_size=5, invert_yaxis=True, combine=False, title=None, target_name=None, overwrite=True)
Compute Self-Similarity Matrix (SSM) by converting the input signal into a suitable feature sequence and comparing each element of the feature sequence with all other elements of the sequence. SSMs can be computed over different input features such as 'motiongrams', 'spectrogram', 'chromagram' and 'tempogram'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
str
|
Defines the type of features on which to compute SSM. Possible to compute SSM on 'motiongrams', 'videograms', 'spectrogram', 'chromagram' and 'tempogram'. Defaults to 'motiongrams'. |
'motiongrams'
|
filtertype
|
str
|
'Regular' turns all values below |
'Regular'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
blur
|
str
|
'Average' to apply a 10px * 10px blurring filter, 'None' otherwise. Defaults to 'None'. |
'None'
|
norm
|
int
|
Normalize the columns of the feature sequence. Possible to compute Manhattan norm (1), Euclidean norm (2), Minimum norm (-np.inf), Maximum norm (np.inf), etc. Defaults to np.inf. |
inf
|
norm_threshold
|
float
|
Only the columns with norm at least |
0.001
|
combine
|
bool
|
For 'motiongrams', compute a single SSM from the concatenated horizontal + vertical motiongram features (both axes of motion in one display) and return a single MgImage instead of an MgList of two. Defaults to False. |
False
|
cmap
|
str
|
A Colormap instance or registered colormap name. The colormap maps the C values to colors. Defaults to 'gray_r'. |
'gray_r'
|
use_median
|
bool
|
If True the algorithm applies a median filter on the thresholded frame-difference stream. Defaults to False. |
False
|
kernel_size
|
int
|
Size of the median filter (if |
5
|
invert_yaxis
|
bool
|
Whether to invert the y axis of the SSM. Defaults to True. |
True
|
title
|
str
|
Optionally add title to the figure. Possible to set the filename as the title using the string 'filename'. Defaults to None. |
None
|
target_name
|
[type]
|
Target output name for the SSM. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
'MgList | MgImage | None'
|
MgList | MgImage | None: With |
Source code in musicalgestures/_ssm.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
videograms ¶
videograms(target_name_x=None, target_name_y=None, overwrite=True, mode='average', line_x=None, line_y=None)
Renders horizontal and vertical videograms of the source video using ffmpeg.
By default, videoframes are averaged by axes. Alternatively, mode='slit'
samples a single column and row per frame (photo-finish style) and stacks
those over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_name_x
|
str
|
Target output name for the vertical videogram (the x-axis collapse). Defaults to None (which assumes that the input filename with the suffix "_vgv" should be used). |
None
|
target_name_y
|
str
|
Target output name for the horizontal videogram (the y-axis collapse). Defaults to None (which assumes that the input filename with the suffix "_vgh" should be used). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
mode
|
str
|
Either |
'average'
|
line_x
|
int
|
Source x-position (column index) used in slit mode for the vertical videogram. Defaults to the center column. |
None
|
line_y
|
int
|
Source y-position (row index) used in slit mode for the horizontal videogram. Defaults to the center row. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
MgList |
'MgList'
|
An MgList with the MgImage objects referring to the vertical and horizontal videograms respectively. |
Source code in musicalgestures/_videograms.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
directograms ¶
directograms(title=None, filtertype='Adaptative', threshold=0.05, kernel_size=5, convert=True, target_name=None, overwrite=True)
Compute a directogram to factor the magnitude of motion into different angles. Each columun of the directogram is computed as the weighted histogram (HISTOGRAM_BINS) of angles for the optical flow of an input frame.
Source: Abe Davis -- Visual Rhythm and Beat (section 4.1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Optionally add title to the figure. Defaults to None, which uses 'Directogram' as a title. Defaults to None. |
None
|
filtertype
|
str
|
'Regular' turns all values below |
'Adaptative'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
kernel_size
|
int
|
Size of structuring element. Defaults to 5. |
5
|
convert
|
bool
|
If True (default), non-AVI input is first converted to an all-intra MJPEG |
True
|
target_name
|
str
|
Target output name for the directogram. Defaults to None (which assumes that the input filename with the suffix "_dg" should be used). |
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 |
|---|---|---|
MgFigure |
'MgFigure'
|
A MgFigure object referring to the internal figure and its data. |
Source code in musicalgestures/_directograms.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
warp_audiomotion_beats ¶
warp_audiomotion_beats(audio_file, speed=(0.5, 2), data=None, filtertype='Adaptative', threshold=0.05, kernel_size=5, target_name=None, overwrite=True)
Warp the motion beats of the video to align with the audio beats. Davis calls these visual beats, patterns of motion that can be shifted in time to control visual rhythm; in this toolbox's terms they are motion beats, since they are computed from the directogram rather than perceived. Visual beats are warped after computing a directogram which factors the magnitude of motion in the video into different angles.
Source: Abe Davis -- Visual Rhythm and Beat (section 5)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio_file
|
str
|
Path to the audio file. |
required |
speed
|
tuple
|
Speed's change between the audio and motion beats which can be adjusted to slow down or speed up the visual rhythms. Defaults to (0.5,2). |
(0.5, 2)
|
data
|
array_like
|
Computed directogram data can be added separately to avoid the directogram processing time (which can be quite long). Defaults to None. |
None
|
filtertype
|
str
|
'Regular' turns all values below |
'Adaptative'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
kernel_size
|
int
|
Size of structuring element. Defaults to 5. |
5
|
target_name
|
str
|
Target output name for the directogram. Defaults to None (which assumes that the input filename with the suffix "_dg" should be used). |
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'
|
A MgVideo as warp_audiovisual_beats for parent MgVideo |
Source code in musicalgestures/_warp.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
blur_faces ¶
blur_faces(mask='blur', mask_image=None, mask_scale=1.0, ellipse=True, draw_heatmap=False, neighbours=32, resolution=250, draw_scores=False, save_data=True, data_format='csv', color=(0, 0, 0), use_gpu=False, target_name=None, overwrite=True)
Automatic anonymization of faces in videos. This function works by first detecting all human faces in each video frame and then applying an anonymization filter (blurring, black rectangles or images) on each detected face region.
Credits: centerface.onnx (original) and centerface.py are based on https://github.com/Star-Clouds/centerface (revision 8c39a49), released under MIT license.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
str
|
Mask filter mode for face regions. 'blur' applies a strong gaussian blurring, 'rectangle' draws a solid black box, 'image' replaces the face with a custom image and 'none' does leaves the input unchanged. Defaults to 'blur'. |
'blur'
|
mask_image
|
str
|
Anonymization image path which can be used for masking face regions. This can be activated by specifying 'image' in the mask parameter. Defaults to None. |
None
|
mask_scale
|
float
|
Scale factor for face masks, to make sure that the masks cover the complete face. Defaults to 1.0. |
1.0
|
ellipse
|
bool
|
Mask faces with blurred ellipses. Defaults to True. |
True
|
draw_heatmap
|
bool
|
Draw heatmap of the detected faces using the centroid of the face mask. Defaults to False. |
False
|
neighbours
|
int
|
Number of neighbours for smoothing the heatmap image. Defaults to 32. |
32
|
resolution
|
int
|
Number of pixel resolution for the heatmap visualization. Defaults to 250. |
250
|
draw_scores
|
bool
|
Draw detection faceness scores onto outputs (a score between 0 and 1 that roughly corresponds to the detector's confidence that something is a face). Defaults to False. |
False
|
save_data
|
bool
|
Whether to save the scaled coordinates of the face mask (time (ms), x1, y1, x2, y2) for each frame to a file. Defaults to True. |
True
|
data_format
|
str
|
Specifies format of blur_faces-data. Accepted values are 'csv', 'tsv' and 'txt'. For multiple output formats, use list, e.g. ['csv', 'txt']. Defaults to 'csv'. |
'csv'
|
color
|
tuple
|
Customized color of the rectangle boxes. Defaults to black (0, 0, 0). |
(0, 0, 0)
|
use_gpu
|
bool
|
Whether to attempt GPU (CUDA) acceleration for face detection. Falls back to CPU automatically if CUDA is unavailable. Defaults to False. |
False
|
target_name
|
str
|
Target output name. Defaults to None (which assumes that the input filename with the suffix "_blurred" should be used). |
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 |
A MgVideo as blur_faces for parent MgVideo |
Source code in musicalgestures/_blurfaces.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
impacts ¶
impacts(title=None, detection=True, local_mean=0.1, local_maxima=0.15, filtertype='Adaptative', threshold=0.05, kernel_size=5, convert=True, target_name=None, overwrite=True)
Compute a visual analogue of an onset envelope, aslo known as an impact envelope (Abe Davis). This is computed by summing over positive entries in the columns of the directogram. This gives an impact envelope with precisely the same form as an onset envelope. To account for large outlying spikes that sometimes happen at shot boundaries (i.e., cuts), the 99th percentile of the impact envelope values are clipped to the 98th percentile. Then, the impact envelopes are normalized by their maximum to make calculations more consistent across video resolutions. Fianlly, the local mean of the impact envelopes are calculated using a 0.1-second window, and local maxima using a 0.15-second window. Impacts are defined as local maxima that are above their local mean by at least 10% of the envelope’s global maximum.
Source: Abe Davis -- Visual Rhythm and Beat (section 4.2 and 4.3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Optionally add title to the figure. Defaults to None, which uses 'Directogram' as a title. Defaults to None. |
None
|
detection
|
bool
|
Whether to allow the detection of impacts based on local mean and local maxima or not. |
True
|
local_mean
|
float
|
Size of the local mean window in seconds which reduces the amount of intensity variation between one impact and the next. |
0.1
|
local_maxima
|
float
|
Size of the local maxima window in seconds for the impact envelopes |
0.15
|
filtertype
|
str
|
'Regular' turns all values below |
'Adaptative'
|
threshold
|
float
|
Eliminates pixel values less than given threshold. Ranges from 0 to 1. Defaults to 0.05. |
0.05
|
kernel_size
|
int
|
Size of structuring element. Defaults to 5. |
5
|
convert
|
bool
|
If True (default), non-AVI input is first converted to an all-intra MJPEG |
True
|
target_name
|
str
|
Target output name for the impacts figure. Defaults to None (which assumes that the input filename with the suffix "_impacts" should be used). |
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 |
|---|---|---|
MgFigure |
'MgFigure'
|
An MgFigure object referring to the internal figure and its data. |
Source code in musicalgestures/_impacts.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
grid ¶
grid(height=300, rows=3, columns=3, padding=0, margin=0, target_name=None, overwrite=True, return_array=False)
Generates frame strip video preview using ffmpeg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Frame height, width is adjusted automatically to keep the correct aspect ratio. Defaults to 300. |
300
|
rows
|
int
|
Number of rows of the grid. Defaults to 3. |
3
|
columns
|
int
|
Number of columns of the grid. Defaults to 3. |
3
|
padding
|
int
|
Padding size between the frames. Defaults to 0. |
0
|
margin
|
int
|
Margin size for the grid. Defaults to 0. |
0
|
target_name
|
[type]
|
Target output name for the grid image. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
return_array
|
bool
|
Whether to return an array of not. If set to False the function writes the grid image to disk. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
An MgImage object referring to the internal grid image. |
Source code in musicalgestures/_grid.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
actions_from_motion ¶
actions_from_motion(envelope=None, fs=None, threshold=0.15, min_duration=0.1, min_gap=0.1)
Segment this video into actions and describe the shape of each.
With no envelope given, one is built from the body rather than from the picture: pose landmarks are extracted if they are not cached, and their quantity of motion becomes the envelope. That is what makes the result follow the person and not the camera --- a pan moves every pixel and moves no landmark relative to the others.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope
|
A motion envelope to segment. Defaults to None, meaning build one from pose. Pass your own to segment something else, and note that a pixel-derived envelope will read camera motion as action. |
None
|
|
fs
|
float
|
Sampling rate of |
None
|
threshold
|
float
|
Level counting as motion, as a fraction of the envelope's range. Defaults to 0.15. |
0.15
|
min_duration
|
float
|
Shortest span kept, in seconds. Defaults to 0.1. |
0.1
|
min_gap
|
float
|
Longest gap closed, in seconds. Defaults to 0.1. |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list[Action]
|
The actions found, each carrying its shape in |
Source code in musicalgestures/_actions.py
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 | |
postures_from_pose ¶
postures_from_pose(landmarks=None, fs=None, stability=0.1, min_duration=1.0, min_gap=0.25, **pose_kwargs)
Segment this video into postures and describe the shape of each.
With no landmarks given, they are taken from a cached pose() result when there is
one, and extracted fresh otherwise. The result is the static counterpart of
actions_from_motion(): where that cuts the recording where the body moves, this
cuts it where the body holds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
|
None
|
|
fs
|
float
|
Sampling rate of |
None
|
stability
|
float
|
Fastest configuration change still counting as held, in torso lengths per second. Defaults to 0.1. |
0.1
|
min_duration
|
float
|
Shortest hold kept, in seconds. Defaults to 1.0. |
1.0
|
min_gap
|
float
|
Longest observed wobble bridged, in seconds. Defaults to 0.25. |
0.25
|
**pose_kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list[Posture]
|
The postures found, each carrying its configuration and shape. Also stored |
list[Posture]
|
on the video as |
Source code in musicalgestures/_postures.py
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 | |
resample ¶
resample(fps=None, speed=None, skip=None, target_name=None, overwrite=True)
Resample the (already loaded) video and return a new MgVideo, leaving the original object untouched.
Three independent, combinable operations:
fps: retime to a target frame rate using FFmpeg'sfpsfilter — duration-preserving (frames are dropped/duplicated to hit the rate), e.g. 30 → 25 fps.speed: change playback speed by a factor (>1 faster/shorter, <1 slower/longer); the video is retimed withsetptsand the audio withatemposo they stay in sync.skip: integer frame decimation — discardskipframes for every one kept (this also shortens/speeds up the clip), matching the loader'sskipparameter.
When more than one is given they are applied in order: skip → speed/fps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fps
|
float
|
Target frame rate (duration-preserving). Defaults to None. |
None
|
speed
|
float
|
Playback-speed factor. Defaults to None. |
None
|
skip
|
int
|
Discard |
None
|
target_name
|
str
|
Output name. Defaults to None (input filename + "_resampled"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgVideo |
MgVideo
|
a new MgVideo pointing to the resampled file. |
Source code in musicalgestures/_videoadjust.py
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 | |
save_analysis ¶
save_analysis(of, fps, aom, com, qom, motion_analysis, audio_descriptors, width, height, unit, title, target_name_plot, overwrite)
Helper function to plot the motion data using matplotlib.
Source code in musicalgestures/_motionvideo.py
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 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 | |
show ¶
show(filename=None, key=None, mode='windowed', window_width=640, window_height=480, window_title=None, **ipython_kwargs)
General method to show an image or video file either in a window, or inline in a jupyter notebook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
If given, |
None
|
key
|
str
|
If given, |
None
|
mode
|
str
|
Whether to show things in a separate window or inline in the jupyter notebook. Accepted values are 'windowed' and 'notebook'. Defaults to 'windowed'. |
'windowed'
|
window_width
|
int
|
The width of the window. Defaults to 640. |
640
|
window_height
|
int
|
The height of the window. Defaults to 480. |
480
|
window_title
|
str
|
The title of the window. If None, the title of the window will be the file name. Defaults to None. |
None
|
ipython_kwargs
|
dict
|
Additional arguments for IPython.display.Image or IPython.display.Video. Defaults to None. |
{}
|
Source code in musicalgestures/_show.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
info ¶
info(type=None, autoshow=True, overwrite=True)
Returns info about video/audio/format file using ffprobe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
Type of information to retrieve. Possible choices are 'summary', 'audio', 'video', 'format' or 'frame'. Defaults to None (which gives info about video, audio and format). - 'summary': prints a human-readable table of key video properties (resolution, fps, frame count, duration, color mode, audio) and returns a dict. - 'audio' / 'video' / 'format': returns the matching ffprobe stream as a pandas DataFrame row. - 'frame': renders a bar chart of I/P/B frame sizes and returns a DataFrame. - None: returns a DataFrame with all ffprobe stream and format metadata. |
None
|
autoshow
|
bool
|
Whether to show the I/P/B frames figure automatically. Defaults to True. NB: The type argument needs to be set to 'frame'. |
True
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filename to avoid overwriting. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
|
dict or pandas.DataFrame: dict when type='summary', DataFrame otherwise. |
Source code in musicalgestures/_info.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
history ¶
history(filename=None, history_length=10, weights=1, normalize=False, norm_strength=1, norm_smooth=0, target_name=None, overwrite=True)
This function creates a video where each frame is the average of the N previous frames, where n is determined by history_length. The history frames are summed up and normalized, and added to the current frame to show the history. Uses ffmpeg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the input video file. If None, the video file of the MgVideo is used. Defaults to None. |
None
|
history_length
|
int
|
Number of frames to be saved in the history tail. Defaults to 10. |
10
|
weights
|
int / float / list / str
|
Defines the weight or weights applied to the frames in the history tail. If given as list the first element in the list will correspond to the weight of the newest frame in the tail. If given as a str - like "3 1.2 1" - it will be automatically converted to a list - like [3, 1.2, 1]. Defaults to 1. |
1
|
normalize
|
bool
|
If True, the history video will be normalized. This can be useful when processing motion (frame difference) videos. Defaults to False. |
False
|
norm_strength
|
int / float
|
Defines the strength of the normalization where 1 represents full strength. Defaults to 1. |
1
|
norm_smooth
|
int
|
Defines the number of previous frames to use for temporal smoothing. The input range of each channel is smoothed using a rolling average over the current frame and the |
0
|
target_name
|
str
|
Target output name for the video. Defaults to None (which assumes that the input filename with the suffix "_history" should be used). |
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 |
A new MgVideo pointing to the output video file. |
Source code in musicalgestures/_history.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
history_cv2 ¶
history_cv2(filename=None, history_length=10, weights=1, convert=True, target_name=None, overwrite=True)
This function creates a video where each frame is the average of the N previous frames, where n is determined by history_length. The history frames are summed up and normalized, and added to the current frame to show the history. Uses cv2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the input video file. If None, the video file of the MgVideo is used. Defaults to None. |
None
|
history_length
|
int
|
Number of frames to be saved in the history tail. Defaults to 10. |
10
|
weights
|
int / float / list
|
Defines the weight or weights applied to the frames in the history tail. If given as list the first element in the list will correspond to the weight of the newest frame in the tail. Defaults to 1. |
1
|
convert
|
bool
|
If True (default), non-AVI input is first converted to an all-intra MJPEG |
True
|
target_name
|
str
|
Target output name for the video. Defaults to None (which assumes that the input filename with the suffix "_history" should be used). |
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 |
A new MgVideo pointing to the output video file. |
Source code in musicalgestures/_history.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
blend ¶
blend(filename=None, mode='all_mode', component_mode='average', target_name=None, overwrite=True)
Finds and saves a blended image of an input video file using FFmpeg. The FFmpeg tblend (time blend) filter takes two consecutive frames from one single stream, and outputs the result obtained by blending the new frame on top of the old frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the input video file. If None, the video file of the MgObject is used. Defaults to None. |
None
|
mode
|
str
|
Set blend mode for specific pixel component or all pixel components. Accepted options are 'c0_mode', 'c1_mode', c2_mode', 'c3_mode' and 'all_mode'. Defaults to 'all_mode'. |
'all_mode'
|
component_mode
|
str
|
Component mode of the FFmpeg tblend. Available values for component modes can be accessed here: https://ffmpeg.org/ffmpeg-filters.html#blend-1. Defaults to 'average'. |
'average'
|
target_name
|
str
|
The name of the output video. Defaults to None (which assumes that the input filename with the component mode suffix should be used). |
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 |
|---|---|---|
MgImage |
MgImage
|
A new MgImage pointing to the output image file. |
Source code in musicalgestures/_blend.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
pixelarray ¶
pixelarray(width=640, target_name=None, overwrite=True)
Creates a 'Frame-Averaged Pixel Array' of a video by reducing each frame to a single pixel and arranging all frames into a single image. This is equivalent to the bash script that scales each frame to 1x1 pixel and then tiles them into a grid.
Based on the original bash script concept: - Each frame is reduced to a single pixel (average color of the frame) - All pixel values are arranged in a grid with specified width - Height is calculated automatically based on total frames and width
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the output image in pixels (number of frame-pixels per row). Defaults to 640. |
640
|
target_name
|
str
|
The name of the output image file. If None, uses input filename
with 'framearray |
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 |
|---|---|---|
MgImage |
A new MgImage pointing to the output frame-averaged pixel array image file. |
Source code in musicalgestures/_frameaverage.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
pixelarray_cv2 ¶
pixelarray_cv2(width=640, target_name=None, overwrite=True)
Alternative implementation using OpenCV for more control over the process. Creates a 'Frame-Averaged Pixel Array' by reading each frame, calculating its average color, and arranging these average colors in a grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the output image in pixels. Defaults to 640. |
640
|
target_name
|
str
|
The name of the output image file. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
A new MgImage pointing to the output frame-averaged pixel array image file. |
Source code in musicalgestures/_frameaverage.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
pixelarray_stats ¶
pixelarray_stats(width=640, include_stats=True)
Creates a frame-averaged pixel array and optionally returns statistics about the video. This function provides additional information similar to the bash script's output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the output image in pixels. Defaults to 640. |
640
|
include_stats
|
bool
|
Whether to return detailed statistics. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary containing the generated MgImage and optional statistics. |
Source code in musicalgestures/_frameaverage.py
125 126 127 128 129 130 131 132 133 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 | |
heatmap ¶
heatmap(colormap='inferno', overlay=True, alpha=0.75, background_dim=0.4, blur=0, normalize=True, gamma=0.5, target_name=None, overwrite=True)
Renders a motion heatmap showing which parts of the video change the most.
The function accumulates the absolute pixel difference between consecutive frames
over the whole video, producing a single image where bright/hot regions mark areas
of frequent or large change and dark/cool regions mark areas that stay still. When
overlay is True the heat is composited on top of a dimmed average frame, so the
activity is shown in the spatial context of the scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colormap
|
str
|
Any matplotlib colormap name used to colour the heat (e.g. 'inferno', 'jet', 'viridis', 'hot', 'magma'). Defaults to 'inferno'. |
'inferno'
|
overlay
|
bool
|
If True, composite the heatmap over a dimmed grayscale average frame so the motion is shown in context. If False, render the bare heatmap on a black background. Defaults to True. |
True
|
alpha
|
float
|
Maximum opacity of the heat overlay in [0, 1]. Hotter
pixels are more opaque. Only used when |
0.75
|
background_dim
|
float
|
Brightness multiplier for the average-frame
background in [0, 1]. Lower values make the heat stand out more. Only used
when |
0.4
|
blur
|
int
|
Radius of an optional Gaussian smoothing applied to the accumulated motion (0 disables). Gives a smoother, less speckled heatmap. Defaults to 0. |
0
|
normalize
|
bool
|
If True, scale the accumulated motion so the most active pixel maps to the top of the colormap. Defaults to True. |
True
|
gamma
|
float
|
Gamma applied to the normalised heat before colouring. Values < 1 boost faint motion so subtle activity is visible; 1.0 is linear. Defaults to 0.5. |
0.5
|
target_name
|
str
|
The name of the output image. Defaults to None (which uses the input filename with the suffix "_heatmap.png"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment the target filename to avoid overwriting. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
A new MgImage pointing to the output heatmap image file. |
Source code in musicalgestures/_heatmap.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
motiontempo ¶
motiontempo(fmin=0.2, fmax=8.0, dpi=300, autoshow=True, title=None, target_name=None, overwrite=True)
Estimates the dominant motion tempo of a video from its quantity of motion.
A quantity-of-motion (QoM) signal is computed as the mean absolute difference
between consecutive frames. Its dominant periodicity within [fmin, fmax] is
found with an FFT and reported both in Hz and in beats per minute (BPM), giving a
simple estimate of the overall motion tempo (e.g. step rate of a dancer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmin
|
float
|
Lowest motion frequency to consider (Hz). Defaults to 0.2. |
0.2
|
fmax
|
float
|
Highest motion frequency to consider (Hz). Defaults to 8.0. |
8.0
|
dpi
|
int
|
Image quality of the rendered figure in DPI. Defaults to 300. |
300
|
autoshow
|
bool
|
Whether to show the resulting figure automatically. Defaults to True. |
True
|
title
|
str
|
Optionally add a title to the figure. Use 'filename' for the file name. Defaults to None. |
None
|
target_name
|
str
|
The name of the output image. Defaults to None (which uses the input filename with the suffix "_motiontempo.png"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment the target filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
MgFigure
|
An MgFigure object. Numeric results are available in |
Source code in musicalgestures/_motiontempo.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
motionvectors ¶
motionvectors(target_name=None, overwrite=True)
Renders a video visualising the motion vectors encoded in the input video.
Inter-frame codecs (MPEG-1/2/4, H.264, H.265, …) store motion vectors that describe
how macroblocks move between frames. This method uses FFmpeg's codecview filter
(with -flags2 +export_mvs) to draw those vectors as arrows on top of the video,
giving a quick, decoder-level view of motion without any re-computation.
NB: Only codecs that actually carry motion vectors will show arrows. Intra-only
formats (e.g. MJPEG, common in .avi files) have none — convert to an inter-frame
codec first (e.g. via show(mode='notebook') which makes an mp4, or any mp4/h264
source) to see motion vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_name
|
str
|
Target output name for the video. Defaults to None (which uses the input filename with the suffix "_motionvectors"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment the target filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgVideo |
MgVideo
|
An MgVideo pointing to the rendered motion-vector video. |
Source code in musicalgestures/_motionvectors.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
motionvectordata ¶
motionvectordata()
Read the motion vectors the codec already computed, as numbers rather than arrows.
motionvectors() renders these as a video to look at. This returns them as data, and
the difference in cost is the point: an inter-frame codec has already searched for the
displacement of every macroblock, so reading its answer is close to free, while
differencing pixels does the same search again in Python. On a 103-minute recording,
decoding took 2.2 s and decoding with the vectors took 2.7 s, against 27 minutes for
the frame-differenced quantity of motion.
What it is not. The vectors are the encoder's decisions, not a measurement of the scene: an encoder is entitled to any vector that predicts the block cheaply, and on flat or still regions it will pick one that has nothing to do with motion. The result tracks quantity of motion well where there is motion to track and poorly where there is not --- on that same corpus, median r = 0.86 in windows with motion and 0.57 in windows without. Re-encoded proxies carry their proxy encoder's vectors, not the camera's.
Vectors are normalised to point forward in time. A B-frame may predict a block
from a later frame, which reverses the sign; dividing by the vector's source
corrects that, so a block moving right reads as positive whichever way it was
predicted. Without it a B-frame's vectors point backwards half the time and averaging
them gives roughly nothing.
The reference distance is corrected from the cadence, with two residuals.
source records only the direction, plus or minus one, never how many frames away
the reference was, so the distance is recovered instead from the picture-type
cadence: past-referencing vectors are divided by the display-order gap to the
previous reference frame, which makes a P-frame after a run of B-frames read
per-frame displacement rather than the whole span's. What the cadence cannot see:
blocks reaching an OLDER reference through multi-reference prediction --- measured
on a block moving 4 pixels per frame, such blocks read as 8 or 16 with source at
plus or minus one throughout --- and B-frame vectors pointing at a future
reference, which default filtering excludes. So median_dx and median_dy are
medians for a reason and are robust to the residuals; magnitude is a sum and
inherits what remains of the over-count. Treat magnitude as a quantity to
correlate against itself over time, which is what it was validated for, rather
than as pixels per second.
Returns:
| Name | Type | Description |
|---|---|---|
MgMotionVectorData |
MgMotionVectorData
|
|
MgMotionVectorData
|
|
|
MgMotionVectorData
|
quantity to compare against quantity of motion), and |
|
MgMotionVectorData
|
(the typical displacement in pixels of the blocks that moved --- taken over |
|
MgMotionVectorData
|
every block instead, these would report the still background's zero however fast |
|
MgMotionVectorData
|
the one moving thing was going). Frames with no vectors, which includes every |
|
MgMotionVectorData
|
intra frame, read as zero throughout. |
Raises:
| Type | Description |
|---|---|
ImportError
|
if PyAV is not installed. ffprobe reports that the side data exists but will not print the vectors themselves, and ffmpeg has no numeric dump, so there is no route to these numbers through the command line. |
Source code in musicalgestures/_motionvectors.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
motionvectorhistory ¶
motionvectorhistory(mode='direction', colormap='inferno', gamma=0.5, target_name=None, overwrite=True)
The whole space the motion happened in, accumulated from the codec's vectors.
motionhistory() renders the Bobick--Davis image from frame differences and encodes
recency; heatmap() accumulates where pixels changed. Neither can say which way
anything went, because a frame difference has no sign --- somebody entering a region
and leaving it look identical. A motion vector is a displacement, so this can, and
that is the reason for it to exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
|
'direction'
|
colormap
|
str
|
Matplotlib colormap, used by |
'inferno'
|
gamma
|
float
|
Applied to the accumulated amount before colouring, so that a few violent moments do not leave everything else black. Defaults to 0.5. |
0.5
|
target_name
|
str
|
Output path. Defaults to the input name with
|
None
|
overwrite
|
bool
|
Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
MgImage
|
the rendered image, at the video's own dimensions. |
Notes
Built from P-frames only, for the reason given on motionvectordata. And the
vectors are the encoder's decisions: over a region with no detail every candidate
predicts equally well, so the encoder copies whatever its neighbours used and the
field there is inherited rather than observed. Expect that wherever the picture is
flat.
Source code in musicalgestures/_motionvectors.py
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 | |
motionvectorgrams ¶
motionvectorgrams(colormap='inferno', gamma=0.5, max_width=4000, target_name=None, overwrite=True)
Motiongrams built from the codec's motion vectors.
The same view motiongrams() gives, at a fraction of the cost, because the
displacement has already been computed by the encoder. The trade is resolution: this
is drawn on the macroblock lattice, sixteen pixels, and on P-frames only, so on 50 fps
footage it carries about 12.6 columns per second rather than 50.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colormap
|
str
|
Matplotlib colormap. Defaults to |
'inferno'
|
gamma
|
float
|
Applied before colouring so quiet passages stay visible. Defaults to 0.5. |
0.5
|
max_width
|
int
|
Longest the saved image's TIME axis may be, in pixels --- across the horizontal image, down the vertical one. One point per P-frame is right for the array and wrong for the picture: a 158-minute session has 77,592 of them, and stretching that to the video's height gave a 149-megapixel PNG of 309 MB for something meant to be glanced at. Points are pooled by taking the maximum, not the mean, so a brief accent still shows in a column standing for several seconds. Defaults to 4000. |
4000
|
target_name
|
str
|
Output path; the two images take |
None
|
overwrite
|
bool
|
Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgList |
MgList
|
the y-motiongram and the x-motiongram, in that order, in the classic |
MgList
|
orientations --- y wide with time rightward, x tall with time downward. |
Source code in musicalgestures/_motionvectors.py
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 | |
motionvectorwaterfall ¶
motionvectorwaterfall(n_samples=40, axis='horizontal', cmap='viridis', dpi=200, elev=35, azim=-60, target_name=None, overwrite=True)
A waterfall of motion profiles, cascading through time.
The same cascade silhouette_waterfall() draws, but from displacement rather than
from a silhouette, so it needs no background subtraction and no pose model --- and it
shows where motion was, not where a body was. A dancer standing still has a
silhouette and no vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
How many profiles to stack. Defaults to 40. |
40
|
axis
|
str
|
|
'horizontal'
|
cmap
|
str
|
Matplotlib colormap, applied over time. Defaults to
|
'viridis'
|
dpi
|
int
|
Defaults to 200. |
200
|
elev, azim
|
float
|
3D view angles. Default to 35 and -60. |
required |
target_name
|
str
|
Output path. Defaults to the input name with
|
None
|
overwrite
|
bool
|
Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
MgFigure
|
the rendered waterfall. |
Source code in musicalgestures/_motionvectors.py
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 | |
motionvectoroverview ¶
motionvectoroverview(colormap='inferno', gamma=0.5, target_name=None, overwrite=True)
One sheet per recording, from one decode: where, how much, and when.
Built for a first look at unfamiliar material rather than for measurement. Hours of archive video, several representations per file, as the starting point for qualitative annotation --- so it favours covering the whole recording cheaply over resolving any part of it finely.
Five panels, of the three kinds a first pass wants:
- spatial --- the area motion covered, coloured by direction, and the same accumulation as plain amount;
- temporal --- motion over the whole recording, the curve to scrub against;
- spatio-temporal --- the y- and x-motiongrams, position against time, where a body crossing the room draws a diagonal.
Everything comes from the codec's own motion vectors, so the cost is close to the cost of reading the file: about five minutes for a 100-minute 1920x1080 recording, against roughly twenty-four for the same views computed one at a time, and far less than differencing the pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colormap
|
str
|
Matplotlib colormap for the amount panels. Defaults to
|
'inferno'
|
gamma
|
float
|
Applied before colouring so quiet passages stay visible. Defaults to 0.5. |
0.5
|
target_name
|
str
|
Output path. Defaults to the input name with
|
None
|
overwrite
|
bool
|
Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
MgFigure
|
the sheet, with every underlying array in |
MgFigure
|
feed further analysis without decoding again. |
Source code in musicalgestures/_motionvectors.py
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |
motionscape ¶
motionscape(track=None, track_times=None, n_scales=96, colormap='magma', gamma=0.5, target_name=None, overwrite=True)
A scape of the recording's motion: every timescale in one triangle.
After Craig Sapp's keyscape, where each row is a window length and the apex is a single window covering the whole piece. Here each cell is the mean quantity of motion over that window, so the plot answers a question the flat curve cannot: at what scale does this recording stop looking like one thing? A session of even, continuous improvisation is flat all the way up. A session of separated bursts stays separated at the base and merges into one mass near the apex, and the height at which it merges is the length of the structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
array - like
|
One value per frame to build the scape from. Pass
a frame-differenced quantity of motion here --- |
None
|
track_times
|
array - like
|
Seconds for each value in |
None
|
n_scales
|
int
|
Rows in the triangle. Defaults to 96. |
96
|
colormap
|
str
|
Defaults to |
'magma'
|
gamma
|
float
|
Applied before colouring. Defaults to 0.5. |
0.5
|
target_name
|
str
|
Output path. Defaults to the input name with
|
None
|
overwrite
|
bool
|
Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
MgFigure
|
the scape, with the track and the triangle in |
Source code in musicalgestures/_motionvectors.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 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 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 | |
pose_timeline ¶
pose_timeline(view='strip', n_samples=12, min_visibility=0.5, landmarks=None, times=None, cmap='viridis', dpi=200, trajectories=None, markers=TRAJECTORY_GROUPS, smooth=SMOOTH, smooth_spatial=SMOOTH_SPATIAL, target_name=None, overwrite=True, **pose_kwargs)
Postures and trajectories over time. See pose_timeline.
Landmarks come from a cached pose() result when there is one, exactly as posegram
resolves them, and otherwise from a fresh extraction.
Source code in musicalgestures/_posetimeline.py
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 | |
multishot ¶
multishot(n_bodies=8, n_candidates=120, start=None, end=None, width=960, tolerance=TOLERANCE, feather=FEATHER, min_area=MIN_AREA, max_area=MAX_AREA, max_border=MAX_BORDER, shadow_ratio=SHADOW_RATIO, region=None, segmenter='plate', select='spaced', background='plate', colorize=False, animate=False, frame_ms=700, target_name=None, overwrite=True)
Many moments of this recording in one picture, as an MgImage.
The method form of multishot, so it composes with the rest of the object API. See
that function for what the arguments mean and for how this differs from
stroboscope().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animate
|
bool
|
Write a looping GIF of the build-up instead of the still: the bare room first, one more body per frame in time order, and the finished composite held for three frames' worth at the end. |
False
|
frame_ms
|
int
|
Milliseconds per animation frame. Defaults to 700. |
700
|
target_name
|
str
|
Output name. Defaults to "_multishot.png", or
"_multishot.gif" when |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
the composite, or the GIF of it building up. |
Raises:
| Type | Description |
|---|---|
ValueError
|
when no frame held a body of a plausible size. An empty room is not a result, and returning one silently would look like the recording was empty rather than like the size bounds matched nothing. |
Source code in musicalgestures/_multishot.py
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 | |
plate ¶
plate(width=960, n_samples=300, stratify=True, target_name=None, overwrite=True)
The empty room this recording was made in, as an MgImage.
The method form of room_plate: a per-pixel median over sampled frames, twice, with
the second pass spread over the recording so that anything standing there through a
break does not become furniture.
In colour, from the frames the grey pass chose --- not a fresh draw, which would be a different room.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Working width. Defaults to 960; pass the video's own width for a full-resolution room. |
960
|
n_samples
|
int
|
Frames to sample. Defaults to 300. |
300
|
stratify
|
bool
|
Spread the second pass over the recording. Defaults to True. |
True
|
target_name
|
str
|
Output name. Defaults to "_plate.png". |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
the room. |
Source code in musicalgestures/_multishot.py
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 | |
zoompage ¶
zoompage(target_name=None, overwrite=True, max_points=8000, which='videogram_v')
The zoomable page for this recording, in one call, as a method.
Everything derives from the video itself. The motion track and gram come from
extract_tracks, computed on first call and cached beside the video like every
other analysis; the audio band comes from the video's own soundtrack when it has
one; and the player is the video, referenced by its bare name, so the page works
from the folder the two share and needs no server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_name
|
str
|
Output path. Defaults to "_zoom.html" beside the video. |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
max_points
|
int
|
Ceiling on embedded envelope points. |
8000
|
which
|
str
|
Which cached gram to embed as the strip. |
'videogram_v'
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
The file written. |
Source code in musicalgestures/_zoomview.py
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 | |
eulerian ¶
eulerian(mode='color', freq_low=0.83, freq_high=1.0, amplification=50, levels=4, chroma_attenuation=1.0, lambda_cutoff=16, target_name=None, overwrite=True)
Applies Eulerian Video Magnification (EVM) to reveal subtle changes in a video.
EVM amplifies small temporal variations that are normally invisible. Two modes are available:
mode='color'— amplifies subtle colour changes (e.g. blood flow / pulse, breathing). Uses a Gaussian pyramid and an ideal (FFT) temporal band-pass filter. Processed in two passes so only a small down-sampled stack is held in memory.mode='motion'— amplifies subtle motion. Uses a Laplacian pyramid with a streaming IIR temporal band-pass filter and spatial-wavelength attenuation, so it runs frame-by-frame with low memory use.
Based on Wu et al., "Eulerian Video Magnification for Revealing Subtle Changes in the World" (SIGGRAPH 2012).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
'color' or 'motion'. Defaults to 'color'. |
'color'
|
freq_low
|
float
|
Lower temporal cutoff in Hz. Defaults to 0.83 (~50 bpm). |
0.83
|
freq_high
|
float
|
Upper temporal cutoff in Hz. Defaults to 1.0 (~60 bpm). |
1.0
|
amplification
|
float
|
Amplification factor (alpha). Defaults to 50. |
50
|
levels
|
int
|
Number of spatial pyramid levels. Defaults to 4. |
4
|
chroma_attenuation
|
float
|
Chrominance attenuation in [0, 1] (color mode). Lower values reduce colour artefacts. Defaults to 1.0. |
1.0
|
lambda_cutoff
|
float
|
Spatial wavelength cutoff for amplitude attenuation (motion mode). Defaults to 16. |
16
|
target_name
|
str
|
Target output name. Defaults to None (input filename with the suffix "_evm"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgVideo |
MgVideo
|
An MgVideo pointing to the magnified output video. |
Source code in musicalgestures/_eulerian.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
sonomotiongram ¶
sonomotiongram(sonogram='vertical', n_fft=2048, sr=22050, n_iter=32, flip=True, normalize=True, target_name=None, overwrite=True)
Creates a sonomotiongram: a sonification of the video's motiongram.
The motiongram (a time–space image of where motion happens) is treated as a magnitude spectrogram — spatial position maps to frequency, motion intensity to amplitude — and converted back to audio with an inverse STFT (Griffin–Lim phase estimation). The result lets you hear the motion. Based on Jensenius, "Some video abstraction techniques for displaying body movement in analysis and performance" / sonomotiongrams (SMC 2013).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sonogram
|
str
|
Which motiongram to sonify: 'vertical' (motion across the vertical axis) or 'horizontal'. Defaults to 'vertical'. |
'vertical'
|
n_fft
|
int
|
FFT size; sets the number of frequency bins (n_fft//2+1) the motiongram rows are mapped onto. Defaults to 2048. |
2048
|
sr
|
int
|
Sample rate of the rendered audio. Defaults to 22050. |
22050
|
n_iter
|
int
|
Griffin–Lim iterations for phase estimation (higher = cleaner, slower). Defaults to 32. |
32
|
flip
|
bool
|
If True, map the top of the image to high frequencies (usually more intuitive). Defaults to True. |
True
|
normalize
|
bool
|
Normalise the rendered audio to peak 1.0. Defaults to True. |
True
|
target_name
|
str
|
Output audio filename. Defaults to None (input filename
with the suffix "sono |
None
|
overwrite
|
bool
|
Whether to allow overwriting or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgAudio |
An MgAudio pointing to the rendered sonification (WAV). |
Source code in musicalgestures/_sonification.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
stroboscope ¶
stroboscope(n_samples=12, method='auto', threshold=0.1, kernel_size=5, keep_largest=False, colorize=True, background='average', target_name=None, overwrite=True)
Deprecated since 1.23.0: use multishot(), which absorbed this.
The two were the same picture made two ways, and having both meant a reader had to
know which. multishot() now carries both: select='even' is this method's regular
sampling, background='average' is its mean-average ground, and colorize=True
is its time tint. The defaults differ because the defaults are an opinion --- moments
chosen for spatial separation, on a median plate --- and even sampling onto a mean
average is what makes two bodies land in the same place on a ground that keeps a ghost
of everyone who crossed.
This wrapper delegates and will be removed at 2.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Silhouettes to composite. Defaults to 12. |
12
|
method
|
str
|
'auto', 'mediapipe' or 'bgsub'. Defaults to 'auto'. |
'auto'
|
threshold
|
float
|
Foreground threshold (0-1). Defaults to 0.1. |
0.1
|
kernel_size
|
int
|
Unused by the replacement; accepted for compatibility. |
5
|
keep_largest
|
bool
|
Unused by the replacement; accepted for compatibility. |
False
|
colorize
|
bool
|
Tint each silhouette by time. Defaults to True. |
True
|
background
|
str
|
'average', 'first', 'black' or 'white'. Defaults to 'average'. |
'average'
|
target_name
|
str
|
Output name. Defaults to "_stroboscope.png". |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
the composite. |
Source code in musicalgestures/_spacetime.py
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 | |
silhouette_waterfall ¶
silhouette_waterfall(n_samples=40, method='auto', threshold=0.1, kernel_size=5, keep_largest=False, axis='horizontal', cmap='viridis', dpi=200, elev=35, azim=-60, axes=True, crop=False, target_name=None, overwrite=True)
Renders a 3D silhouette waterfall: the per-frame silhouette projected onto one spatial axis and stacked as cascading curves along a time (depth) axis, so the body's occupancy profile "flows" through time — like a 3D spectrogram waterfall.
For a single person on a static background, raise threshold and/or set
keep_largest=True for a cleaner profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Number of time slices (profiles) to stack. Defaults to 40. |
40
|
method
|
str
|
Silhouette extraction: 'auto', 'mediapipe', or 'bgsub'. Defaults to 'auto'. |
'auto'
|
threshold
|
float
|
Foreground threshold (0–1). Higher rejects more background. Defaults to 0.1. |
0.1
|
kernel_size
|
int
|
Morphological cleanup kernel (0 disables). Defaults to 5. |
5
|
keep_largest
|
bool
|
Keep only the largest blob (the person). Defaults to False. |
False
|
axis
|
str
|
'horizontal' profiles over x (collapse y); 'vertical' profiles over y. Defaults to 'horizontal'. |
'horizontal'
|
cmap
|
str
|
Matplotlib colormap (by time). Defaults to 'viridis'. |
'viridis'
|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
elev
|
float
|
3D elevation angle. Defaults to 35. |
35
|
azim
|
float
|
3D azimuth angle. Defaults to -60. |
-60
|
axes
|
bool
|
Draw the axes, tick labels, and title. Set to False for a clean render with all axes and text removed. Defaults to True. |
True
|
crop
|
bool
|
Tighten the spatial axis to the occupied (nonzero) 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 ("_silhouette_waterfall.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the 3D waterfall figure (the stacked profiles are in |
Source code in musicalgestures/_spacetime.py
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 | |
motionhistory ¶
motionhistory(threshold=0.05, decay=0.3, normalize=False, blur=0, cmap='hot', dpi=300, target_name=None, overwrite=True)
Renders a Motion History Image (Bobick & Davis): a single image where intensity encodes how recently motion occurred at each pixel (recent motion bright, older motion fades out).
A motion mark is set to full intensity where motion occurs and then decays linearly to
zero over a window set by decay, so old motion disappears instead of accumulating and
washing out the image. Raise threshold to ignore background noise, and lower decay
for shorter (less crowded) trails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Motion threshold (0–1) on frame differences. Higher rejects more background noise. Defaults to 0.05. |
0.05
|
decay
|
float
|
Fade window as a fraction of the clip length (0–1): a motion mark fully fades after this fraction of the video. Smaller = shorter trails, less blow-out. Defaults to 0.3. |
0.3
|
normalize
|
bool
|
Stretch the result to the full intensity range. Defaults to False. The MHI is already built in [0, 1], so normalization is rarely needed; when the final frames are static it amplifies faint residual trails and over-brightens ("blows up") the image, so it is guarded to skip when the peak intensity is very low. |
False
|
blur
|
int
|
Optional Gaussian smoothing radius for the difference mask (0 = off). Helps suppress speckle noise. Defaults to 0. |
0
|
cmap
|
str
|
Matplotlib colormap. Defaults to 'hot'. |
'hot'
|
dpi
|
int
|
Output DPI. Defaults to 300. |
300
|
target_name
|
str
|
Output name. Defaults to None ("_mhi.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
the motion history image. |
Source code in musicalgestures/_spacetime.py
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 | |
spacetime_volume ¶
spacetime_volume(n_samples=50, downsample=8, method='auto', threshold=0.1, kernel_size=5, keep_largest=False, cmap='viridis', dpi=200, elev=20, azim=-60, target_name=None, overwrite=True)
Renders a 3D space-time scatter of the person's silhouette: points (x, y, t) where the silhouette is present, with time on the depth axis and colour, showing how the body occupies space through time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Number of time samples (depth slices). Defaults to 50. |
50
|
downsample
|
int
|
Spatial downsampling factor for the silhouette points. Defaults to 8. |
8
|
method
|
str
|
Silhouette extraction: 'auto', 'mediapipe', or 'bgsub'. Defaults to 'auto'. |
'auto'
|
threshold
|
float
|
Foreground threshold (0–1). Higher rejects more background. Defaults to 0.1. |
0.1
|
kernel_size
|
int
|
Morphological cleanup kernel for the silhouette (0 disables). Defaults to 5. |
5
|
keep_largest
|
bool
|
Keep only the largest blob (the person). Defaults to False. |
False
|
cmap
|
str
|
Matplotlib colormap for time. Defaults to 'viridis'. |
'viridis'
|
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
|
target_name
|
str
|
Output name. Defaults to None ("_spacetime_volume.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the 3D space-time figure (data holds the point cloud). |
Source code in musicalgestures/_spacetime.py
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 | |
beat_statistics ¶
beat_statistics(source='motion', n_bins=32, cmap='YlOrRd', dpi=300, autoshow=True, title=None, target_name=None, overwrite=True, fmin=0.2, fmax=8.0)
Circular statistics of beat-timing consistency, from the audio or from the motion.
Fits an ideal isochronous beat grid to the detected beats and visualises how each beat deviates from it (a polar phase histogram with the mean resultant vector, plus a millisecond-deviation time series), revealing whether the timing rushes, drags, or stays steady. Requires at least four detected beats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
|
'motion'
|
n_bins
|
int
|
Bins in the polar phase histogram. Defaults to 32. |
32
|
cmap
|
str
|
Colormap for the polar histogram. Defaults to 'YlOrRd'. |
'YlOrRd'
|
dpi
|
int
|
Output DPI. Defaults to 300. |
300
|
autoshow
|
bool
|
Kept for API parity (display is via show()). Defaults to True. |
True
|
title
|
str
|
Optional figure title; use 'filename' for the file name. Defaults to None. |
None
|
target_name
|
str
|
Output image name. Defaults to None. |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
fmin
|
float
|
Lowest motion-onset rate to consider (Hz), 'motion' only. Defaults to 0.2. |
0.2
|
fmax
|
float
|
Highest motion-onset rate to consider (Hz), 'motion' only. Defaults to 8.0. |
8.0
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure | None'
|
figure with the beat statistics in |
Source code in musicalgestures/_movementbeats.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
tempo_similarity ¶
tempo_similarity(dpi=300, autoshow=True, title=None, target_name=None, overwrite=True)
Compare the audio tempo with the motion tempo and report how similar they are.
Estimates the tempo of the audio track (from its onset-strength envelope) and of the motion (from the quantity-of-motion envelope), then aligns the two normalised envelopes and cross-correlates them to measure their agreement. The figure shows the two envelopes overlaid and their cross-correlation; the report (also saved as a CSV) lists the audio tempo, motion tempo, their ratio and nearest harmonic relationship, the peak cross-correlation, and the lag (s) at which the motion best aligns with the audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dpi
|
int
|
Output DPI. Defaults to 300. |
300
|
autoshow
|
bool
|
Kept for API parity (display via show()). Defaults to True. |
True
|
title
|
str
|
Optional figure title; 'filename' uses the file name. Defaults to None. |
None
|
target_name
|
str
|
Output image name. Defaults to None ("_tempo_similarity.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure | None'
|
the report figure (metrics in |
Source code in musicalgestures/_movementbeats.py
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 | |
motiondescriptors ¶
motiondescriptors(window='hann', entropy_bins=50, fmin=0.2, fmax=10.0, save_data=True, save_plot=True, data_format='csv', target_name=None, overwrite=True)
Scalar motion descriptors derived from the quantity-of-motion (QoM) signal.
Computes a compact set of higher-level descriptors that summarise how something moves,
complementing the per-frame motion data from :func:motion:
- motion_energy — mean squared QoM; the overall amount of motion.
- motion_smoothness — SPARC (spectral arc length) of the QoM profile; a dimensionless, validated smoothness metric (less negative = smoother, more negative = jerkier).
- motion_entropy — normalised (0–1) Shannon entropy of the QoM magnitude distribution; the complexity/variedness of the motion.
- spectral descriptors of the QoM signal (Hann-windowed by default): the dominant frequency (Hz, the dominant periodicity of the motion) and the spectral centroid (Hz, the "centre of mass" of the motion spectrum).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
str
|
FFT window for the spectral descriptors — 'hann' (default, recommended to reduce leakage) or 'none' for a rectangular window. |
'hann'
|
entropy_bins
|
int
|
Number of histogram bins for the entropy estimate. Defaults to 50. |
50
|
fmin
|
float
|
Lowest frequency (Hz) considered for the dominant frequency and spectral centroid, excluding slow amplitude drift near DC. Defaults to 0.2. |
0.2
|
fmax
|
float
|
Highest frequency (Hz) considered for those spectral descriptors. Defaults to 10.0. |
10.0
|
save_data
|
bool
|
Save the descriptors to a data file. Defaults to True. |
True
|
save_plot
|
bool
|
Save the figure (QoM time series + power spectrum). Defaults to True. |
True
|
data_format
|
str
|
Data file format: 'csv', 'tsv' or 'txt'. Defaults to 'csv'. |
'csv'
|
target_name
|
str
|
Output image name. Defaults to None ( |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
'MgFigure | None'
|
MgFigure | None: figure whose |
'MgFigure | None'
|
( |
Source code in musicalgestures/_motiondescriptors.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
phase_synchrony ¶
phase_synchrony(fmin=0.5, fmax=4.0, fs=50.0, n_bins=36, dpi=300, autoshow=True, title=None, target_name=None, overwrite=True)
Quantify how phase-locked the motion is to the audio.
Both the audio onset-strength envelope and the quantity-of-motion envelope are
band-pass filtered to the tempo band [fmin, fmax] Hz, and their instantaneous phases
(via the Hilbert transform) are compared. The phase-locking value (PLV, 0–1) summarises the
consistency of the audio↔motion phase difference; a polar histogram shows its distribution.
Returns an MgFigure (metrics in .data), or None if the video has no audio.
Source code in musicalgestures/_audio_video.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
structure_comparison ¶
structure_comparison(n=200, dpi=300, cmap='magma', autoshow=True, title=None, target_name=None, overwrite=True)
Compare the temporal structure of the audio with that of the video.
Builds a self-similarity matrix (SSM) of the audio (from MFCC frames) and of the video
(from low-resolution frame appearance), resampled to the same n time points, and shows
them side by side with their absolute difference map — bright regions in the difference
are where the audio structure and the video structure diverge.
Returns an MgFigure (mean structural agreement in .data), or None if the video has no audio.
Source code in musicalgestures/_audio_video.py
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 | |
motion_audio_coupling ¶
motion_audio_coupling(dpi=300, cmap='coolwarm', dot_size=260, autoshow=True, title=None, target_name=None, overwrite=True, **pose_kwargs)
Map which body parts' speeds correlate most strongly with the music's onsets.
For every pose marker the per-frame speed is correlated with the audio onset-strength
envelope (sampled at the video frame rate). The result is shown as a body map — the average
pose with each marker coloured by its correlation — plus a sorted bar chart, and a CSV of the
per-marker correlations. Uses cached pose keypoints when available, otherwise runs pose()
first (**pose_kwargs are forwarded).
Returns an MgFigure (per-marker correlations in .data), or None if the video has no audio.
Source code in musicalgestures/_audio_video.py
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 | |
dynamics_coupling ¶
dynamics_coupling(fs=50.0, max_lag=2.0, dpi=300, autoshow=True, title=None, target_name=None, overwrite=True)
Compare the audio RMS level with the quantity of motion — does the dancer move more when the music is louder?
Aligns the audio RMS envelope with the quantity-of-motion envelope and reports their
correlation (at zero lag and at the best lag within max_lag seconds). The figure overlays
the two normalised envelopes and shows a scatter of RMS level vs. motion.
Returns an MgFigure (metrics in .data), or None if the video has no audio.
Source code in musicalgestures/_audio_video.py
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 | |
pose ¶
pose(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 motion 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 741 742 743 744 745 746 747 748 749 750 751 | |
pose_waterfall ¶
pose_waterfall(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:
| Type | Description |
|---|---|
'MgFigure | None'
|
MgFigure | None: the 3D waterfall figure, or None if there are too few frames. |
Source code in musicalgestures/_pose.py
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 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 | |
pose_segments ¶
pose_segments(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:
| Type | Description |
|---|---|
'MgFigure | None'
|
MgFigure | None: the grid of circular plots (per-segment stats in |
Source code in musicalgestures/_pose.py
1010 1011 1012 1013 1014 1015 1016 1017 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 | |
pose_center ¶
pose_center(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/motion — 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:
| Type | Description |
|---|---|
'MgFigure | None'
|
MgFigure | None: the centred-trajectories figure; |
'MgFigure | None'
|
coordinates and |
Source code in musicalgestures/_pose.py
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 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 1103 1104 1105 1106 1107 1108 1109 | |
pose_distance ¶
pose_distance(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:
| Type | Description |
|---|---|
'MgFigure | None'
|
MgFigure | None: |
'MgFigure | None'
|
|
Source code in musicalgestures/_pose.py
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
painting ¶
painting(reference_s=5.0, width=200, dpi=110, title=None, save_data=True, target_name=None, target_name_data=None, target_name_colourgram=None, overwrite=True)
Measure the painting in this video (the video should frame the canvas) and draw it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_s
|
float
|
Seconds at the start taken as the initial canvas. Defaults to 5. |
5.0
|
width
|
int
|
Working width in pixels. Defaults to 200. |
200
|
dpi
|
int
|
Figure resolution. |
110
|
title
|
str
|
Figure title. |
None
|
save_data
|
bool
|
Write the per-second table as CSV. Defaults to True. |
True
|
target_name
|
str
|
Figure path. Defaults to |
None
|
target_name_data
|
str
|
CSV path. Defaults to |
None
|
target_name_colourgram
|
str
|
Raw colourgram path. Defaults to |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
MgFigure
|
With the content dict in |
MgFigure
|
the colourgram as |
Source code in musicalgestures/_canvas.py
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 | |
eyetracking ¶
eyetracking(export_dir, start=0.0, blink_pad_frames=3, save_data=True, target_name=None, overwrite=True)
Align a Pupil Labs export to this video and keep the frame table on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
export_dir
|
str | Path
|
The Pupil Cloud export folder. |
required |
start
|
str | float
|
Where this video begins on the recording clock: an event
name from events.csv ( |
0.0
|
blink_pad_frames
|
int
|
See :func: |
3
|
save_data
|
bool
|
Write the table as CSV beside the video. Defaults to True. |
True
|
target_name
|
str
|
Output path. Defaults to |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: The frame table, also stored as |
DataFrame
|
recording as |
Source code in musicalgestures/_pupillabs.py
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 | |
gazegrams ¶
gazegrams(bins=120, bin_s=1.0, colormap='magma', target_name_x=None, target_name_y=None, overwrite=True)
Write the horizontal and vertical gazegrams of an aligned export as images.
Oriented like the motiongrams: the _ggy image has time across and vertical scene
position down; the _ggx image has time down and horizontal position across.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bins
|
int
|
Position bins. Defaults to 120. |
120
|
bin_s
|
float
|
Time bin in seconds. Defaults to 1.0. |
1.0
|
colormap
|
str
|
Matplotlib colormap. Defaults to |
'magma'
|
target_name_x
|
str
|
Path for the horizontal-position gazegram. |
None
|
target_name_y
|
str
|
Path for the vertical-position gazegram. |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgList |
MgList
|
|
MgList
|
and |
Source code in musicalgestures/_pupillabs.py
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 | |
eyetracking_timeline ¶
eyetracking_timeline(bin_s=1.0, dpi=120, title=None, target_name=None, overwrite=True)
Draw gaze velocity, event rates, pupil size and head rotation over the video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_s
|
float
|
Bin for the rates. Defaults to 1.0. |
1.0
|
dpi
|
int
|
Figure resolution. Defaults to 120. |
120
|
title
|
str
|
Figure title. Defaults to the video's name. |
None
|
target_name
|
str
|
Output path. Defaults to |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
MgFigure
|
With the per-bin table in |
MgFigure
|
|
Source code in musicalgestures/_pupillabs.py
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 | |
posegram ¶
posegram(landmarks=None, times=None, colormap='magma', gamma=0.5, max_width=4000, dpi=130, target_name=None, overwrite=True)
Draw the posegram: landmarks head to foot down the page, time across it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
None
|
times
|
array - like
|
Seconds per frame, needed whenever the landmarks were not sampled at the video's own frame rate. Pose is usually extracted at a reduced rate, so this is usually needed. |
None
|
colormap
|
str
|
Defaults to |
'magma'
|
gamma
|
float
|
Applied before colouring so quiet passages stay visible. Defaults to 0.5. |
0.5
|
max_width
|
int
|
Widest the drawn image may be. One column per frame makes a 149-megapixel picture of a long session; columns are pooled by maximum above this, so a brief accent still shows. Defaults to 4000. |
4000
|
dpi
|
int
|
Defaults to 130. |
130
|
target_name
|
str
|
Output path. Defaults to the input name with
|
None
|
overwrite
|
bool
|
Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'musicalgestures.MgFigure'
|
the posegram, with the activity array in |
Source code in musicalgestures/_posegram.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 | |
posegram_spatial ¶
posegram_spatial(landmarks=None, times=None, frame_size=None, axis='vertical', weight='speed', bins=200, colormap='magma', gamma=0.5, max_width=4000, dpi=130, target_name=None, overwrite=True)
The posegram drawn on the image's axes, so it lines up with a motiongram.
posegram() puts one landmark per row, which answers "which body part moved". This
puts image position on the vertical axis instead, which is what a motiongram does,
so a body crossing the frame draws the same diagonal in both and the two can be laid
against each other. Where they disagree, the pixels saw something the pose model did
not, or the other way round.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
None
|
times
|
array - like
|
Seconds per frame. Pose is usually extracted at a reduced rate, so this is usually needed. |
None
|
frame_size
|
tuple
|
|
None
|
axis
|
str
|
|
'vertical'
|
weight
|
str
|
|
'speed'
|
bins
|
int
|
Rows. Defaults to 200. |
200
|
colormap, gamma, max_width, dpi, target_name, overwrite
|
as |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'musicalgestures.MgFigure'
|
the gram, with the array in |
Source code in musicalgestures/_posegram.py
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 | |
posegrams ¶
posegrams(landmarks=None, times=None, frame_size=None, bins=200, weight='speed', colormap='magma', gamma=0.5, max_width=4000, dpi=130, target_name=None, overwrite=True)
Posegrams of where the body actually was, in the frame's own coordinates.
The pose counterpart of motiongrams(), and oriented the same way: the horizontal
view has time running across with image y down the page, the vertical view has time
running down with image x across. Laid around a video frame they line up with it, and
laid beside a motiongram of the same recording they can be read against it — a body
crossing the room draws the same diagonal in both.
Because pose gives an actual position rather than a region of changed pixels, these are the true location over time, not an estimate of where change happened.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
None
|
times
|
array - like
|
Seconds per frame; usually needed, since pose is normally extracted at a reduced rate. |
None
|
frame_size
|
tuple
|
|
None
|
bins
|
int
|
Cells along the spatial axis. Defaults to 200. |
200
|
weight
|
str
|
|
'speed'
|
colormap, gamma, max_width, dpi, target_name, overwrite
|
as elsewhere. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MgList |
'musicalgestures.MgList'
|
the horizontal and vertical posegrams, in that order. |
Source code in musicalgestures/_posegram.py
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 | |
__repr__ ¶
__repr__()
Source code in musicalgestures/_video.py
380 381 382 383 384 385 386 387 388 | |
average ¶
average(**kwargs)
Backward compatibility alias for blend(component_mode='average'). Creates an average image of all frames in the video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional arguments passed to blend method. Note: 'normalize' parameter is accepted for backward compatibility but ignored. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
A new MgImage pointing to the output average image file. |
Source code in musicalgestures/_video.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
test_input ¶
test_input()
Gives feedback to user if initialization from input went wrong.
Source code in musicalgestures/_video.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
get_video ¶
get_video()
Creates a video attribute to the Musical Gestures object with the given correct settings.
NB: For an MgVideo, self.length is the number of frames (from
get_framecount), whereas for MgAudio self.length is the duration in
seconds. To get the video duration in seconds use self.length / self.fps.
Source code in musicalgestures/_video.py
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 | |
numpy ¶
numpy()
Read all video frames into a numpy array using FFmpeg.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple |
Source code in musicalgestures/_video.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
from_numpy ¶
from_numpy(array, fps, target_name=None)
Writes a numpy array of video frames to a video file using FFmpeg.
After writing, updates self.filename, self.of, and self.fex to
reflect the actual output path so that subsequent operations on this object
refer to the newly created file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Video frames array with shape (N, H, W, 3) in BGR format. |
required |
fps
|
float
|
Frames per second for the output video. |
required |
target_name
|
str
|
Full path for the output file. If None, uses
|
None
|
Source code in musicalgestures/_video.py
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 | |
extract_frame ¶
extract_frame(**kwargs)
Extracts a frame from the video at a given time. see _utils.extract_frame for details.
Other Parameters:
| Name | Type | Description |
|---|---|---|
frame |
int
|
The frame number to extract. |
time |
str
|
The time in HH:MM:ss.ms where to extract the frame from. |
target_name |
str
|
The name for the output file. If None, the name will be FRAME. |
overwrite |
bool
|
Whether to allow overwriting existing files or to automatically increment target filename to avoid overwriting. Defaults to True. |
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
An MgImage object referring to the extracted frame. |
Source code in musicalgestures/_video.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |