Skip to content

Commit

Permalink
Publish pyopf (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: pix4d_concourse_developers <[email protected]>
  • Loading branch information
tomashynek and pix4d_concourse_developers authored Dec 12, 2024
1 parent ec60ebe commit e16f0c6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added
### Changed
### Fixed
### Removed

## 1.4.0

### Added

- Added the functionality for `opf2nerf` to output the `avg_pos` and `scale` when using with `--nerfstudio`.
- Added the original resources to the metadata of resolved project items.

### Fixed

- Version check for compatibility.

## 1.3.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "pyopf"
version = "1.3.1"
version = "1.4.0"
description = "Python library for I/O and manipulation of projects under the Open Photogrammetry Format (OPF)"
authors = [
"Pix4D",
Expand Down
20 changes: 11 additions & 9 deletions src/opf_tools/opf2nerf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,9 @@ def rescale_position(
transforms_train: dict,
transforms_test: dict,
avg_pos: np.ndarray,
max_pos: np.ndarray,
min_pos: np.ndarray,
cam_aabb_size: float,
scale: float,
) -> None:
"""Rescale and center so all cameras fit in a cube bounding box of edge length cam_aabb_size centered in [0, 0, 0]."""
scale = np.max(max_pos - min_pos)
scale /= cam_aabb_size

for transforms in [transforms_train, transforms_test]:
for frame in transforms["frames"]:
transform_matrix = np.asarray(frame["transform_matrix"])
Expand Down Expand Up @@ -250,13 +245,20 @@ def generate_nerf_transforms(
pbar.set_postfix_str(os.path.basename(image_path) + "->" + assigned_msg)

avg_pos /= len(project.calibration.calibrated_cameras.cameras)
scale = np.max(max_pos - min_pos) / user_config["camera_aabb_size"]

if user_config["nerfstudio"]:
# if the conversion is under nerfstudio format, the average positions
# of the cameras & scale of the scene are saved in the transforms.json
# file to transform back to the original coordinates.
transforms_train["avg_pos"] = avg_pos.tolist()
transforms_train["scale"] = scale

rescale_position(
transforms_train,
transforms_test,
avg_pos,
max_pos,
min_pos,
user_config["camera_aabb_size"],
scale,
)

return transforms_train, transforms_test
Expand Down
8 changes: 6 additions & 2 deletions src/pyopf/VersionInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ def parse(cls, version: str):
return cls(major, minor, prerelease)

def compatible_with(self, other):
if self.major != other.major or self.prerelease != other.prerelease:
# self is the version of the file we read
# other is the version of the reader code
if self.major != other.major:
return False
if self.major > 0:
if self.prerelease is not None and self.minor != other.minor:
if other.prerelease is not None and (
self.minor != other.minor or self.prerelease != other.prerelease
):
return False
elif self.major == 0 and self.minor != other.minor:
return False
Expand Down
10 changes: 9 additions & 1 deletion src/pyopf/project/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

from ..VersionInfo import VersionInfo
from ..versions import FormatVersion
from .project import Generator, ProjectItem, ProjectItemType, ProjectSource
from .project import (
Generator,
ProjectItem,
ProjectItemType,
ProjectResource,
ProjectSource,
)


class Sources:
Expand All @@ -20,6 +26,7 @@ class Metadata:
name: Optional[str] = None
labels: Optional[list[str]] = None
sources: Union[list[ProjectSource], Sources] = field(default_factory=list)
resources: list[ProjectResource] = field(default_factory=list)
"""The object sources. This may contain an object with named attributes
pointing to the sources or a list of ProjectSources"""

Expand All @@ -31,6 +38,7 @@ def from_item(item: ProjectItem) -> "Metadata":
type=item.type,
labels=item.labels,
sources=item.sources,
resources=item.resources,
)

def raw_sources(self) -> list[ProjectSource]:
Expand Down

0 comments on commit e16f0c6

Please sign in to comment.