undo process_data change

This commit is contained in:
terrance committed 2023-05-12 18:48:58 +00:00
1 parent c9151d4a90
commit ee35703db8
4 files changed
+48 -59

No files matched your search

+6 -3
View File
@@ -13,12 +13,12 @@
# limitations under the License. # limitations under the License.
""" """
Tools supporting the execution of COLMAP and preparation of COLMAP-based datasets for nerfstudio training. Tools supporting the execution of COLMAP and preparation of COLMAP-based datasets for nerstudio training.
""" """
import json import json
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Literal, Optional from typing import Any, Dict, Optional
import appdirs import appdirs
import cv2 import cv2
@@ -27,6 +27,7 @@ import requests
import torch import torch
from rich.console import Console from rich.console import Console
from rich.progress import track from rich.progress import track
from typing_extensions import Literal
# TODO(1480) use pycolmap instead of colmap_parsing_utils # TODO(1480) use pycolmap instead of colmap_parsing_utils
# import pycolmap # import pycolmap
@@ -114,7 +115,9 @@ def run_colmap(
colmap_version = get_colmap_version(colmap_cmd) colmap_version = get_colmap_version(colmap_cmd)
colmap_database_path = colmap_dir / "database.db" colmap_database_path = colmap_dir / "database.db"
colmap_database_path.unlink(missing_ok=True) if colmap_database_path.exists():
# Can't use missing_ok argument because of Python 3.7 compatibility.
colmap_database_path.unlink()
# Feature extraction # Feature extraction
feature_extractor_cmd = [ feature_extractor_cmd = [
+1 -1
View File
@@ -21,9 +21,9 @@ Requires hloc module from : https://github.com/cvg/Hierarchical-Localization
import sys import sys
from pathlib import Path from pathlib import Path
from typing import Literal
from rich.console import Console from rich.console import Console
from typing_extensions import Literal
from nerfstudio.process_data.process_data_utils import CameraModel from nerfstudio.process_data.process_data_utils import CameraModel
+38 -52
View File
@@ -61,17 +61,12 @@ def metashape_to_json( # pylint: disable=too-many-statements
if sensors is None: if sensors is None:
raise ValueError("No sensors found") raise ValueError("No sensors found")
calibrated_sensors = [ calibrated_sensors = [sensor for sensor in sensors if sensor.find("calibration")]
sensor for sensor in sensors if sensor.get("type") == "spherical" or sensor.find("calibration")
]
if not calibrated_sensors: if not calibrated_sensors:
raise ValueError("No calibrated sensor found in Metashape XML") raise ValueError("No calibrated sensor found in Metashape XML")
sensor_type = [s.get("type") for s in calibrated_sensors] sensor_type = [s.get("type") for s in calibrated_sensors]
if sensor_type.count(sensor_type[0]) != len(sensor_type): if sensor_type.count(sensor_type[0]) != len(sensor_type):
raise ValueError( raise ValueError("All Metashape sensors do not have the same sensor type")
"All Metashape sensors do not have the same sensor type. "
"nerfstudio does not support per-frame camera_model."
)
data = {} data = {}
if sensor_type[0] == "frame": if sensor_type[0] == "frame":
data["camera_model"] = CAMERA_MODELS["perspective"].value data["camera_model"] = CAMERA_MODELS["perspective"].value
@@ -92,54 +87,46 @@ def metashape_to_json( # pylint: disable=too-many-statements
s["h"] = int(resolution.get("height")) # type: ignore s["h"] = int(resolution.get("height")) # type: ignore
calib = sensor.find("calibration") calib = sensor.find("calibration")
if calib is None: f = calib.find("f")
assert sensor_type[0] == "spherical", "Only spherical sensors should have no intrinsics" if f is not None:
s["fl_x"] = s["w"] / 2.0
s["fl_y"] = s["h"]
s["cx"] = s["w"] / 2.0
s["cy"] = s["h"] / 2.0
else:
f = calib.find("f")
assert f is not None, "Focal length not found in Metashape xml"
s["fl_x"] = s["fl_y"] = float(f.text) # type: ignore s["fl_x"] = s["fl_y"] = float(f.text) # type: ignore
s["cx"] = _find_param(calib, "cx") + s["w"] / 2.0 # type: ignore s["cx"] = _find_param(calib, "cx") + s["w"] / 2.0 # type: ignore
s["cy"] = _find_param(calib, "cy") + s["h"] / 2.0 # type: ignore s["cy"] = _find_param(calib, "cy") + s["h"] / 2.0 # type: ignore
s["k1"] = _find_param(calib, "k1") s["k1"] = _find_param(calib, "k1")
s["k2"] = _find_param(calib, "k2") s["k2"] = _find_param(calib, "k2")
s["k3"] = _find_param(calib, "k3") s["k3"] = _find_param(calib, "k3")
s["k4"] = _find_param(calib, "k4") s["k4"] = _find_param(calib, "k4")
s["p1"] = _find_param(calib, "p1") s["p1"] = _find_param(calib, "p1")
s["p2"] = _find_param(calib, "p2") s["p2"] = _find_param(calib, "p2")
sensor_dict[sensor.get("id")] = s sensor_dict[sensor.get("id")] = s
components = chunk.find("components") components = chunk.find("components")
if components is not None: component_dict = {}
component_dict = {} for component in components:
for component in components: transform = component.find("transform")
transform = component.find("transform") if transform is not None:
if transform is not None: rotation = transform.find("rotation")
rotation = transform.find("rotation") if rotation is None:
if rotation is None: r = np.eye(3)
r = np.eye(3) else:
else: r = np.array([float(x) for x in rotation.text.split()]).reshape((3, 3))
r = np.array([float(x) for x in rotation.text.split()]).reshape((3, 3)) translation = transform.find("translation")
translation = transform.find("translation") if translation is None:
if translation is None: t = np.zeros(3)
t = np.zeros(3) else:
else: t = np.array([float(x) for x in translation.text.split()])
t = np.array([float(x) for x in translation.text.split()]) scale = transform.find("scale")
scale = transform.find("scale") if scale is None:
if scale is None: s = 1.0
s = 1.0 else:
else: s = float(scale.text)
s = float(scale.text)
m = np.eye(4) m = np.eye(4)
m[:3, :3] = r m[:3, :3] = r
m[:3, 3] = t / s m[:3, 3] = t / s
component_dict[component.get("id")] = m component_dict[component.get("id")] = m
frames = [] frames = []
cameras = chunk.find("cameras") cameras = chunk.find("cameras")
@@ -172,10 +159,9 @@ def metashape_to_json( # pylint: disable=too-many-statements
num_skipped += 1 num_skipped += 1
continue continue
transform = np.array([float(x) for x in camera.find("transform").text.split()]).reshape((4, 4)) transform = np.array([float(x) for x in camera.find("transform").text.split()]).reshape((4, 4))
if components is not None: component_id = camera.get("component_id")
component_id = camera.get("component_id") if component_id in component_dict:
if component_id in component_dict: transform = component_dict[component_id] @ transform
transform = component_dict[component_id] @ transform
transform = transform[[2, 0, 1, 3], :] transform = transform[[2, 0, 1, 3], :]
transform[:, 1:3] *= -1 transform[:, 1:3] *= -1
frame["transform_matrix"] = transform.tolist() frame["transform_matrix"] = transform.tolist()
@@ -20,11 +20,12 @@ import shutil
import sys import sys
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
from typing import List, Literal, Optional, OrderedDict, Tuple from typing import List, Optional, Tuple
import cv2 import cv2
import numpy as np import numpy as np
from rich.console import Console from rich.console import Console
from typing_extensions import Literal, OrderedDict
from nerfstudio.utils.rich_utils import status from nerfstudio.utils.rich_utils import status
from nerfstudio.utils.scripts import run_command from nerfstudio.utils.scripts import run_command
@@ -38,13 +39,12 @@ class CameraModel(Enum):
OPENCV = "OPENCV" OPENCV = "OPENCV"
OPENCV_FISHEYE = "OPENCV_FISHEYE" OPENCV_FISHEYE = "OPENCV_FISHEYE"
EQUIRECTANGULAR = "EQUIRECTANGULAR"
CAMERA_MODELS = { CAMERA_MODELS = {
"perspective": CameraModel.OPENCV, "perspective": CameraModel.OPENCV,
"fisheye": CameraModel.OPENCV_FISHEYE, "fisheye": CameraModel.OPENCV_FISHEYE,
"equirectangular": CameraModel.EQUIRECTANGULAR, "equirectangular": CameraModel.OPENCV,
} }