diff --git a/pyba/Camera.py b/pyba/Camera.py index 0bb593b..242f124 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): @@ -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): @@ -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 diff --git a/pyba/config.py b/pyba/config.py index 615729b..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, 0), - (0, 255, 0), - (0, 255, 0), - (0, 255, 0), - (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]) 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 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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e6b4db3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +# See https://github.com/pypa/pip/issues/11457 +[build-system] +requires = ["setuptools >= 64"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py index 0478ef5..7b14f82 100644 --- a/setup.py +++ b/setup.py @@ -4,12 +4,18 @@ long_description = fh.read() setuptools.setup( - name="pyba", - version="0.12", + name="nely-pyba", + version="0.13.1", 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", + install_requires=[ + "opencv-python-headless>=4.8.1.78", # https://github.com/NeLy-EPFL/DeepFly3D/security/dependabot/4 + "numpy", + "matplotlib", + "scipy" + ], +)