Skip to content

Commit

Permalink
modfied blender data parser (#54)
Browse files Browse the repository at this point in the history
* update

* requsted changes

* Update __init__.py

* revert for ngp

* Update blender dataparser
1. Allow images having different sizes
2. Close opened file after getting sizes

* Remove unused import

* Revert some minor changes

* Fix wrong width and height order

---------
  • Loading branch information
hardikdava authored Sep 21, 2024
1 parent 13c8d29 commit 92b0126
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions internal/dataparsers/blender_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

import torch
from PIL import Image
from typing import Literal
from dataclasses import dataclass
from .dataparser import ImageSet, PointCloud, DataParserConfig, DataParser, DataParserOutputs
Expand Down Expand Up @@ -40,9 +41,6 @@ def _parse_transforms_json(self, split: str) -> ImageSet:
with open(os.path.join(self.path, "transforms_{}.json".format(i)), "r") as f:
transforms["frames"] += json.load(f)["frames"]

# TODO: auto detect image size
width = 800

# parse extrinsic
image_name_list = []
image_path_list = []
Expand All @@ -65,18 +63,25 @@ def _parse_transforms_json(self, split: str) -> ImageSet:
R = world_to_camera[:, :3, :3]
T = world_to_camera[:, :3, 3]

# TODO: allow different height
height_list = []
for image_path in image_path_list:
img = Image.open(image_path)
try:
width, height = img.size
assert height == width, "height must be equal to width"
height_list.append(height)
finally:
img.close()

height = torch.tensor(height_list, dtype=torch.int)
width = torch.clone(height)

# parse focal length
fx = torch.tensor(
[fov2focal(fov=transforms["camera_angle_x"], pixels=width)],
dtype=torch.float32,
).expand(R.shape[0])
fx = fov2focal(fov=transforms["camera_angle_x"], pixels=width)
# TODO: allow different fy
fy = torch.clone(fx)

width = torch.tensor([width], dtype=torch.int).expand(R.shape[0])
# TODO: allow different height
height = torch.clone(width)

return ImageSet(
image_names=image_name_list,
image_paths=image_path_list,
Expand Down

0 comments on commit 92b0126

Please sign in to comment.