From 9952fa84ed0935abcb5f1a4c8e3a0615034d098d Mon Sep 17 00:00:00 2001 From: Sibo Wang Date: Thu, 17 Mar 2022 14:45:45 +0100 Subject: [PATCH 01/11] migrate PyPI projects to `nely-epfl` account --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 0478ef5..7e7d100 100644 --- a/setup.py +++ b/setup.py @@ -4,12 +4,12 @@ long_description = fh.read() setuptools.setup( - name="pyba", - version="0.12", + name="nely-pyba", + version="0.13", author="Semih Günel", packages=["pyba"], description="Python Bundle Adjustment Routines", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/semihgunel/PyBundleAdjustment" -) \ No newline at end of file + url="https://github.com/NeLy-EPFL/PyBundleAdjustment" +) From 8471a88d993ece9abbd95af4c84454eeecda9969 Mon Sep 17 00:00:00 2001 From: Jasper Phelps Date: Sat, 1 Jun 2024 21:56:20 +0200 Subject: [PATCH 02/11] Change obsolete `np.float` to `float`. The following is printed when code that includes `np.float` attempts to run: AttributeError: module 'numpy' has no attribute 'float'. `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations --- pyba/Camera.py | 2 +- pyba/pyba.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyba/Camera.py b/pyba/Camera.py index 0bb593b..375ec6a 100644 --- a/pyba/Camera.py +++ b/pyba/Camera.py @@ -41,7 +41,7 @@ def __init__( self.intrinsic = intr self.tvec = tvec self.R = R - self.distort = np.zeros(5, dtype=np.float) if distort is None else distort + self.distort = np.zeros(5, dtype=float) if distort is None else distort @property def P(self): diff --git a/pyba/pyba.py b/pyba/pyba.py index dd4b247..1c00552 100644 --- a/pyba/pyba.py +++ b/pyba/pyba.py @@ -162,7 +162,7 @@ def residuals( points3d = params[n_cameras * 13 :].reshape((n_points, 3)) cam_indices_list = list(set(camera_indices)) - points_proj = np.zeros(shape=(point_indices.shape[0], 2), dtype=np.float) + points_proj = np.zeros(shape=(point_indices.shape[0], 2), dtype=float) for cam_id in cam_indices_list: update_parameters( camera_params[cam_id], cam_list[cam_id], update_intrinsic, update_distort From 2b09c3d92f4923ab99f02e3205b8aec7e1dcea7c Mon Sep 17 00:00:00 2001 From: Jasper Phelps Date: Wed, 4 Sep 2024 14:05:28 +0200 Subject: [PATCH 03/11] Bump version 0.13 -> 0.13.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7e7d100..78abed6 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="nely-pyba", - version="0.13", + version="0.13.1", author="Semih Günel", packages=["pyba"], description="Python Bundle Adjustment Routines", From 3f01ba8d2430c8aae9f5ff5fad72a0faa5fd1793 Mon Sep 17 00:00:00 2001 From: Dom Date: Fri, 20 Sep 2024 15:12:40 +0200 Subject: [PATCH 04/11] Fix deprecated usage of Axes3D.w_xaxis Fixes #1 --- pyba/plot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyba/plot.py b/pyba/plot.py index deeea84..f922012 100644 --- a/pyba/plot.py +++ b/pyba/plot.py @@ -71,12 +71,12 @@ def plot_3d( points3d = np.copy(points3d) points3d -= points3d.mean() white = (1.0, 1.0, 1.0, 0.0) - ax_3d.w_xaxis.set_pane_color(white) - ax_3d.w_yaxis.set_pane_color(white) + ax_3d.xaxis.set_pane_color(white) + ax_3d.yaxis.set_pane_color(white) - ax_3d.w_xaxis.line.set_color(white) - ax_3d.w_yaxis.line.set_color(white) - ax_3d.w_zaxis.line.set_color(white) + ax_3d.xaxis.line.set_color(white) + ax_3d.yaxis.line.set_color(white) + ax_3d.zaxis.line.set_color(white) if lim is not None: max_range = lim From b5d908475b3c62116bd14b927757bf89ffd3e74e Mon Sep 17 00:00:00 2001 From: Dom Date: Fri, 20 Sep 2024 15:13:10 +0200 Subject: [PATCH 05/11] Replace `plt.imread` with `cv2.imread` Fixes #2 --- pyba/Camera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyba/Camera.py b/pyba/Camera.py index 375ec6a..c7c3072 100644 --- a/pyba/Camera.py +++ b/pyba/Camera.py @@ -119,7 +119,7 @@ def get_njoints(self): def get_image(self, img_id: int): try: - img = plt.imread(self.image_path.format(img_id=img_id)) + img = cv2.imread(self.image_path.format(img_id=img_id)) except: img = np.zeros((480, 960), dtype=np.uint8) if img.ndim == 2 or (img.ndim == 3 and img.shape[-1] == 1): From f93b2ad404af6041cdc377ff362861752f64bed6 Mon Sep 17 00:00:00 2001 From: Jasper Phelps Date: Wed, 2 Oct 2024 11:40:57 +0200 Subject: [PATCH 06/11] Make left hind leg cyan (not green) to match DeepFly3D colors Closes NeLy-EPFL/DeepFly3D#52 --- pyba/config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyba/config.py b/pyba/config.py index 615729b..c07165b 100644 --- a/pyba/config.py +++ b/pyba/config.py @@ -23,10 +23,10 @@ (255, 0, 255), (255, 0, 255), (255, 0, 255), - (0, 255, 0), - (0, 255, 0), - (0, 255, 0), - (0, 255, 0), + (0, 255, 255), + (0, 255, 255), + (0, 255, 255), + (0, 255, 255), (255, 131, 0), (255, 131, 0), ] From 7a0367e5c91e9f2467dfd456fceca7e58ae92395 Mon Sep 17 00:00:00 2001 From: Dom Date: Fri, 4 Oct 2024 10:04:06 +0200 Subject: [PATCH 07/11] Add dependencies to setup.py --- setup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 78abed6..7b14f82 100644 --- a/setup.py +++ b/setup.py @@ -11,5 +11,11 @@ description="Python Bundle Adjustment Routines", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/NeLy-EPFL/PyBundleAdjustment" + url="https://github.com/NeLy-EPFL/PyBundleAdjustment", + install_requires=[ + "opencv-python-headless>=4.8.1.78", # https://github.com/NeLy-EPFL/DeepFly3D/security/dependabot/4 + "numpy", + "matplotlib", + "scipy" + ], ) From 8fa93a02191c8a3f8c640c43c99c4694d6b4c89f Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 21 Oct 2024 17:37:07 +0200 Subject: [PATCH 08/11] Update limb colour plotting to be more intuitive --- pyba/config.py | 80 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/pyba/config.py b/pyba/config.py index c07165b..86fcdea 100644 --- a/pyba/config.py +++ b/pyba/config.py @@ -1,34 +1,58 @@ import numpy as np +LEG_RIGHT_FRONT = (178, 178, 255) +LEG_RIGHT_MIDDLE = (102, 102, 255) +LEG_RIGHT_REAR = (0, 0, 255) +LEG_LEFT_FRONT = (255, 178, 178) +LEG_LEFT_MIDDLE = (255, 102, 102) +LEG_LEFT_REAR = (255, 0, 0) +BODY = (255, 254, 254) + +# LEG_RIGHT_FRONT = (198, 219, 239) +# LEG_RIGHT_MIDDLE = (107, 174, 214) +# LEG_RIGHT_REAR = (49, 130, 189) +# LEG_LEFT_FRONT = (253, 174, 107) +# LEG_LEFT_MIDDLE = (253, 141, 60) +# LEG_LEFT_REAR = (230, 85, 13) +# BODY = (49, 163, 84) + +LEG_RIGHT_FRONT = (186, 30, 49) +LEG_RIGHT_MIDDLE = (201, 86, 79) +LEG_RIGHT_REAR = (213, 133, 121) +LEG_LEFT_FRONT = (15, 115, 153) +LEG_LEFT_MIDDLE = (26, 141, 175) +LEG_LEFT_REAR = (117, 190, 203) +BODY = (210, 210, 210) + df3d_colors = [ - (255, 0, 0), - (255, 0, 0), - (255, 0, 0), - (255, 0, 0), - (0, 0, 255), - (0, 0, 255), - (0, 0, 255), - (0, 0, 255), - (0, 255, 0), - (0, 255, 0), - (0, 255, 0), - (0, 255, 0), - (255, 131, 0), - (255, 131, 0), - (255, 255, 0), - (255, 255, 0), - (255, 255, 0), - (255, 255, 0), - (255, 0, 255), - (255, 0, 255), - (255, 0, 255), - (255, 0, 255), - (0, 255, 255), - (0, 255, 255), - (0, 255, 255), - (0, 255, 255), - (255, 131, 0), - (255, 131, 0), + LEG_RIGHT_FRONT, + LEG_RIGHT_FRONT, + LEG_RIGHT_FRONT, + LEG_RIGHT_FRONT, + LEG_RIGHT_MIDDLE, + LEG_RIGHT_MIDDLE, + LEG_RIGHT_MIDDLE, + LEG_RIGHT_MIDDLE, + LEG_RIGHT_REAR, + LEG_RIGHT_REAR, + LEG_RIGHT_REAR, + LEG_RIGHT_REAR, + BODY, + BODY, + LEG_LEFT_FRONT, + LEG_LEFT_FRONT, + LEG_LEFT_FRONT, + LEG_LEFT_FRONT, + LEG_LEFT_MIDDLE, + LEG_LEFT_MIDDLE, + LEG_LEFT_MIDDLE, + LEG_LEFT_MIDDLE, + LEG_LEFT_REAR, + LEG_LEFT_REAR, + LEG_LEFT_REAR, + LEG_LEFT_REAR, + BODY, + BODY, ] df3d_bones = np.array([[i, i + 1] for i in range(15) if (i + 1) % 5 != 0]) From 527172fd5bfa61224e1ad3e1662cadce739bd03f Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 28 Oct 2024 11:16:07 +0100 Subject: [PATCH 09/11] Add `pyproject.toml` to enable editable install into the future See https://github.com/pypa/pip/issues/11457 --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..19d4f69 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +DeepFly3D/pyproject.toml# See https://github.com/pypa/pip/issues/11457 +[build-system] +requires = ["setuptools >= 64"] +build-backend = "setuptools.build_meta" \ No newline at end of file From 023b89d5b94630d25ddfab137713aeda4e552172 Mon Sep 17 00:00:00 2001 From: Dom Date: Mon, 28 Oct 2024 11:19:55 +0100 Subject: [PATCH 10/11] Fix typo in `pyproject.toml` --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 19d4f69..e6b4db3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,4 @@ -DeepFly3D/pyproject.toml# See https://github.com/pypa/pip/issues/11457 +# See https://github.com/pypa/pip/issues/11457 [build-system] requires = ["setuptools >= 64"] build-backend = "setuptools.build_meta" \ No newline at end of file From f1627f3421e4c7d290592f8ed072debd86b9519f Mon Sep 17 00:00:00 2001 From: Alexandre Flusin Date: Wed, 23 Jul 2025 16:20:12 +0200 Subject: [PATCH 11/11] Implement reprojection logic --- pyba/Camera.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pyba/Camera.py b/pyba/Camera.py index c7c3072..242f124 100644 --- a/pyba/Camera.py +++ b/pyba/Camera.py @@ -142,21 +142,31 @@ def summarize(self): def plot_2d( self, img_id: int, - points2d: Optional[np.ndarray] = None, + points: Optional[np.ndarray] = None, bones: Optional[np.ndarray] = None, colors: Optional[List[Tuple]] = None, ) -> np.ndarray: - img = self.get_image(img_id) - points2d = self.points2d[img_id] if points2d is None else points2d + """ + Parameters + ---------- + ... + + points: either points2d to plot directly, or points3d in which case they will + be projected for plotting. + """ + img = self.get_image(img_id) + points = self.points2d[img_id] if points is None else points[[img_id]] + if points.shape[-1] == 3: # If 3D points are given, project them + points = self.project(points).squeeze() # bones if bones is not None: for idx, b in enumerate(bones): if self.can_see(img_id, b[0]): img = cv2.line( img, - tuple(points2d[b[0]].astype(int)), - tuple(points2d[b[1]].astype(int)), + tuple(points[b[0]].astype(int)), + tuple(points[b[1]].astype(int)), colors[idx] if colors is not None else (128, 0, 0), 5, ) @@ -164,7 +174,7 @@ def plot_2d( for jid in range(self.get_njoints()): if self.can_see(img_id, jid): img = cv2.circle( - img, tuple(points2d[jid].astype(int)), 5, [0, 0, 128], 5 + img, tuple(points[jid].T.astype(int)), 5, [0, 0, 128], 5 ) return img