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
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 | |
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 ¶
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, horizontal and vertical 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 vertical motiongram. 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 horizontal motiongram. 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 | |
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 vertical motiongram. 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 horizontal motiongram. 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
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 | |
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 |
|---|---|
'list'
|
str/list: The path(s) to the rendered data file(s). |
Source code in musicalgestures/_motionvideo.py
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 | |
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
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 | |
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
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 | |
motionscore ¶
motionscore()
Computes the average VMAF motion score of the video using FFmpeg.
Returns:
| Name | Type | Description |
|---|---|---|
float |
'float'
|
The average VMAF motion score, or None if unavailable. |
Source code in musicalgestures/_motionvideo.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 | |
motion_mp ¶
motion_mp(filtertype='Regular', threshold=0.05, blur='None', kernel_size=5, inverted_motionvideo=False, inverted_motiongram=False, unit='seconds', equalize_motiongram=True, 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, convert=True, overwrite=True, num_processes=-1)
Source code in musicalgestures/_motionvideo_mp_run.py
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 | |
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:
| Name | Type | Description |
|---|---|---|
'MgList | MgImage'
|
if features='motiongrams':¶ |
|
MgList |
'MgList | MgImage'
|
An MgList pointing to the output SSM images (as MgImages). |
'MgList | MgImage'
|
else:¶ |
|
MgImage |
'MgList | MgImage'
|
An MgImage to the output SSM. |
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 | |
videograms ¶
videograms(target_name_x=None, target_name_y=None, overwrite=True)
Renders horizontal and vertical videograms of the source video using ffmpeg. Averages videoframes by axes, and creates two images of the horizontal-axis and vertical-axis stacks. In these stacks, a single row or column corresponds to a frame from the source video, and the index of the row or column corresponds to the index of the source frame.
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
|
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 | |
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_audiovisual_beats ¶
warp_audiovisual_beats(audio_file, speed=(0.5, 2), data=None, filtertype='Adaptative', threshold=0.05, kernel_size=5, target_name=None, overwrite=True)
Warp audio beats with visual beats (patterns of motion that can be shifted in time to control visual rhythm). 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 audiovisual 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 | |
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
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 | |
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
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 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 | |
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 | |
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 | |
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
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 52 53 54 55 56 57 58 59 60 61 62 63 | |
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
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 | |
motiontempo ¶
motiontempo(fmin=0.2, fmax=8.0, dpi=300, autoshow=True, title=None, target_name=None, overwrite=True)
Estimates the dominant movement 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 movement tempo (e.g. step rate of a dancer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmin
|
float
|
Lowest movement frequency to consider (Hz). Defaults to 0.2. |
0.2
|
fmax
|
float
|
Highest movement 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
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 | |
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 | |
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)
Renders a stroboscope / chronophotography image: the person's silhouette at evenly sampled times composited onto a single frame, showing the body moving through space over time (Muybridge-style).
For a clean result with a single person on a static background, raise threshold and
set keep_largest=True so only the person's blob is composited (avoids the image
"blowing up" from background noise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Number of time samples (silhouettes) to composite. Defaults to 12. |
12
|
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
|
colorize
|
bool
|
Tint each silhouette by time (early→late) for a temporal cue. Defaults to True. |
True
|
background
|
str
|
'average' (clean plate), 'first' (first frame), 'black' or 'white'. Defaults to 'average'. |
'average'
|
target_name
|
str
|
Output name. Defaults to None ("_stroboscope.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
the stroboscope image. |
Source code in musicalgestures/_spacetime.py
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 | |
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
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 | |
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
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 | |
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
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 | |
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 movement.
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 rhythm 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 movement-onset rate to consider (Hz), 'motion' only. Defaults to 0.2. |
0.2
|
fmax
|
float
|
Highest movement-onset rate to consider (Hz), 'motion' only. Defaults to 8.0. |
8.0
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
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/rhythm with the movement tempo/rhythm and report how similar they are.
Estimates the tempo of the audio track (from its onset-strength envelope) and of the movement (from the quantity-of-motion envelope), then aligns the two normalised envelopes and cross-correlates them to measure rhythmic agreement. The figure shows the two envelopes overlaid and their cross-correlation; the report (also saved as a CSV) lists the audio tempo, movement tempo, their ratio and nearest harmonic relationship, the peak cross-correlation, and the lag (s) at which the movement 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'
|
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 318 | |
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 movement 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 movement.
- 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 main movement-rhythm rate) and the spectral centroid (Hz, the "centre of mass" of the movement 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:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
figure whose |
'MgFigure'
|
( |
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 movement is to the audio rhythm.
Both the audio onset-strength envelope and the movement 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↔movement 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
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 | |
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 movement.
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 musical structure and the movement 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
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 | |
body_audio_coupling ¶
body_audio_coupling(dpi=300, cmap='coolwarm', dot_size=260, autoshow=True, title=None, target_name=None, overwrite=True, **pose_kwargs)
Map which body parts are most rhythmically coupled to the music.
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
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 | |
dynamics_coupling ¶
dynamics_coupling(fs=50.0, max_lag=2.0, dpi=300, autoshow=True, title=None, target_name=None, overwrite=True)
Compare audio loudness with movement quantity — does the dancer move more when the music is louder?
Aligns the audio RMS-loudness 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 loudness vs. motion.
Returns an MgFigure (metrics in .data), or None if the video has no audio.
Source code in musicalgestures/_audio_video.py
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 | |
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 movement frequency (Hz). A CSV of the per-marker statistics is saved alongside it. Defaults to True. |
True
|
save_trajectories
|
bool
|
Whether to also render an image of every marker's spatial trajectory across the whole video. Defaults to True. |
True
|
trajectory_labels
|
bool
|
Whether to annotate the trajectories image with each marker's name. Defaults to False (cleaner image). |
False
|
trajectory_background
|
str
|
Background of the trajectories PNG: |
None
|
target_name_data
|
str
|
Target output name for the data. Defaults to None (which assumes that the input filename with the suffix "_pose" should be used). |
None
|
target_name_average
|
str
|
Target output name for the average-pose image. Defaults to None (input filename with the suffix "_pose_average.png"). |
None
|
target_name_trajectories
|
str
|
Target output name for the trajectories image. Defaults to None (input filename with the suffix "_pose_trajectories.png"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgVideo |
'musicalgestures.MgVideo'
|
An MgVideo pointing to the output video. The average-pose and trajectories images
(when rendered) are attached as |
Source code in musicalgestures/_pose.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
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:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the 3D waterfall figure, or None if there are too few frames. |
Source code in musicalgestures/_pose.py
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 | |
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:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the grid of circular plots (per-segment stats in |
Source code in musicalgestures/_pose.py
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | |
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/movement — useful before comparing or further analysing trajectories. Plots the centred
marker trajectories and (by default) saves a CSV of the centred coordinates. Uses cached pose
keypoints when available, otherwise runs pose() first (**pose_kwargs are forwarded).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_data
|
bool
|
Save a CSV of the centred coordinates. Defaults to True. |
True
|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
target_name
|
str
|
Output name. Defaults to None ("_pose_centered.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
**pose_kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the centred-trajectories figure; |
'MgFigure'
|
coordinates and |
Source code in musicalgestures/_pose.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 | |
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:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
|
'MgFigure'
|
|
Source code in musicalgestures/_pose.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
__repr__ ¶
__repr__()
Source code in musicalgestures/_video.py
190 191 192 193 194 195 196 197 198 | |
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
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
test_input ¶
test_input()
Gives feedback to user if initialization from input went wrong.
Source code in musicalgestures/_video.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
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
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 | |
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
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
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
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 | |
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
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |