mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-21 07:05:44 +08:00
Final typing fixes + add Pyright to CI (#1944)
* knocking out a couple * Fix more errors * Add pyright * Remove some unnecessary cv2 type ignores, warning on missing imports (for missing tinycudann) * Minor annotation fixes * Update docs * Drop `None` from temporal distortion output --------- Co-authored-by: Brent Yi <yibrenth@gmail.com>
This commit is contained in:
1 parent
08e3a1f1a6
commit
2b0831b6d4
28 files changed
+110
-71
No files matched your search
@@ -203,6 +203,10 @@ class ColmapConverterToNerfstudioDataset(BaseConverterToNerfstudioDataset):
|
||||
elif sfm_tool == "hloc":
|
||||
if mask_path is not None:
|
||||
raise RuntimeError("Cannot use a mask with hloc. Please remove the cropping options " "and try again.")
|
||||
|
||||
assert feature_type is not None
|
||||
assert matcher_type is not None
|
||||
assert matcher_type != "NN" # Only used for colmap.
|
||||
hloc_utils.run_hloc(
|
||||
image_dir=self.image_dir,
|
||||
colmap_dir=self.absolute_colmap_path,
|
||||
|
||||
@@ -582,7 +582,7 @@ def create_sfm_depth(
|
||||
|
||||
out_name = str(im_data.name)
|
||||
depth_path = output_dir / out_name
|
||||
cv2.imwrite(str(depth_path), depth_img)
|
||||
cv2.imwrite(str(depth_path), depth_img) # type: ignore
|
||||
|
||||
image_id_to_depth_path[im_id] = depth_path
|
||||
|
||||
@@ -594,13 +594,13 @@ def create_sfm_depth(
|
||||
overlay = 255.0 * colormaps.apply_depth_colormap(torch.from_numpy(depth_flat)).numpy()
|
||||
overlay = overlay.reshape([H, W, 3])
|
||||
input_image_path = input_images_dir / im_data.name
|
||||
input_image = cv2.imread(str(input_image_path))
|
||||
input_image = cv2.imread(str(input_image_path)) # type: ignore
|
||||
debug = 0.3 * input_image + 0.7 + overlay
|
||||
|
||||
out_name = out_name + ".debug.jpg"
|
||||
output_path = output_dir / "debug_depth" / out_name
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
cv2.imwrite(str(output_path), debug.astype(np.uint8))
|
||||
cv2.imwrite(str(output_path), debug.astype(np.uint8)) # type: ignore
|
||||
|
||||
return image_id_to_depth_path
|
||||
|
||||
|
||||
@@ -190,6 +190,7 @@ def generate_planar_projections_from_equirectangular(
|
||||
v_rad = torch.pi * v_deg / 180.0
|
||||
u_rad = torch.pi * u_deg / 180.0
|
||||
pers_image = equi2pers(im, rots={"roll": 0, "pitch": v_rad, "yaw": u_rad}) * 255.0
|
||||
assert isinstance(pers_image, torch.Tensor)
|
||||
pers_image = (pers_image.permute(1, 2, 0)).type(torch.uint8).to("cpu").numpy()
|
||||
cv2.imwrite(f"{output_dir}/{i[:-4]}_{count}.jpg", pers_image)
|
||||
count += 1
|
||||
|
||||
@@ -42,7 +42,7 @@ else:
|
||||
_HAS_HLOC = True
|
||||
|
||||
try:
|
||||
from pixsfm.refine_hloc import PixSfM
|
||||
from pixsfm.refine_hloc import PixSfM # type: ignore
|
||||
except ImportError:
|
||||
_HAS_PIXSFM = False
|
||||
else:
|
||||
|
||||
@@ -395,7 +395,7 @@ def find_tool_feature_matcher_combination(
|
||||
"sosnet",
|
||||
"disk",
|
||||
],
|
||||
Literal["superglue", "superglue-fast", "NN-superpoint", "NN-ratio", "NN-mutual", "adalam"],
|
||||
Literal["NN", "superglue", "superglue-fast", "NN-superpoint", "NN-ratio", "NN-mutual", "adalam"],
|
||||
],
|
||||
]:
|
||||
"""Find a valid combination of sfm tool, feature type, and matcher type.
|
||||
@@ -452,7 +452,7 @@ def generate_circle_mask(height: int, width: int, percent_radius) -> Optional[np
|
||||
mask = np.zeros((height, width), dtype=np.uint8)
|
||||
center = (width // 2, height // 2)
|
||||
radius = int(percent_radius * np.sqrt(width**2 + height**2) / 2.0)
|
||||
cv2.circle(mask, center, radius, 1, -1) # type: ignore
|
||||
cv2.circle(mask, center, radius, 1, -1)
|
||||
return mask
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ def save_mask(
|
||||
The path to the mask file or None if no mask is needed.
|
||||
"""
|
||||
image_path = next(image_dir.glob("frame_*"))
|
||||
image = cv2.imread(str(image_path)) # type: ignore
|
||||
image = cv2.imread(str(image_path))
|
||||
height, width = image.shape[:2]
|
||||
mask = generate_mask(height, width, crop_factor, percent_radius)
|
||||
if mask is None:
|
||||
@@ -531,17 +531,17 @@ def save_mask(
|
||||
mask *= 255
|
||||
mask_path = image_dir.parent / "masks"
|
||||
mask_path.mkdir(exist_ok=True)
|
||||
cv2.imwrite(str(mask_path / "mask.png"), mask) # type: ignore
|
||||
cv2.imwrite(str(mask_path / "mask.png"), mask)
|
||||
downscale_factors = [2**i for i in range(num_downscales + 1)[1:]]
|
||||
for downscale in downscale_factors:
|
||||
mask_path_i = image_dir.parent / f"masks_{downscale}"
|
||||
mask_path_i.mkdir(exist_ok=True)
|
||||
mask_path_i = mask_path_i / "mask.png"
|
||||
mask_i = cv2.resize( # type: ignore
|
||||
mask_i = cv2.resize(
|
||||
mask,
|
||||
(width // downscale, height // downscale),
|
||||
interpolation=cv2.INTER_NEAREST, # type: ignore
|
||||
interpolation=cv2.INTER_NEAREST,
|
||||
)
|
||||
cv2.imwrite(str(mask_path_i), mask_i) # type: ignore
|
||||
cv2.imwrite(str(mask_path_i), mask_i)
|
||||
CONSOLE.log(":tada: Generated and saved masks.")
|
||||
return mask_path / "mask.png"
|
||||
@@ -17,7 +17,7 @@
|
||||
import csv
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from typing import Dict, List
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
@@ -27,7 +27,7 @@ from nerfstudio.utils.rich_utils import CONSOLE
|
||||
|
||||
|
||||
def realitycapture_to_json(
|
||||
image_filename_map: List[Path],
|
||||
image_filename_map: Dict[str, Path],
|
||||
csv_filename: Path,
|
||||
output_dir: Path,
|
||||
verbose: bool = False,
|
||||
|
||||
Reference in new issue
Block a user