diff --git a/moonwalk.py b/moonwalk.py index 9c6194b..0f4660c 100644 --- a/moonwalk.py +++ b/moonwalk.py @@ -36,6 +36,16 @@ colorset = [(0, 0, 0), ] +walk_image = pyglet.image.load('walk.jpg') # TODO investigaet pyglet.resource: https://pyglet.readthedocs.io/en/latest/programming_guide/image.html#displaying-images +image_grid = pyglet.image.ImageGrid(walk_image, rows=1, columns=4) +# texture_grid = image_grid.get_texture_sequence() +walk_animation = image_grid.get_animation(period=.2) +walk_animation_dim = { + 'y': walk_animation.get_max_height(), + 'x': walk_animation.get_max_width() +} +sprite = pyglet.sprite.Sprite(img=walk_animation) + @dataclass class Params: @@ -46,6 +56,7 @@ class Params: emitter_speed: float = 4 # objects per second object_velocity: float = 80 # pixels/second velocity_decay: float = 1 # make system a bit springy + iou_threshold: float = 0 # SORT Intersection over union def add_listener(self, attr: str, callback: callable): """ @@ -91,7 +102,11 @@ class DetectedObject: self.h = 20 # height self.t = (self.canvas.height - self.h)/2 # top - self.shape = pyglet.shapes.Rectangle(self.l, self.t, self.w, self.h, color=(255, 22, 20), batch=self.canvas.batch_figures) + # self.shape = pyglet.shapes.Rectangle(self.l, self.t, self.w, self.h, color=(255, 22, 20), batch=self.canvas.batch_figures) + + self.shape = pyglet.sprite.Sprite(img=walk_animation,x=self.l, y=self.t, batch=self.canvas.batch_figures) + self.shape.scale_x = self.w/walk_animation_dim['x'] + self.shape.scale_y = self.h/walk_animation_dim['y'] # rectangle.opacity = 128 # rectangle.rotation = 33 #TODO renderer @@ -166,6 +181,7 @@ class Canvas: # Purple background color: # pyglet.gl.glClearColor(*AnimConfig.clear_color) + self.draw_stats = True self.fps_display = pyglet.window.FPSDisplay(window=self.window, color=(255,255,255,255)) self.fps_display.label.x = self.window.width - 150 self.fps_display.label.y = self.window.height - 17 @@ -194,6 +210,7 @@ class Canvas: self.interval_items: list[pyglet.clock._ScheduledIntervalItem] = [i for i in pyglet.clock._default._schedule_interval_items if i.func == self.on_track] self.params.add_listener('tracker_fps', self.on_tracker_fps_change) + self.params.add_listener('iou_threshold', self.on_iou_threshold_change) def getTrackBboxShapes(self, track_id): color = colorset[int(track_id) % len(colorset)] @@ -210,6 +227,12 @@ class Canvas: for ii in self.interval_items: ii.interval = 1/new_value logger.debug(f"Set tracker interval to {ii.interval}") + + def on_iou_threshold_change(self, field, old_value, new_value): + """ + Param dataclass listener for changes to iou_threshold + """ + self.tracker.iou_threshold = new_value def run(self): @@ -224,7 +247,8 @@ class Canvas: self.batch_figures.draw() self.batch_bounding_boxes.draw() self.batch_info.draw() - self.fps_display.draw() + if self.draw_stats: + self.fps_display.draw() def on_close(self): logger.info('closing') @@ -240,6 +264,9 @@ class Canvas: level = logging.INFO if logger.getEffectiveLevel() == logging.DEBUG else logging.DEBUG logger.setLevel(level) logger.info(f"set log level: {level}") + if symbol == pyglet.window.key.S: + self.draw_stats = not self.draw_stats + logger.info(f"rendering stats: {self.draw_stats}") if symbol == pyglet.window.key.UP: logger.debug('up') self.params.object_velocity += (10 if pyglet.window.key.MOD_SHIFT & modifiers else 1) @@ -255,6 +282,12 @@ class Canvas: x <= (self.labels[param_name].x + self.labels[param_name].content_width) and \ y >= self.labels[param_name].y and \ y <= (self.labels[param_name].y + self.labels[param_name].content_height): + if param_value == 0: + if scroll_y < 1: + param_value -= .1 + else: + param_value += .1 + if scroll_y < 0: param_value /= (-scroll_y * 1.25) else: