mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 05:48:57 +08:00
Solve the bug for camera calibration
This commit is contained in:
1 parent
e504c1f2f8
commit
08aaf0cb80
3 files changed
+37
-27
No files matched your search
@@ -25,12 +25,20 @@ if __name__ == '__main__':
|
|||||||
os.makedirs(output_folder, exist_ok=True)
|
os.makedirs(output_folder, exist_ok=True)
|
||||||
|
|
||||||
# Run FFmpeg command to convert video to PNG frames
|
# Run FFmpeg command to convert video to PNG frames
|
||||||
command = [
|
if video_name == 'left_sfm' or video_name == 'right_sfm':
|
||||||
"ffmpeg",
|
command = [
|
||||||
"-i", video,
|
"ffmpeg",
|
||||||
"-vf", "fps=29.97",
|
"-i", video,
|
||||||
f"{output_folder}/output_%04d.png"
|
"-vf", "fps=4.0",
|
||||||
]
|
f"{output_folder}/output_%04d.png"
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
command = [
|
||||||
|
"ffmpeg",
|
||||||
|
"-i", video,
|
||||||
|
"-vf", "fps=15.0",
|
||||||
|
f"{output_folder}/output_%04d.png"
|
||||||
|
]
|
||||||
subprocess.run(command, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
subprocess.run(command, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
# only keep frames where mod 10 = 0
|
# only keep frames where mod 10 = 0
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class NerfstudioDataParserConfig(DataParserConfig):
|
|||||||
"""The method to use for orientation."""
|
"""The method to use for orientation."""
|
||||||
center_method: Literal["poses", "focus", "none"] = "poses"
|
center_method: Literal["poses", "focus", "none"] = "poses"
|
||||||
"""The method to use to center the poses."""
|
"""The method to use to center the poses."""
|
||||||
auto_scale_poses: bool = False
|
auto_scale_poses: bool = True
|
||||||
"""Whether to automatically scale the poses to fit in +/- 1 bounding box."""
|
"""Whether to automatically scale the poses to fit in +/- 1 bounding box."""
|
||||||
train_split_fraction: float = 0.9
|
train_split_fraction: float = 0.9
|
||||||
"""The fraction of images to use for training. The remaining images are for eval."""
|
"""The fraction of images to use for training. The remaining images are for eval."""
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class OpenSFMToNeRFStudioDataset(BaseConverterToNerfstudioDataset):
|
|||||||
"""If True, skips copying and downscaling of images and only runs COLMAP if possible and enabled"""
|
"""If True, skips copying and downscaling of images and only runs COLMAP if possible and enabled"""
|
||||||
is_HDR: bool = False
|
is_HDR: bool = False
|
||||||
"""If True, process the .exr files as HDR images."""
|
"""If True, process the .exr files as HDR images."""
|
||||||
use_mask: bool = False
|
use_mask: bool = True
|
||||||
"""If True, process the .exr files with mask."""
|
"""If True, process the .exr files with mask."""
|
||||||
use_exposure: bool = False
|
use_exposure: bool = False
|
||||||
"""If True, using different exposures."""
|
"""If True, using different exposures."""
|
||||||
@@ -148,6 +148,9 @@ class OpenSFMToNeRFStudioDataset(BaseConverterToNerfstudioDataset):
|
|||||||
frames_names = openSFM_reconstruction[0]['shots'].keys()
|
frames_names = openSFM_reconstruction[0]['shots'].keys()
|
||||||
frames_names = sorted(frames_names)
|
frames_names = sorted(frames_names)
|
||||||
|
|
||||||
|
# Remove GT files from the training sets
|
||||||
|
frames_names = list(set(frames_names) - set( [x for x in frames_names if x.startswith('GT')]))
|
||||||
|
|
||||||
# Computing the basis transform matrix
|
# Computing the basis transform matrix
|
||||||
rot_list = []
|
rot_list = []
|
||||||
trn_list = []
|
trn_list = []
|
||||||
@@ -209,26 +212,25 @@ class OpenSFMToNeRFStudioDataset(BaseConverterToNerfstudioDataset):
|
|||||||
# Convert OpenSFM coordinates to the NeRFStudio
|
# Convert OpenSFM coordinates to the NeRFStudio
|
||||||
camera_dict = {}
|
camera_dict = {}
|
||||||
camera_dict["frames"] = []
|
camera_dict["frames"] = []
|
||||||
for idx, fname in enumerate(frames_names):
|
for idx, fname in enumerate([x for x in frames_names if x.startswith('left_e1')]):
|
||||||
# if fname.startswith("left_sfm"):
|
# if fname.startswith("left_sfm"):
|
||||||
if fname.startswith("left_e1"):
|
right_fname = fname.replace("left_e1", "right_e2")
|
||||||
right_fname = fname.replace("left_e1", "right_e2")
|
# right_fname = fname.replace("left_sfm", "right_sfm")
|
||||||
# right_fname = fname.replace("left_sfm", "right_sfm")
|
shot_data = openSFM_reconstruction[0]['shots'][fname]
|
||||||
shot_data = openSFM_reconstruction[0]['shots'][fname]
|
left_C2W, left_rvec, left_tvec = opensfm_to_opengl(shot_data)
|
||||||
left_C2W, left_rvec, left_tvec = opensfm_to_opengl(shot_data)
|
if valid_idx[idx]:
|
||||||
if valid_idx[idx]:
|
camera_dict["frames"].append(
|
||||||
camera_dict["frames"].append(
|
{
|
||||||
{
|
"file_path": fname.split('.')[0],
|
||||||
"file_path": fname.split('.')[0],
|
"transform_matrix": left_C2W.tolist()
|
||||||
"transform_matrix": left_C2W.tolist()
|
})
|
||||||
})
|
|
||||||
|
right_C2W = left_C2W @ basis_change
|
||||||
right_C2W = left_C2W @ basis_change
|
camera_dict["frames"].append(
|
||||||
camera_dict["frames"].append(
|
{
|
||||||
{
|
"file_path": right_fname.split('.')[0],
|
||||||
"file_path": right_fname.split('.')[0],
|
"transform_matrix": right_C2W.tolist()
|
||||||
"transform_matrix": right_C2W.tolist()
|
})
|
||||||
})
|
|
||||||
|
|
||||||
with open(self.output_dir / 'panoramic_transforms.json', 'w') as f:
|
with open(self.output_dir / 'panoramic_transforms.json', 'w') as f:
|
||||||
json.dump(camera_dict, f, indent=4)
|
json.dump(camera_dict, f, indent=4)
|
||||||
|
|||||||
Reference in new issue
Block a user