mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 07:48:50 +08:00
undo process_data change
This commit is contained in:
1 parent
c9151d4a90
commit
ee35703db8
4 files changed
+13
-24
No files matched your search
@@ -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 = [
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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,15 +87,8 @@ 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:
|
|
||||||
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")
|
f = calib.find("f")
|
||||||
assert f is not None, "Focal length not found in Metashape xml"
|
if f is not None:
|
||||||
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
|
||||||
@@ -115,7 +103,6 @@ def metashape_to_json( # pylint: disable=too-many-statements
|
|||||||
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")
|
||||||
@@ -172,7 +159,6 @@ 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
|
||||||
|
|||||||
@@ -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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user