From 59b0732c2f594c953ac079419d3bc17e9699a43d Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Mon, 12 Jul 2021 02:28:06 +1000 Subject: [PATCH] wip: --- average_map.py | 14 +++++++++----- cut_sync_race.py | 4 ++-- find_fastest.py | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/average_map.py b/average_map.py index a7a2757..1ea9e34 100644 --- a/average_map.py +++ b/average_map.py @@ -26,7 +26,7 @@ def main(output_file, videos, maxlen=900): subprocess.check_call([ 'ffmpeg', '-hide_banner', '-i', video, - '-r', '1', + '-r', '2', os.path.join(rowdir, 'frame%08d.png'), ]) for i, frame in enumerate(sorted(os.listdir(rowdir))): @@ -43,10 +43,14 @@ def main(output_file, videos, maxlen=900): #avg_color = (0, 0, 0) #count = 0 #for color in frame_im.getdata(): - # if color != [0,0,0]: + # if color != (0,0,0): # avg_color = tuple(a + b for a, b in zip(avg_color, color)) # count += 1 - #avg_color = tuple(a / count for a in avg_color) + #if count > 0: + # avg_color = tuple(a / count for a in avg_color) + #else: + # avg_color = (0, 0, 0) + #image.putpixel((i, row), tuple(avg_color)) ## true avg using numpy #avg_per_row = numpy.average(cv2.imread(filepath), axis=0) @@ -58,12 +62,12 @@ def main(output_file, videos, maxlen=900): non_black = im[im.sum(axis=2) != 0] avg = numpy.average(non_black, axis=0) try: - color = tuple(map(int, avg)) + # note numpy flips the RGB values to BGR for some reason, so flip back + color = tuple(map(int, avg))[::-1] except ValueError: # avg is NaN because all pixels black color = (0, 0, 0) image.putpixel((i, row), color) - #image.putpixel((i, row), tuple(avg_color)) rmtree(rowdir) diff --git a/cut_sync_race.py b/cut_sync_race.py index b00b429..ee213e2 100644 --- a/cut_sync_race.py +++ b/cut_sync_race.py @@ -142,8 +142,8 @@ def main(match_id, race_number, output_path, line for line in re.split('[\r\n]', err.strip()) if line.startswith('[blackdetect @ ') ] - if len(lines) == 1: - line, = lines + if len(lines) > 0: + line = lines[0] # take first black_end = line.split(' ')[4] assert black_end.startswith('black_end:') time_offset = float(black_end.split(':')[1]) diff --git a/find_fastest.py b/find_fastest.py index f99eeff..0769bb2 100644 --- a/find_fastest.py +++ b/find_fastest.py @@ -28,7 +28,7 @@ from uuid import uuid4 import argh import mysql.connector -def main(league, limit=144, +def main(league, limit=144, max_duration=3600.0, host='condor.live', user='necrobot-read', password='necrobot-read', database='condor_x2', ): logging.basicConfig(level=logging.INFO) @@ -50,9 +50,10 @@ def main(league, limit=144, JOIN race_runs ON (races.race_id = race_runs.race_id) WHERE race_runs.rank = 1 AND match_info.league_tag = %(league)s + AND race_runs.time < %(max_duration)s ORDER BY race_runs.time ASC LIMIT %(limit)s - """, {'limit': limit, 'league': league}) + """, {'limit': limit, 'league': league, 'max_duration': int(max_duration * 100)}) data = cur.fetchall() data = [