Skip to content

Commit

Permalink
Add support for storing the rendered video in a video file
Browse files Browse the repository at this point in the history
Add example gif to README.md
  • Loading branch information
DarwinsBuddy committed Oct 12, 2023
1 parent 5eea091 commit 98ded4b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## foosball-ai
## foosball-ai
[![codecov](https://codecov.io/gh/DarwinsBuddy/foosball-ai/branch/main/graph/badge.svg?token=ACYNOG1WFW)](https://codecov.io/gh/DarwinsBuddy/foosball-ai)
[![Tests](https://github.com/DarwinsBuddy/foosball-ai/actions/workflows/test.yml/badge.svg)](https://github.com/DarwinsBuddy/foosball-ai/actions/workflows/test.yml)

![example gif of a tracked goal](https://github.com/DarwinsBuddy/foosball-ai/blob/main/misc/example.gif)

This software is designed to take a camera feed or a video file as an input of a match played
on a foosball table (🇦🇹 Wuzzler), track the ball and count goals.

Expand Down
1 change: 1 addition & 0 deletions foosball/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_argparse():
"If no file present fallback to 'yellow'")
ap.add_argument("-v", "--verbose", action='store_true', help="Verbose")
ap.add_argument("-o", "--off", action='store_true', help="Disable ai")
ap.add_argument("-out", "--output", default=None, help="path to store (optional) a rendered video")
ap.add_argument("-q", "--headless", action='store_true', help="Disable visualizations")
ap.add_argument("-b", "--buffer", type=int, default=16, help="max track buffer size")
ap.add_argument("-xp", "--xpad", type=int, default=50,
Expand Down
5 changes: 5 additions & 0 deletions foosball/tracking/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from queue import Empty

from imutils.video import FPS
from vidgear.gears import WriteGear

from . import Tracking, get_ball_config, get_goal_config
from .render import r_text, BLACK
Expand All @@ -28,6 +29,8 @@ def __init__(self, stream: Stream, dis, *args, **kwargs):
self.ball_config = get_ball_config(self.kwargs.get('ball'))
self.goals_config = get_goal_config()

self.output = None if kwargs.get('output') is None else WriteGear(kwargs.get('output'), logging=True)

if self.calibration is not None:
self.calibration_config = lambda: self.ball_config if self.calibration == 'ball' else self.goals_config
self.detection_frame = None
Expand Down Expand Up @@ -102,6 +105,8 @@ def step_frame():
if not self.headless:
self.render_fps(f, fps)
self.display.show(f)
if self.output is not None:
self.output.write(f)
if self.calibration is not None:
self.render_calibration()
if self.display.render(callbacks=callbacks):
Expand Down
Binary file added misc/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 98ded4b

Please sign in to comment.