mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-17 12:50:35 +08:00
camera refactoring
Summary: Refactor cameras * CamerasBase was enhanced with `transform_points_screen` that transforms projected points from NDC to screen space * OpenGLPerspective, OpenGLOrthographic -> FoVPerspective, FoVOrthographic * SfMPerspective, SfMOrthographic -> Perspective, Orthographic * PerspectiveCamera can optionally be constructred with screen space parameters * Note on Cameras and coordinate systems was added Reviewed By: nikhilaravi Differential Revision: D23168525 fbshipit-source-id: dd138e2b2cc7e0e0d9f34c45b8251c01266a2063
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9242e7e65d
commit
57a22e7306
@@ -102,7 +102,7 @@
|
||||
"\n",
|
||||
"# rendering components\n",
|
||||
"from pytorch3d.renderer import (\n",
|
||||
" OpenGLPerspectiveCameras, look_at_view_transform, look_at_rotation, \n",
|
||||
" FoVPerspectiveCameras, look_at_view_transform, look_at_rotation, \n",
|
||||
" RasterizationSettings, MeshRenderer, MeshRasterizer, BlendParams,\n",
|
||||
" SoftSilhouetteShader, HardPhongShader, PointLights\n",
|
||||
")"
|
||||
@@ -217,8 +217,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize an OpenGL perspective camera.\n",
|
||||
"cameras = OpenGLPerspectiveCameras(device=device)\n",
|
||||
"# Initialize a perspective camera.\n",
|
||||
"cameras = FoVPerspectiveCameras(device=device)\n",
|
||||
"\n",
|
||||
"# To blend the 100 faces we set a few parameters which control the opacity and the sharpness of \n",
|
||||
"# edges. Refer to blending.py for more details. \n",
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
"from pytorch3d.structures import Meshes, Textures\n",
|
||||
"from pytorch3d.renderer import (\n",
|
||||
" look_at_view_transform,\n",
|
||||
" OpenGLPerspectiveCameras, \n",
|
||||
" FoVPerspectiveCameras, \n",
|
||||
" PointLights, \n",
|
||||
" DirectionalLights, \n",
|
||||
" Materials, \n",
|
||||
@@ -309,16 +309,16 @@
|
||||
"# the cow is facing the -z direction. \n",
|
||||
"lights = PointLights(device=device, location=[[0.0, 0.0, -3.0]])\n",
|
||||
"\n",
|
||||
"# Initialize an OpenGL perspective camera that represents a batch of different \n",
|
||||
"# Initialize a camera that represents a batch of different \n",
|
||||
"# viewing angles. All the cameras helper methods support mixed type inputs and \n",
|
||||
"# broadcasting. So we can view the camera from the a distance of dist=2.7, and \n",
|
||||
"# then specify elevation and azimuth angles for each viewpoint as tensors. \n",
|
||||
"R, T = look_at_view_transform(dist=2.7, elev=elev, azim=azim)\n",
|
||||
"cameras = OpenGLPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"cameras = FoVPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"\n",
|
||||
"# We arbitrarily choose one particular view that will be used to visualize \n",
|
||||
"# results\n",
|
||||
"camera = OpenGLPerspectiveCameras(device=device, R=R[None, 1, ...], \n",
|
||||
"camera = FoVPerspectiveCameras(device=device, R=R[None, 1, ...], \n",
|
||||
" T=T[None, 1, ...]) \n",
|
||||
"\n",
|
||||
"# Define the settings for rasterization and shading. Here we set the output \n",
|
||||
@@ -361,7 +361,7 @@
|
||||
"# Our multi-view cow dataset will be represented by these 2 lists of tensors,\n",
|
||||
"# each of length num_views.\n",
|
||||
"target_rgb = [target_images[i, ..., :3] for i in range(num_views)]\n",
|
||||
"target_cameras = [OpenGLPerspectiveCameras(device=device, R=R[None, i, ...], \n",
|
||||
"target_cameras = [FoVPerspectiveCameras(device=device, R=R[None, i, ...], \n",
|
||||
" T=T[None, i, ...]) for i in range(num_views)]"
|
||||
],
|
||||
"execution_count": null,
|
||||
@@ -925,4 +925,4 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
"from pytorch3d.structures import Pointclouds\n",
|
||||
"from pytorch3d.renderer import (\n",
|
||||
" look_at_view_transform,\n",
|
||||
" OpenGLOrthographicCameras, \n",
|
||||
" FoVOrthographicCameras, \n",
|
||||
" PointsRasterizationSettings,\n",
|
||||
" PointsRenderer,\n",
|
||||
" PointsRasterizer,\n",
|
||||
@@ -147,9 +147,9 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize an OpenGL perspective camera.\n",
|
||||
"# Initialize a camera.\n",
|
||||
"R, T = look_at_view_transform(20, 10, 0)\n",
|
||||
"cameras = OpenGLOrthographicCameras(device=device, R=R, T=T, znear=0.01)\n",
|
||||
"cameras = FoVOrthographicCameras(device=device, R=R, T=T, znear=0.01)\n",
|
||||
"\n",
|
||||
"# Define the settings for rasterization and shading. Here we set the output image to be of size\n",
|
||||
"# 512x512. As we are rendering images for visualization purposes only we will set faces_per_pixel=1\n",
|
||||
@@ -195,9 +195,9 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize an OpenGL perspective camera.\n",
|
||||
"# Initialize a camera.\n",
|
||||
"R, T = look_at_view_transform(20, 10, 0)\n",
|
||||
"cameras = OpenGLOrthographicCameras(device=device, R=R, T=T, znear=0.01)\n",
|
||||
"cameras = FoVOrthographicCameras(device=device, R=R, T=T, znear=0.01)\n",
|
||||
"\n",
|
||||
"# Define the settings for rasterization and shading. Here we set the output image to be of size\n",
|
||||
"# 512x512. As we are rendering images for visualization purposes only we will set faces_per_pixel=1\n",
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
"from pytorch3d.structures import Meshes, Textures\n",
|
||||
"from pytorch3d.renderer import (\n",
|
||||
" look_at_view_transform,\n",
|
||||
" OpenGLPerspectiveCameras, \n",
|
||||
" FoVPerspectiveCameras, \n",
|
||||
" PointLights, \n",
|
||||
" DirectionalLights, \n",
|
||||
" Materials, \n",
|
||||
@@ -286,11 +286,11 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Initialize an OpenGL perspective camera.\n",
|
||||
"# Initialize a camera.\n",
|
||||
"# With world coordinates +Y up, +X left and +Z in, the front of the cow is facing the -Z direction. \n",
|
||||
"# So we move the camera by 180 in the azimuth direction so it is facing the front of the cow. \n",
|
||||
"R, T = look_at_view_transform(2.7, 0, 180) \n",
|
||||
"cameras = OpenGLPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"cameras = FoVPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"\n",
|
||||
"# Define the settings for rasterization and shading. Here we set the output image to be of size\n",
|
||||
"# 512x512. As we are rendering images for visualization purposes only we will set faces_per_pixel=1\n",
|
||||
@@ -444,7 +444,7 @@
|
||||
"source": [
|
||||
"# Rotate the object by increasing the elevation and azimuth angles\n",
|
||||
"R, T = look_at_view_transform(dist=2.7, elev=10, azim=-150)\n",
|
||||
"cameras = OpenGLPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"cameras = FoVPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"\n",
|
||||
"# Move the light location so the light is shining on the cow's face. \n",
|
||||
"lights.location = torch.tensor([[2.0, 2.0, -2.0]], device=device)\n",
|
||||
@@ -519,7 +519,7 @@
|
||||
"# view the camera from the same distance and specify dist=2.7 as a float,\n",
|
||||
"# and then specify elevation and azimuth angles for each viewpoint as tensors. \n",
|
||||
"R, T = look_at_view_transform(dist=2.7, elev=elev, azim=azim)\n",
|
||||
"cameras = OpenGLPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"cameras = FoVPerspectiveCameras(device=device, R=R, T=T)\n",
|
||||
"\n",
|
||||
"# Move the light back in front of the cow which is facing the -z direction.\n",
|
||||
"lights.location = torch.tensor([[0.0, 0.0, -3.0]], device=device)"
|
||||
|
||||
Reference in New Issue
Block a user