Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions pyba/Camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -142,29 +142,39 @@ 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,
)

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
Expand Down
80 changes: 52 additions & 28 deletions pyba/config.py
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
10 changes: 5 additions & 5 deletions pyba/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyba/pyba.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# See https://github.com/pypa/pip/issues/11457
[build-system]
requires = ["setuptools >= 64"]
build-backend = "setuptools.build_meta"
14 changes: 10 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
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"
],
)