-
Notifications
You must be signed in to change notification settings - Fork 11
8 ‐ Chaining
A simple workflow for using the Musical Gestures Toolbox can be the following:
-
- Creating an MgVideo which loads a video file and optionally applies some preprocessing to it.
-
- Calling a process on the MgVideo.
-
- Viewing the result.
Something like this:
source = musicalgestures.MgVideo('/path/to/source/video.avi', starttime=5, endtime=15, skip=3) # load video, apply preprocessing
source.motion() # call a process on it
source.show(key='motion') # view the result
This is convenient if you want to apply several different processes on the same input video.
source = musicalgestures.MgVideo('/path/to/source/video.avi', starttime=5, endtime=15, skip=3) # load and preprocess video
source.motion() # render a motion video from the source video
source.history() # render a history video from the source video
source.average() # render an average image from the source video
The Musical Gestures Toolbox also offers an alternative workflow in case you want to apply a process on the result of a previous process. Although show()
is not really a process (ie. it does not yield a file as a result) it can provide a good example of the use of chaining:
# this...
source.motion().show()
# ...is the equivalent of this!
source.motion()
source.show(key='motion')
It also works with images:
source.average().show()
But chaining can go further than this. How about reading (and preprocessing) a video, rendering its motion video, the motion history and the average of the motion history, with showing the _motion_history_average.png at the end - all as a one-liner?!
musicalgestures.MgVideo('/path/to/source/video.avi', skip=4, crop='auto').motion().history().average().show()
# equivalent without chaining
source = musicalgestures.MgVideo('/path/to/source/video.avi', skip=4, crop='auto')
motionvideo = source.motion()
motionhistory = motionvideo.history()
motionhistory.average()
motionhistory.show(key='average')
# rendering and viewing the motion video
musicalgestures.MgVideo('/path/to/source/video.avi', skip=4).motion().show()
# rendering the motion video, the motion history video, and viewing the latter
musicalgestures.MgVideo('/path/to/source/video.avi', skip=3).motion().history(normalize=True).show()
# rendering the motion video, the motion average image, and viewing the latter
musicalgestures.MgVideo('/path/to/source/video.avi', skip=15).motion().average().show()
A project from the fourMs Lab, RITMO Centre for Interdisciplinary Studies in Rhythm, Time and Motion, Department of Musicology, University of Oslo.