You know that effect in some videos where objects moving in the scene leave a trail of their old position?

It is usually called “echo effect” or “trail effect” or “motion trail”, some examples of it are:







Effects like this are normally created in post-production: isolating in some way the objects which will leave the trail, most of the time recording with a green-screen, and then messing around with frames.

However, since I am too lazy to be an artist, I tried to re-create it automatically and in real-time using some computer vision to isolate the moving objects.

opencv_trail_effect is an experiment using OpenCV to draw a trail after performing foreground segmentation.

Segmentation in opencv_trail_effect can done using either thresholding or background subtraction.

A few conditions are required to create a decent effect:

the camera should not move; the lighting in the scene should be quite stable (when doing background subtraction it is recommended to disable auto-gain in the camera, and avoid any artifact introduced by the power line frequency); the subject should enter the scene only after the background learning phase has finished, i.e. after opencv_trail_effect has shown the preview window.

Examples of use

The effect in “Blame It On The Boogie” could be described as a short faded trail and can be achieved with this command line:

$ ./opencv_trail_effect -l 12 -s background -d fadeaccumulate

The effect in “WTF?” is equivalent to an infinite trail in which the isolated foreground is copied on the background and stays there, it can be achieved with this command line:

$ ./opencv_trail_effect -l -1 -s background -d copy

The effect in “L'Anima Vola” seems to have a “catch-up” behavior; that one can be done by drawing the trail in reverse, with this command line:

$ ./opencv_trail_effect -l 30 -s background -d copy -r

Another effect seen in movies can be obtained by doing the average of the frames in the trail, possibly with the most recent frame drawn on top:

$ ./opencv_trail_effect -l 10 -s background -d average -B

Here is a video showing the examples from above:

I am thinking about making this effect more widely available in open source video frameworks, like GStreamer, maybe via frei0r which GStreamer can already use.

I see that there is already a Light Graffiti effect in frei0r and the trail effect can be seen as a generalization of it, so maybe some code can be shared.

Any suggestion, or help, is welcome.

Side note

These effects can bring to mind other cool effects in music videos, like the frame shuffling effect in Peter Gabriel - Sledgehammer, that one can be done with the nervousTV plugin from effectv or frei0r, for example via GStreamer with:

$ gst-launch-1.0 -v v4l2src ! videoconvert ! frei0r-filter-nervous ! videoconvert ! autovideosink

Which could be fun to use in video calls too, but this is another story.