From 74fbb48970e69f9800df44e31d28653425edd756 Mon Sep 17 00:00:00 2001 From: Alexandre Flusin Date: Wed, 23 Jul 2025 15:48:52 +0200 Subject: [PATCH 1/2] Implement reprojection in 3d video --- df3d/core.py | 13 +++++++++---- df3d/video.py | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/df3d/core.py b/df3d/core.py index e9e651e..1912a72 100644 --- a/df3d/core.py +++ b/df3d/core.py @@ -295,7 +295,8 @@ def smooth_points2d(self, cam_id, private_cache=dict()): private_cache[cam_id] = smooth_pose2d(cam.points2d) return private_cache[cam_id] - def plot_2d(self, cam_id, img_id, with_corrections=False, smooth=False, joints=[]): + def plot_2d(self, cam_id, img_id, with_corrections=False, + smooth=False, joints=[], reprojection=False): """Plots the 2d pose estimation results. Parameters: @@ -311,11 +312,15 @@ def plot_2d(self, cam_id, img_id, with_corrections=False, smooth=False, joints=[ from pyba.config import df3d_bones, df3d_colors if with_corrections: - pts2d = self.corrected_points2d(cam_id, img_id) + pts = self.corrected_points2d(cam_id, img_id) else: - pts2d = None + pts = None + + if reprojection: + pts = np.copy(self.camNet.points3d) + return self.camNet[cam_id].plot_2d( - img_id, points2d=pts2d, bones=df3d_bones, colors=df3d_colors + img_id, points=pts, bones=df3d_bones, colors=df3d_colors ) def get_image(self, cam_id, img_id): diff --git a/df3d/video.py b/df3d/video.py index 5a2d4a4..a8fa59a 100644 --- a/df3d/video.py +++ b/df3d/video.py @@ -110,17 +110,17 @@ def _make_video(video_path, imgs, fps=default_fps): def _resize(current_shape, new_width): width, height = current_shape - ratio = new_width / width; + ratio = new_width / width return (int(width * ratio), int(height * ratio)) -def _compute_2d_img(plot_2d, img_id, cam_id): +def _compute_2d_img(plot_2d, img_id, cam_id, reprojection=True): """Uses plot_2d to generate an image and resizes it using cv2. Returns: A numpy array containing the resized image. """ - img = plot_2d(cam_id, img_id, smooth=True) + img = plot_2d(cam_id, img_id, smooth=True, reprojection=reprojection) img = cv2.resize(img, (img2d_aspect[0]*img3d_dpi, img2d_aspect[1]*img3d_dpi)) return img From 4ce47bcd062df7c7034b61a854df6922469fb878 Mon Sep 17 00:00:00 2001 From: Jasper Phelps Date: Mon, 11 May 2026 17:23:20 +0200 Subject: [PATCH 2/2] Use pyba's plot_reprojections; guard incompatible flags Update Core.plot_2d to the new pyba API: route reprojection requests through Camera.plot_reprojections and keep Camera.plot_2d for 2D-only plotting. Raise ValueError if with_corrections and reprojection are both True, since corrections were silently discarded before. --- df3d/core.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/df3d/core.py b/df3d/core.py index 1912a72..d76641c 100644 --- a/df3d/core.py +++ b/df3d/core.py @@ -311,17 +311,17 @@ def plot_2d(self, cam_id, img_id, with_corrections=False, """ from pyba.config import df3d_bones, df3d_colors - if with_corrections: - pts = self.corrected_points2d(cam_id, img_id) - else: - pts = None + if with_corrections and reprojection: + raise ValueError("'with_corrections' and 'reprojection' " + "cannot both be set to True") + cam = self.camNet[cam_id] if reprojection: - pts = np.copy(self.camNet.points3d) - - return self.camNet[cam_id].plot_2d( - img_id, points=pts, bones=df3d_bones, colors=df3d_colors - ) + return cam.plot_reprojections(img_id, self.camNet.points3d, + bones=df3d_bones, colors=df3d_colors) + pts2d = self.corrected_points2d(cam_id, img_id) if with_corrections else None + return cam.plot_2d(img_id, points2d=pts2d, + bones=df3d_bones, colors=df3d_colors) def get_image(self, cam_id, img_id): """Returns the img_id image from cam_id camera."""