-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sitzmann
committed
Jan 25, 2022
1 parent
4a1410b
commit 2bbf863
Showing
45 changed files
with
579 additions
and
266 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# coding=utf-8 | ||
# directories | ||
input_images_dir = 'input_images/' | ||
media_out_dir = 'media_out/' | ||
data_dir = 'data/' | ||
reference_digits_dir = data_dir + 'reference_digits/' | ||
|
||
# dimensions | ||
resize_factor = 20 | ||
field_height_m, field_width_m = 100, 37 # dimensions of an actual field, not the tactics board | ||
resolution_x, resolution_y = 1920, 1080 | ||
max_num_windows = 5 | ||
digit_target_size = 28 | ||
|
||
# | ||
min_intensity, max_intensity = 0, 255 | ||
ksize_sharpening = 0.8 | ||
ksize_blur_thresholded = 3 | ||
|
||
# field detection | ||
ksize_initial_blur = 15 | ||
field_detection_poly_epsilon = 150 | ||
|
||
radius_players_cm = 1 | ||
player_radius_lb, player_radius_ub = 0.75, 0.9 | ||
|
||
# digits | ||
font_size = 0.15 * resize_factor |
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import cairo | ||
import cv2 | ||
import numpy as np | ||
from typing import Optional | ||
import export_scene | ||
import os | ||
import shutil | ||
import state | ||
import cfg | ||
|
||
|
||
def main(): | ||
init_context() | ||
draw_field() | ||
draw_player(10, 0) | ||
show(surface) | ||
|
||
|
||
def draw_scene(state: state.State): | ||
init_context() | ||
draw_field() | ||
[draw_player(player, (0.6, 0, 0)) for player in state.players_team_1] | ||
[draw_player(player, (0, 0, 0.6)) for player in state.players_team_2] | ||
return surface | ||
|
||
|
||
def animate_scene(state_1, state_2, num_steps, name='animation'): | ||
output_path = f'{cfg.media_out_dir}{name}' | ||
shutil.rmtree(output_path, ignore_errors=True) | ||
os.makedirs(output_path, exist_ok=True) | ||
for i, frac in enumerate(np.linspace(0, 1, num_steps)): | ||
state = state_1 * (1 - frac) + state_2 * frac | ||
surface = draw_scene(state) | ||
path = f'{output_path}/{i:04d}.png' | ||
surface.write_to_png(path) | ||
export_scene.save_video(output_path, fps=10) | ||
shutil.rmtree(output_path) | ||
|
||
|
||
# globals | ||
width, height, endzone_height = 37, 100, 18 | ||
border = 3 | ||
scale = 8 | ||
ctx: Optional[cairo.Context] = None | ||
surface: Optional[cairo.ImageSurface] = None | ||
|
||
|
||
def draw_field(): | ||
draw_background() | ||
ctx.move_to(*m2p([border, border])) | ||
select_line_brush() | ||
path = [[width, 0], [0, height], [-width, 0], [0, -height]] | ||
for line in path: | ||
rel_line(*line) | ||
for y in [endzone_height, height - endzone_height]: | ||
move_to(0, y) | ||
rel_line(width, 0) | ||
ctx.stroke() | ||
|
||
|
||
def draw_background(): | ||
ctx.set_source_rgb(0.3, 0.5, 0.3) | ||
ctx.move_to(*m2p([0, 0])) | ||
w = width + 2 * border | ||
h = height + 2 * border | ||
path = [[w, 0], [0, h], [-w, 0], [0, -h]] | ||
for line in path: | ||
rel_line(*line) | ||
ctx.fill() | ||
|
||
@np.vectorize | ||
def m2p(x, rounded=True): | ||
x = scale * x | ||
if rounded: | ||
x = int(x) | ||
return x | ||
|
||
|
||
def move_to(x, y): | ||
ctx.move_to(*m2p([border + x, border + y])) | ||
|
||
|
||
def rel_line(x, y): | ||
ctx.rel_line_to(*m2p([x, y])) | ||
|
||
|
||
def show(surface, filename='temp', wait=10): | ||
os.makedirs(cfg.media_out_dir, exist_ok=True) | ||
path = f'{cfg.media_out_dir}/{filename}.png' | ||
surface.write_to_png(path) | ||
cv2.imshow(filename, cv2.imread(path)) | ||
window_x = cfg.resolution_x - 50 - m2p(width + 2*border) | ||
cv2.moveWindow(filename, window_x, 0) | ||
cv2.waitKey(wait) | ||
|
||
|
||
def select_line_brush(): | ||
ctx.set_source_rgb(0.7, 0.7, 0.7) # Solid color | ||
ctx.set_line_width(m2p(0.3)) | ||
|
||
|
||
def init_context(): | ||
global ctx, surface | ||
size_meters = np.array([width + 2 * border, height + 2 * border]) | ||
size_pixels = m2p(size_meters / 2, rounded=True) * 2 | ||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, *size_pixels) | ||
ctx = cairo.Context(surface) | ||
|
||
|
||
def draw_player(player: state.Player, color): | ||
ctx.set_line_width(0) | ||
ctx.set_source_rgb(*color) | ||
radius = m2p(1, rounded=False) | ||
move_to(*player.pos) | ||
ctx.arc(*ctx.get_current_point(), radius, 0, 2 * np.pi) | ||
ctx.fill() | ||
ctx.set_source_rgb(0.8, 0.8, 0.8) | ||
ctx.select_font_face("Serif", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) | ||
ctx.set_font_size(m2p(2)) | ||
pos = [m2p(player.pos[0] + border), m2p(player.pos[1] + border)] | ||
text(player.label, pos, player.orientation) | ||
|
||
|
||
def text(string, pos, orientation): | ||
ctx.save() | ||
fascent, fdescent, fheight, fxadvance, fyadvance = ctx.font_extents() | ||
x_off, y_off, tw, th = ctx.text_extents(string)[:4] | ||
nx = -tw/2 | ||
ny = fheight/2 | ||
ctx.translate(pos[0], pos[1]) | ||
ctx.rotate(orientation / -180 * np.pi) | ||
ctx.translate(nx, ny) | ||
ctx.move_to(0, -4) | ||
ctx.show_text(string) | ||
ctx.restore() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import moviepy.video.io.ImageSequenceClip | ||
from glob import glob | ||
|
||
|
||
def save_video(img_folder, fps=30): | ||
image_files = sorted(glob(f'{img_folder}/*.png')) | ||
clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(image_files, fps=fps) | ||
clip.write_videofile(f'{img_folder}.mp4') | ||
|
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import scan | ||
import drawer | ||
images_dir = 'input_images/' | ||
|
||
|
||
def main(): | ||
for image_path in [images_dir + 'ho-stack-1.jpg', images_dir + 'ho-stack-2.jpg']: | ||
# image_path = images_dir + 'disc.jpg' | ||
show_digits = False | ||
show_circles = True | ||
record_examples = False | ||
player_positions = scan.scan(image_path, show_digits, show_circles, record_examples) | ||
surface = drawer.draw_scene(player_positions) | ||
drawer.show(surface, wait=0) | ||
|
||
|
||
def animate(): | ||
img_1, img_2 = images_dir + 'ho-stack-1.jpg', images_dir + 'ho-stack-2.jpg' | ||
show_circles = False | ||
show_digits = False | ||
state_1 = scan.scan(img_1, show_digits, show_circles) | ||
state_2 = scan.scan(img_2, show_digits, show_circles) | ||
drawer.animate_scene(state_1, state_2, 30) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
# animate() |
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.