From dc5e2ff28cf73dd91c85917a44ac14ee74b7f06c Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Wed, 18 Dec 2024 15:24:42 +0100 Subject: [PATCH] change render switches --- trap/animation_renderer.py | 1 + trap/config.py | 4 +- trap/cv_renderer.py | 2 +- trap/plumber.py | 20 +++++----- trap/preview_renderer.py | 78 +++++++++++++++++++------------------- 5 files changed, 54 insertions(+), 51 deletions(-) diff --git a/trap/animation_renderer.py b/trap/animation_renderer.py index 0a8c6f1..1510e91 100644 --- a/trap/animation_renderer.py +++ b/trap/animation_renderer.py @@ -79,6 +79,7 @@ class AnimationRenderer: display = pyglet.canvas.get_display() screen = display.get_screens()[0] + print(display.get_screens()) if self.streaming_process is not None: self.window = pyglet.window.Window(width=self.frame_size[0], height=self.frame_size[1], config=config, fullscreen=False, screen=screen) diff --git a/trap/config.py b/trap/config.py index ac97fa6..ceecd4f 100644 --- a/trap/config.py +++ b/trap/config.py @@ -336,8 +336,8 @@ render_parser.add_argument("--render-file", render_parser.add_argument("--render-window", help="Render a previewing to a window", action='store_true') -render_parser.add_argument("--render-no-preview", - help="No preview, but only animation", +render_parser.add_argument("--render-animation", + help="Render animation (pyglet)", action='store_true') render_parser.add_argument("--render-debug-shapes", help="Lines and points for debugging/mapping", diff --git a/trap/cv_renderer.py b/trap/cv_renderer.py index 975a799..a805d67 100644 --- a/trap/cv_renderer.py +++ b/trap/cv_renderer.py @@ -442,7 +442,7 @@ colorset = [ # ] def get_opacity(track: Track, current_frame: Frame): - fade_duration = current_frame.camera.fps * 3 + fade_duration = current_frame.camera.fps * 1.5 diff = current_frame.index - track.history[-1].frame_nr return max(0, 1 - diff / fade_duration) # track.history[-1].frame_nr < (current_frame.index - current_frame.camera.fps * 3) diff --git a/trap/plumber.py b/trap/plumber.py index 71a00a3..07034d2 100644 --- a/trap/plumber.py +++ b/trap/plumber.py @@ -92,16 +92,16 @@ def start(): ExceptionHandlingProcess(target=run_tracker, kwargs={'config': args, 'is_running': isRunning}, name='tracker'), ] - if args.render_file or args.render_url or args.render_window: - if not args.render_no_preview: #or args.render_file or args.render_url: - procs.append( - # ExceptionHandlingProcess(target=run_cv_renderer, kwargs={'config': args, 'is_running': isRunning}, name='preview') - ExceptionHandlingProcess(target=run_cv_renderer, kwargs={'config': args, 'is_running': isRunning}, name='preview') - ) - if args.render_no_preview: - procs.append( - ExceptionHandlingProcess(target=run_animation_renderer, kwargs={'config': args, 'is_running': isRunning}, name='renderer') - ) + # if args.render_file or args.render_url or args.render_window: + if args.render_window or args.render_file or args.render_url: + procs.append( + # ExceptionHandlingProcess(target=run_cv_renderer, kwargs={'config': args, 'is_running': isRunning}, name='preview') + ExceptionHandlingProcess(target=run_cv_renderer, kwargs={'config': args, 'is_running': isRunning}, name='preview') + ) + if args.render_animation: + procs.append( + ExceptionHandlingProcess(target=run_animation_renderer, kwargs={'config': args, 'is_running': isRunning}, name='renderer') + ) if not args.bypass_prediction: procs.append( diff --git a/trap/preview_renderer.py b/trap/preview_renderer.py index 1aa52af..c59de72 100644 --- a/trap/preview_renderer.py +++ b/trap/preview_renderer.py @@ -185,28 +185,29 @@ class DrawnTrack: self.shapes = self.shapes[:len(drawn_positions)] # for i, pos in drawn_positions.enumerate(): - for ci in range(1, len(drawn_positions)): - x, y = [int(p) for p in drawn_positions[ci-1]] - x2, y2 = [int(p) for p in drawn_positions[ci]] + if True: + for ci in range(1, len(drawn_positions)): + x, y = [int(p) for p in drawn_positions[ci-1]] + x2, y2 = [int(p) for p in drawn_positions[ci]] - y, y2 = self.renderer.window.height - y, self.renderer.window.height - y2 - color = [100+155*ci // len(drawn_positions)]*3 - # print(x,y,x2,y2,color) + y, y2 = self.renderer.window.height - y, self.renderer.window.height - y2 + color = [100+155*ci // len(drawn_positions)]*3 + # print(x,y,x2,y2,color) - if ci >= len(self.shapes): - # TODO: add color2 - line = self.renderer.gradientLine(x, y, x2, y2, 3, color, color, batch=self.renderer.batch_anim) - line = pyglet.shapes.Arc(x2, y2, 10, thickness=2, color=color, batch=self.renderer.batch_anim) - line.opacity = 20 - self.shapes.append(line) - - else: - line = self.shapes[ci-1] - line.x, line.y = x, y - line.x2, line.y2 = x2, y2 - line.radius = int(exponentialDecay(line.radius, 1.5, 3, dt)) - line.color = color - line.opacity = int(exponentialDecay(line.opacity, 180, 8, dt)) + if ci >= len(self.shapes): + # TODO: add color2 + # line = self.renderer.gradientLine(x, y, x2, y2, 3, color, color, batch=self.renderer.batch_anim) + line = pyglet.shapes.Arc(x2, y2, 10, thickness=2, color=color, batch=self.renderer.batch_anim) + line.opacity = 20 + self.shapes.append(line) + + else: + line = self.shapes[ci-1] + line.x, line.y = x, y + # line.x2, line.y2 = x2, y2 + line.radius = int(exponentialDecay(line.radius, 1.5, 3, dt)) + line.color = color + line.opacity = int(exponentialDecay(line.opacity, 180, 8, dt)) # TODO: basically a duplication of the above, do this smarter? # TODO: add intermediate segment @@ -216,26 +217,27 @@ class DrawnTrack: self.pred_history_shapes = self.pred_history_shapes[:len(drawn_pred_history)] # for i, pos in drawn_pred_history.enumerate(): - for ci in range(1, len(drawn_pred_history)): - x, y = [int(p) for p in drawn_pred_history[ci-1]] - x2, y2 = [int(p) for p in drawn_pred_history[ci]] + if False: + for ci in range(1, len(drawn_pred_history)): + x, y = [int(p) for p in drawn_pred_history[ci-1]] + x2, y2 = [int(p) for p in drawn_pred_history[ci]] - y, y2 = self.renderer.window.height - y, self.renderer.window.height - y2 + y, y2 = self.renderer.window.height - y, self.renderer.window.height - y2 - if ci >= len(self.pred_history_shapes): - # line = self.renderer.gradientLine(x, y, x2, y2, 3, color, color, batch=self.renderer.batch_anim) - line = pyglet.shapes.Line(x,y ,x2, y2, 2.5, color, batch=self.renderer.batch_anim) - # line = pyglet.shapes.Arc(x2, y2, 10, thickness=2, color=color, batch=self.renderer.batch_anim) - line.opacity = 120 - self.pred_history_shapes.append(line) - - else: - line = self.pred_history_shapes[ci-1] - line.x, line.y = x, y - line.x2, line.y2 = x2, y2 - # line.radius = int(exponentialDecay(line.radius, 1.5, 3, dt)) - line.color = color - line.opacity = int(exponentialDecay(line.opacity, 180, 8, dt)) + if ci >= len(self.pred_history_shapes): + # line = self.renderer.gradientLine(x, y, x2, y2, 3, color, color, batch=self.renderer.batch_anim) + line = pyglet.shapes.Line(x,y ,x2, y2, 2.5, color, batch=self.renderer.batch_anim) + # line = pyglet.shapes.Arc(x2, y2, 10, thickness=2, color=color, batch=self.renderer.batch_anim) + line.opacity = 120 + self.pred_history_shapes.append(line) + + else: + line = self.pred_history_shapes[ci-1] + line.x, line.y = x, y + line.x2, line.y2 = x2, y2 + # line.radius = int(exponentialDecay(line.radius, 1.5, 3, dt)) + line.color = color + line.opacity = int(exponentialDecay(line.opacity, 180, 8, dt)) for a, drawn_prediction in enumerate(drawn_predictions):