Code Monkey home page Code Monkey logo

matplotvideo's Introduction

matplotvideo - syncing video and matplotlib

PyPI Latest Release Powered by PySport

What is it?

matplotvideo is a Python package providing an easy way to sync matplotlib plots to video. Some of the features:

  • Frame-accurate seeking forward and backward
  • Playback speed control between 0.01x and 4x
  • Auto frame-skip to maintain playback speed when plot takes to long
  • Seek with slider through entire video
  • Intuitive pause/play toggle using spacebar
  • Play all cv2 supported media types

Where to get it

The source code is currently hosted on GitHub at: https://github.com/PySport/matplotvideo

Installers for the latest released version are available at the Python package index.

# or PyPI
pip install matplotvideo

The package requires cv2 to be installed. When you don't have it installed yet, you can check out opencv-python.

Video player controls:

example

Sync between Scene Change data plot and video

  • 'a' 1 frame back
  • 'd' 1 frame forward
  • space toggle paused / play
  • esc quit video player
  • playback speed can be changed with the slider
  • playback position can be changed with the slider

Application examples

  • Verify data using video
  • Enrich video with additional data, like computer vision model output
  • Find interesting video/data frames

Usage

Import attach_video_player_to_figure and attach to matplotlib figure. You can pass additional keyword arguments to attach_video_player_to_figure that are passed to the on_frame callback on each invocation.

from matplotvideo import attach_video_player_to_figure
import matplotlib.pyplot as plt

# (timestamp, value) pairs

# sample: big bunny scene cuts
fancy_data = [
    (0, 1),
    (11.875, 1),
    (11.917, 2),
    (15.75, 2),
    (15.792, 3),
    (23.042, 3),
    (23.083, 4),
    (47.708, 4),
    (47.75, 5),
    (56.083, 5),
    (56.125, 6),
    (60, 6)
]


def on_frame(video_timestamp, line):
    timestamps, y = zip(*fancy_data)
    x = [timestamp - video_timestamp for timestamp in timestamps]

    line.set_data(x, y)
    line.axes.relim()
    line.axes.autoscale_view()
    line.axes.figure.canvas.draw()


def main():
    fig, ax = plt.subplots()
    plt.xlim(-15, 15)
    plt.axvline(x=0, color='k', linestyle='--')

    line, = ax.plot([], [], color='blue')

    attach_video_player_to_figure(fig, "BigBuckBunny.mp4", on_frame, line=line)

    plt.show()


main()

matplotvideo's People

Contributors

koenvo avatar koenvossen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

matplotvideo's Issues

The simple_example.py is crashing

Hello
I'm trying to get to know the library.
When I'm running the "simple example.py" a video appears for a second and then closed.
I'm using Python 3.8 with Pycharm and windows
Thanks a lot
Yochai

PyPI package not found

Hi,

I'm trying to install the package using pip but I get the following error:

ERROR: Could not find a version that satisfies the requirement matplotvideo (from versions: none)
ERROR: No matching distribution found for matplotvideo

Tried on macOS and Ubuntu 18.04.

Video Lagging/looks choppy, player controls don't work.

Hello,

Even when copying your example code and using the same video (the bunny video), the video runs in the player very laggy (even with playback speed at different speeds) and skips a lot of frames. The video player controls also don't work. Any idea as to how to fix either of these issues?

cv2 version incompatibility

I get the following error:
"AttributeError: module 'cv2' has no attribute 'cv2' "
at this line:
---> 44 self.__frame_count = int(self.__cap.get(cv2.cv2.CAP_PROP_FRAME_COUNT))
I assume it is due to an update of the cv2 package that causes it. Can it be fixed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.