4
0
mirror of https://github.com/nerfstudio-project/nerfstudio.git synced 2026-11-11 02:24:38 +08:00

undo process_data change

This commit is contained in:
terrance 2023-05-12 18:48:58 +00:00
parent c9151d4a90
commit ee35703db8
4 changed files with 48 additions and 59 deletions

View File

@ -13,12 +13,12 @@
# 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
from pathlib import Path
from typing import Any, Dict, Literal, Optional
from typing import Any, Dict, Optional
import appdirs
import cv2
@ -27,6 +27,7 @@ import requests
import torch
from rich.console import Console
from rich.progress import track
from typing_extensions import Literal
# TODO(1480) use pycolmap instead of colmap_parsing_utils
# import pycolmap
@ -114,7 +115,9 @@ def run_colmap(
colmap_version = get_colmap_version(colmap_cmd)
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_extractor_cmd = [

View File

@ -21,9 +21,9 @@ Requires hloc module from : https://github.com/cvg/Hierarchical-Localization
import sys
from pathlib import Path
from typing import Literal
from rich.console import Console
from typing_extensions import Literal
from nerfstudio.process_data.process_data_utils import CameraModel

View File

@ -61,17 +61,12 @@ def metashape_to_json( # pylint: disable=too-many-statements
if sensors is None:
raise ValueError("No sensors found")
calibrated_sensors = [
sensor for sensor in sensors if sensor.get("type") == "spherical" or sensor.find("calibration")
]
calibrated_sensors = [sensor for sensor in sensors if sensor.find("calibration")]
if not calibrated_sensors:
raise ValueError("No calibrated sensor found in Metashape XML")
sensor_type = [s.get("type") for s in calibrated_sensors]
if sensor_type.count(sensor_type[0]) != len(sensor_type):
raise ValueError(
"All Metashape sensors do not have the same sensor type. "
"nerfstudio does not support per-frame camera_model."
)
raise ValueError("All Metashape sensors do not have the same sensor type")
data = {}
if sensor_type[0] == "frame":
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
calib = sensor.find("calibration")
if calib is None:
assert sensor_type[0] == "spherical", "Only spherical sensors should have no intrinsics"
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"
f = calib.find("f")
if f is not None:
s["fl_x"] = s["fl_y"] = float(f.text) # 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["cx"] = _find_param(calib, "cx") + s["w"] / 2.0 # type: ignore
s["cy"] = _find_param(calib, "cy") + s["h"] / 2.0 # type: ignore
s["k1"] = _find_param(calib, "k1")
s["k2"] = _find_param(calib, "k2")
s["k3"] = _find_param(calib, "k3")
s["k4"] = _find_param(calib, "k4")
s["p1"] = _find_param(calib, "p1")
s["p2"] = _find_param(calib, "p2")
s["k1"] = _find_param(calib, "k1")
s["k2"] = _find_param(calib, "k2")
s["k3"] = _find_param(calib, "k3")
s["k4"] = _find_param(calib, "k4")
s["p1"] = _find_param(calib, "p1")
s["p2"] = _find_param(calib, "p2")
sensor_dict[sensor.get("id")] = s
components = chunk.find("components")
if components is not None:
component_dict = {}
for component in components:
transform = component.find("transform")
if transform is not None:
rotation = transform.find("rotation")
if rotation is None:
r = np.eye(3)
else:
r = np.array([float(x) for x in rotation.text.split()]).reshape((3, 3))
translation = transform.find("translation")
if translation is None:
t = np.zeros(3)
else:
t = np.array([float(x) for x in translation.text.split()])
scale = transform.find("scale")
if scale is None:
s = 1.0
else:
s = float(scale.text)
component_dict = {}
for component in components:
transform = component.find("transform")
if transform is not None:
rotation = transform.find("rotation")
if rotation is None:
r = np.eye(3)
else:
r = np.array([float(x) for x in rotation.text.split()]).reshape((3, 3))
translation = transform.find("translation")
if translation is None:
t = np.zeros(3)
else:
t = np.array([float(x) for x in translation.text.split()])
scale = transform.find("scale")
if scale is None:
s = 1.0
else:
s = float(scale.text)
m = np.eye(4)
m[:3, :3] = r
m[:3, 3] = t / s
component_dict[component.get("id")] = m
m = np.eye(4)
m[:3, :3] = r
m[:3, 3] = t / s
component_dict[component.get("id")] = m
frames = []
cameras = chunk.find("cameras")
@ -172,10 +159,9 @@ def metashape_to_json( # pylint: disable=too-many-statements
num_skipped += 1
continue
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")
if component_id in component_dict:
transform = component_dict[component_id] @ transform
component_id = camera.get("component_id")
if component_id in component_dict:
transform = component_dict[component_id] @ transform
transform = transform[[2, 0, 1, 3], :]
transform[:, 1:3] *= -1
frame["transform_matrix"] = transform.tolist()

View File

@ -20,11 +20,12 @@ import shutil
import sys
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional, OrderedDict, Tuple
from typing import List, Optional, Tuple
import cv2
import numpy as np
from rich.console import Console
from typing_extensions import Literal, OrderedDict
from nerfstudio.utils.rich_utils import status
from nerfstudio.utils.scripts import run_command
@ -38,13 +39,12 @@ class CameraModel(Enum):
OPENCV = "OPENCV"
OPENCV_FISHEYE = "OPENCV_FISHEYE"
EQUIRECTANGULAR = "EQUIRECTANGULAR"
CAMERA_MODELS = {
"perspective": CameraModel.OPENCV,
"fisheye": CameraModel.OPENCV_FISHEYE,
"equirectangular": CameraModel.EQUIRECTANGULAR,
"equirectangular": CameraModel.OPENCV,
}