Render PyTorch3d cameras in plotly

Summary: Take in a renderer with camera(s) and render the cameras as wireframes in the corresponding plotly plots

Reviewed By: nikhilaravi

Differential Revision: D24151706

fbshipit-source-id: f8e86d61f3d991500bafc0533738c79b96bda630
This commit is contained in:
Amitav Baruah
2020-10-20 17:14:38 -07:00
committed by Facebook GitHub Bot
parent 035109675e
commit 005a334f99
2 changed files with 130 additions and 33 deletions

View File

@@ -1,23 +1,8 @@
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import matplotlib.pyplot as plt
import torch
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
def get_camera_wireframe(scale: float = 0.3):
"""
Returns a wireframe of a 3D line-plot of a camera symbol.
"""
a = 0.5 * torch.tensor([-2, 1.5, 4])
b = 0.5 * torch.tensor([2, 1.5, 4])
c = 0.5 * torch.tensor([-2, -1.5, 4])
d = 0.5 * torch.tensor([2, -1.5, 4])
C = torch.zeros(3)
F = torch.tensor([0, 0, 3])
camera_points = [a, b, d, c, a, C, b, d, C, c, C, F]
lines = torch.stack([x.float() for x in camera_points]) * scale
return lines
from pytorch3d.vis.plotly_vis import get_camera_wireframe
def plot_cameras(ax, cameras, color: str = "blue"):