Skip to content

Commit

Permalink
per-scene camera intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeroberts3000 committed Jan 10, 2022
1 parent 37dd335 commit 76dbac9
Show file tree
Hide file tree
Showing 13 changed files with 1,631 additions and 28 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ code/python/tools/libvrayopenimageio.dylib
code/python/tools/libvrayosl.dylib
code/python/tools/libVRaySDKLibrary.dylib
code/python/tools/plugins
contrib/mikeroberts3000/jupyter/.ipynb_checkpoints
contrib/mikeroberts3000/jupyter/_tmp
contrib/mikeroberts3000/python/libcgauth.dylib
contrib/mikeroberts3000/python/libvray.dylib
contrib/mikeroberts3000/python/libvrayopenimageio.dylib
contrib/mikeroberts3000/python/libvrayosl.dylib
contrib/mikeroberts3000/python/libVRaySDKLibrary.dylib
contrib/mikeroberts3000/python/plugins
6 changes: 3 additions & 3 deletions code/python/lib/embree_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def generate_ray_intersections(vertices, faces, ray_positions, ray_directions, t
with h5py.File(tmp_ray_positions_hdf5_file, "w") as f: f.create_dataset("dataset", data=ray_positions)
with h5py.File(tmp_ray_directions_hdf5_file, "w") as f: f.create_dataset("dataset", data=ray_directions)

current_source_path = path_utils.get_current_source_file_path(frame=inspect.currentframe())
generate_octomap_bin = os.path.abspath(os.path.join(current_source_path, "..", "..", "cpp", "bin", "generate_ray_intersections"))
current_source_path = path_utils.get_current_source_file_path(frame=inspect.currentframe())
generate_ray_intersections_bin = os.path.abspath(os.path.join(current_source_path, "..", "..", "cpp", "bin", "generate_ray_intersections"))

cmd = \
generate_octomap_bin + \
generate_ray_intersections_bin + \
" --vertices_file=" + tmp_vertices_hdf5_file + \
" --faces_file=" + tmp_faces_hdf5_file + \
" --ray_positions_file=" + tmp_ray_positions_hdf5_file + \
Expand Down
4 changes: 2 additions & 2 deletions code/python/tools/scene_generate_images_bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
far = 1000.0

# construct projection matrix
f_h = tan(fov_y/2.0)*near;
f_w = f_h*width_pixels/height_pixels;
f_h = tan(fov_y/2.0)*near
f_w = f_h*width_pixels/height_pixels
left = -f_w
right = f_w
bottom = -f_h
Expand Down
50 changes: 27 additions & 23 deletions contrib/99991/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,37 +544,40 @@ def download_files(args):

# For each zip file
for url in URLS:
f = WebFile(url, session)

z = zipfile.ZipFile(f)
if args.scene is None or args.scene in url:

# for each file in zip file
for entry in z.infolist():
f = WebFile(url, session)

# skip directories in zip file (will be created automatically)
if entry.is_dir():
continue
z = zipfile.ZipFile(f)

path = os.path.join(args.directory, entry.filename)
# for each file in zip file
for entry in z.infolist():

contains_all_words = all(
word in entry.filename for words in args.contains for word in words
)
# skip directories in zip file (will be created automatically)
if entry.is_dir():
continue

if args.list:
if contains_all_words:
print(entry.filename)
else:
if contains_all_words:
if os.path.isfile(path) and not args.overwrite:
print("File already exists:", path)
else:
print("Downloading:", path)
path = os.path.join(args.directory, entry.filename)

contains_all_words = all(
word in entry.filename for words in args.contains for word in words
)

z.extract(entry.filename, args.directory)
if args.list:
if contains_all_words:
print(entry.filename)
else:
if not args.silent:
print("Skipping:", path)
if contains_all_words:
if os.path.isfile(path) and not args.overwrite:
print("File already exists:", path)
else:
print("Downloading:", path)

z.extract(entry.filename, args.directory)
else:
if not args.silent:
print("Skipping:", path)


def main():
Expand Down Expand Up @@ -604,6 +607,7 @@ def main():
parser.add_argument("-d", "--directory", type=str, default="downloads", help="directory to download to")
parser.add_argument("-o", "--overwrite", action="store_true", help="overwrite existing files")
parser.add_argument("-c", "--contains", nargs="*", action="append", default=[], help="only download file if name contains specific word(s)")
parser.add_argument("-e", "--scene", type=str, help="only download files from this scene")
parser.add_argument("-s", "--silent", action="store_true", help="only print downloaded files")
parser.add_argument("-l", "--list", action="store_true", help="only list files, do not download")

Expand Down
98 changes: 98 additions & 0 deletions contrib/mikeroberts3000/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Working with per-scene camera intrinsics in Hypersim

Each Hypersim scene uses slightly different camera intrinsics for rendering. This issue arises because some scenes make use of non-standard tilt-shift photography parameters in their scene definition files. This directory provides: (1) a modified perspective projection matrix for each scene that can be used as a drop-in replacement for the usual OpenGL perspective projection matrix; (2) example code demonstrating how the modified projection matrix can be used in applications; and (3) code for computing the modified projection matrix for each scene.

## Obtaining the perspective projection matrix for a given scene

The [`metadata_camera_parameters.csv`](metadata_camera_parameters.csv) file contains every camera parameter for every scene obtained directly from the corresponding vrscene file. Each row in this CSV file describes a scene, and the `M_proj_00`, `M_proj_01`, ..., `M_proj_44` columns define the entries of the 4x4 perspective projection matrix for that scene, assuming that camera-space points are stored as [x,y,z,w] column-vectors. For many scenes, this matrix will be the usual OpenGL perspective projection matrix. For other scenes with non-standard tilt-shift parameters, this matrix will be modified to account for the non-standard parameters.

This [example code](jupyter/00_00_projecting_points_into_hypersim_images.ipynb) demonstrates how to use the projection matrix.

First, list all files with the command:

```
./download.py --list
```

Output:

```
ai_001_001/_detail/cam_00/camera_keyframe_frame_indices.hdf5
ai_001_001/_detail/cam_00/camera_keyframe_look_at_positions.hdf5
ai_001_001/_detail/cam_00/camera_keyframe_orientations.hdf5
ai_001_001/_detail/cam_00/camera_keyframe_positions.hdf5
ai_001_001/_detail/cam_00/metadata_camera.csv
ai_001_001/_detail/metadata_cameras.csv
ai_001_001/_detail/metadata_node_strings.csv
ai_001_001/_detail/metadata_nodes.csv
ai_001_001/_detail/metadata_scene.csv
ai_001_001/images/scene_cam_00_final_hdf5/frame.0000.color.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0000.diffuse_illumination.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0000.diffuse_reflectance.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0000.residual.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0001.color.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0001.diffuse_illumination.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0001.diffuse_reflectance.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0001.residual.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0002.color.hdf5
ai_001_001/images/scene_cam_00_final_hdf5/frame.0002.diffuse_illumination.hdf5
...
ai_001_001/images/scene_cam_00_final_preview/frame.0000.color.jpg
ai_001_001/images/scene_cam_00_final_preview/frame.0000.diff.jpg
...
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.depth_meters.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.normal_bump_cam.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.normal_bump_world.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.normal_cam.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.normal_world.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.position.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.render_entity_id.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.semantic.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.semantic_instance.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0000.tex_coord.hdf5
ai_001_002/images/scene_cam_03_geometry_hdf5/frame.0001.depth_meters.hdf5
...
ai_001_002/images/scene_cam_03_geometry_preview/frame.0000.color.jpg
...
```

Next, specify which files you are interested in and download them.
For example, the following command will download the first preview image of each scene:

```
./download.py --contains scene_cam_00_final_preview --contains frame.0000.color.jpg --silent
```

# Help


```
usage: download.py [-h] [-d DIRECTORY] [-o] [-c [CONTAINS [CONTAINS ...]]]
[-s] [-l]
optional arguments:
-h, --help show this help message and exit
-d DIRECTORY, --directory DIRECTORY
directory to download to
-o, --overwrite overwrite existing files
-c [CONTAINS [CONTAINS ...]], --contains [CONTAINS [CONTAINS ...]]
only download file if name contains specific word(s)
-s, --silent only print downloaded files
-l, --list only list files, do not download
example: list files without downloading
./download.py --list
example: download the first preview of each scene:
./download.py --contains scene_cam_00_final_preview --contains frame.0000.color.jpg --silent
example: download all files to "all hypersim images" directory
./download.py --directory 'all hypersim images'
example: print help
./download.py --help
```

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions contrib/mikeroberts3000/jupyter/path_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# For licensing see accompanying LICENSE.txt file.
# Copyright (C) 2020 Apple Inc. All Rights Reserved.
#

import os, sys, inspect

def add_path_to_sys_path(path, mode, frame):
assert mode == "unchanged" or mode == "relative_to_cwd" or mode == "relative_to_current_source_dir"
if mode == "unchanged":
if path not in sys.path:
sys.path.insert(0,path)
if mode == "relative_to_cwd":
realpath = os.path.realpath(os.path.abspath(path))
if realpath not in sys.path:
sys.path.insert(0,realpath)
if mode == "relative_to_current_source_dir":
realpath = os.path.realpath(os.path.abspath(os.path.join(os.path.dirname(inspect.getfile(frame)),path)))
if realpath not in sys.path:
sys.path.insert(0,realpath)

def get_current_source_file_path(frame):
return os.path.realpath(os.path.abspath(os.path.join(os.path.dirname(inspect.getfile(frame)))))
Loading

0 comments on commit 76dbac9

Please sign in to comment.