allow ns-process-data to use CR2 raw images (#2119)

* allow ns-process-data to use CR2 raw images

* Update process_data_utils.py

* black wants an extra newline

---------

Co-authored-by: Matias Turkulainen <30566358+maturk@users.noreply.github.com>
This commit is contained in:
machenmusikandMatias Turkulainen authored and GitHub committed 2023-06-27 16:02:58 -04:00
1 parent d9ee5752d2
commit d78af5b569
2 files changed
+19 -2

No files matched your search

+18 -2
View File
@@ -25,11 +25,19 @@ from typing import List, Literal, Optional, OrderedDict, Tuple, Union
import cv2
import numpy as np
import imageio
import rawpy
from nerfstudio.utils.rich_utils import CONSOLE, status
from nerfstudio.utils.scripts import run_command
POLYCAM_UPSCALING_TIMES = 2
"""Lowercase suffixes to treat as raw image."""
ALLOWED_RAW_EXTS = [".cr2"]
"""Suffix to use for converted images from raw."""
RAW_CONVERTED_SUFFIX = ".tiff"
class CameraModel(Enum):
"""Enum for camera types."""
@@ -54,7 +62,7 @@ def list_images(data: Path) -> List[Path]:
Returns:
Paths to images contained in the directory
"""
allowed_exts = [".jpg", ".jpeg", ".png", ".tif", ".tiff"]
allowed_exts = [".jpg", ".jpeg", ".png", ".tif", ".tiff"] + ALLOWED_RAW_EXTS
image_paths = sorted([p for p in data.glob("[!.]*") if p.suffix.lower() in allowed_exts])
return image_paths
@@ -209,7 +217,15 @@ def copy_images_list(
CONSOLE.log(f"Copying image {idx + 1} of {len(image_paths)}...")
copied_image_path = image_dir / f"frame_{idx + 1:05d}{image_path.suffix}"
try:
shutil.copy(image_path, copied_image_path)
# if CR2 raw, we want to read raw and write TIFF, and change the file suffix for downstream processing
if image_path.suffix.lower() in ALLOWED_RAW_EXTS:
copied_image_path = image_dir / f"frame_{idx + 1:05d}{RAW_CONVERTED_SUFFIX}"
with rawpy.imread(str(image_path)) as raw:
rgb = raw.postprocess()
imageio.imsave(copied_image_path, rgb)
image_paths[idx] = copied_image_path
else:
shutil.copy(image_path, copied_image_path)
except shutil.SameFileError:
pass
copied_image_paths.append(copied_image_path)
+1
View File
@@ -43,6 +43,7 @@ dependencies = [
"pyngrok>=5.1.0",
"python-socketio>=5.7.1",
"pyquaternion>=0.9.9",
"rawpy>=0.18.1",
"requests",
"rich>=12.5.1",
"scikit-image>=0.19.3",