Spaces:
Sleeping
Sleeping
feat: add sensor width constant and update FOV calculation; create .gitignore
Browse files- .gitignore +4 -0
- app.py +8 -5
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.DS_Store
|
| 2 |
+
*.ply
|
| 3 |
+
*.settings.json
|
| 4 |
+
__pycache__/
|
app.py
CHANGED
|
@@ -33,6 +33,7 @@ DEFAULT_SETTINGS_JSON: Final[Path] = VIEWER_DIR / "settings.default.json"
|
|
| 33 |
DEFAULT_QUEUE_MAX_SIZE: Final[int] = 32
|
| 34 |
DEFAULT_FOCAL_LENGTH_MM: Final[float] = 35.0
|
| 35 |
SENSOR_HEIGHT_MM: Final[float] = 24.0 # Full-frame 35mm equivalent
|
|
|
|
| 36 |
|
| 37 |
# Register static paths for Gradio 6 file serving
|
| 38 |
gr.set_static_paths(paths=[str(VIEWER_DIR), str(OUTPUTS_DIR)])
|
|
@@ -245,14 +246,16 @@ _ensure_dir(VIEWER_DIR)
|
|
| 245 |
# -----------------------------------------------------------------------------
|
| 246 |
|
| 247 |
|
| 248 |
-
def focal_length_to_fov(focal_length_mm: float, sensor_height_mm: float = SENSOR_HEIGHT_MM) -> float:
|
| 249 |
-
"""Convert focal length (mm) to
|
| 250 |
|
| 251 |
-
Uses the formula: FOV = 2 * atan(
|
|
|
|
| 252 |
"""
|
| 253 |
if focal_length_mm <= 0:
|
| 254 |
focal_length_mm = DEFAULT_FOCAL_LENGTH_MM
|
| 255 |
-
|
|
|
|
| 256 |
return math.degrees(fov_rad)
|
| 257 |
|
| 258 |
|
|
@@ -264,7 +267,7 @@ def create_settings_file(focal_length_mm: float, output_stem: str) -> Path:
|
|
| 264 |
settings = {
|
| 265 |
"camera": {
|
| 266 |
"fov": fov,
|
| 267 |
-
"position": [0, 0,
|
| 268 |
"target": [0, 0, 0],
|
| 269 |
"startAnim": "none",
|
| 270 |
"animTrack": ""
|
|
|
|
| 33 |
DEFAULT_QUEUE_MAX_SIZE: Final[int] = 32
|
| 34 |
DEFAULT_FOCAL_LENGTH_MM: Final[float] = 35.0
|
| 35 |
SENSOR_HEIGHT_MM: Final[float] = 24.0 # Full-frame 35mm equivalent
|
| 36 |
+
SENSOR_WIDTH_MM: Final[float] = 36.0 # Full-frame 35mm width
|
| 37 |
|
| 38 |
# Register static paths for Gradio 6 file serving
|
| 39 |
gr.set_static_paths(paths=[str(VIEWER_DIR), str(OUTPUTS_DIR)])
|
|
|
|
| 246 |
# -----------------------------------------------------------------------------
|
| 247 |
|
| 248 |
|
| 249 |
+
def focal_length_to_fov(focal_length_mm: float, sensor_height_mm: float = SENSOR_HEIGHT_MM, sensor_width_mm: float = SENSOR_WIDTH_MM) -> float:
|
| 250 |
+
"""Convert focal length (mm) to diagonal field of view (degrees).
|
| 251 |
|
| 252 |
+
Uses the formula: FOV = 2 * atan(diagonal / (2 * focal_length))
|
| 253 |
+
where diagonal = sqrt(width^2 + height^2) for full-frame 35mm (36x24mm)
|
| 254 |
"""
|
| 255 |
if focal_length_mm <= 0:
|
| 256 |
focal_length_mm = DEFAULT_FOCAL_LENGTH_MM
|
| 257 |
+
diagonal_mm = math.sqrt(sensor_width_mm**2 + sensor_height_mm**2)
|
| 258 |
+
fov_rad = 2 * math.atan(diagonal_mm / (2 * focal_length_mm))
|
| 259 |
return math.degrees(fov_rad)
|
| 260 |
|
| 261 |
|
|
|
|
| 267 |
settings = {
|
| 268 |
"camera": {
|
| 269 |
"fov": fov,
|
| 270 |
+
"position": [0, 0, 0],
|
| 271 |
"target": [0, 0, 0],
|
| 272 |
"startAnim": "none",
|
| 273 |
"animTrack": ""
|