Lightweight image sequence visualization utility based on matplotlib
Enter
to toggle pause, :arrow_right: to next frame, :arrow_left: to previous frame, etcpip install videofig
Note that the FPS is low in the gif since saving images takes time. Without saving images (by setting SAVE_PLOTS = False
in example scripts), the FPS is about 35.
To generate these gifs, follow these steps:
SAVE_PLOTS
to True
in respective example scriptspython example1.py
ffmpeg -ss 0 -i example1_save/%04d.jpg -vf "setpts=1.0*PTS,fps=25,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 example1_save.gif
Python is an elegant programming language with rich add-on libraries to meet various needs. For scientific computation, it has numpy
; for plotting, it has matplotlib
. Personally, I use Python for video analysis and it works like a charm except for one thing: visualize image sequences for detailed inspection.
When visualizing image sequences for detailed inspection, it is desirable to have play
, pause
, forward by one frame
, backward by one frame
, etc utilities. Moreover, we may add some custom plots(bounding box, for example) and graphics on top. In Matlab, we have VideoPlayer
in Computer Vision System Toolbox
, but to the best of my knowledge, there isn't any tools in Python that provides similar functionality. Let me know, if there are any : )
Accidentally, I came across the excellent script of João Filipe Henriques, which provides utilities for detailed image sequence inspection before VideoPlayer
is available in Matlab. Inspired by this, I decided to write a similar function in Python before more sophisticated tools come out.
This tool is specifically designed to be minimal, lightweight and readable such that anyone can easily modify it to suit different needs. The only dependency is Matplotlib
. I have tested it in Python 2.7, but it should also work in Python 3.5.
videofig(NUM_FRAMES, REDRAW_FUNC)
Creates a figure with a horizontal scrollbar and shortcuts to scroll automatically. The scroll range is 0 to NUM_FRAMES - 1. The function REDRAW_FUN(F, AXES) is called to redraw at scroll position F (for example, REDRAW_FUNC can show the frame F of a video) using AXES for drawing. F is an integer, AXES is a instance of Axes class
This can be used not only to play and analyze standard videos, but it also lets you place any custom Matplotlib plots and graphics on top.
The keyboard shortcuts are:
Please see example scripts on how to achieve more advanced effects.