Pywayne Camera Model
This module wraps the camera_models C++ library via pybind11, providing a Python interface for camera operations.
Quick Start
from pywayne.cv.camera_model import CameraModel
from pywayne.cv.tools import write_cv_yaml
import numpy as np
# Create camera model
camera = CameraModel()
# Load from YAML file
camera.load_from_yaml('camera_config.yaml')
# Access properties
print(f"Model: {camera.model_type}")
print(f"Size: {camera.image_width}x{camera.image_height}")
Loading from YAML
from pathlib import Path
# Sample YAML configuration
yaml_data = {
"model_type": "PINHOLE",
"camera_name": "my_camera",
"image_width": 1280,
"image_height": 720,
"distortion_parameters": {"k1": 0.0, "k2": 0.0},
"projection_parameters": {"fx": 600.0, "fy": 600.0, "cx": 640.0, "cy": 360.0}
}
# Write YAML file
write_cv_yaml('camera_config.yaml', yaml_data)
# Load model
camera.load_from_yaml('camera_config.yaml')
Supported Camera Models
| Model Type |
Description |
PINHOLE |
Standard pinhole camera with radial distortion |
PINHOLE_FULL |
Full pinhole model with all distortion parameters |
CATA |
Catadioptric camera model |
EQUIDISTANT |
Equidistant camera model |
OCAM |
Unified camera model |
Projection Operations
lift_projective()
Lifts a 2D image point to a 3D projective ray:
# Input can be tuple, list, or numpy array
ray_3d = camera.lift_projective([u, v]) # Returns np.ndarray (x, y, z)
space_to_plane()
Projects a 3D point onto the 2D image plane:
# Input can be tuple, list, or numpy array
uv = camera.space_to_plane([x, y, z]) # Returns np.ndarray (u, v)
Properties
| Property |
Description |
model_type |
Camera model type (enum) |
camera_name |
Name of the loaded camera |
image_width |
Image width in pixels |
image_height |
Image height in pixels |
Parameters Dictionary
Export all camera parameters as a dictionary:
params = camera.get_parameters_as_dict()
print(params)
Includes model-specific parameters:
- Pinhole:
k1, k2, p1, p2, fx, fy, cx, cy
- Pinhole Full:
k1-k6, p1-p2, fx, fy, cx, cy
- CATA:
xi, k1-k2, p1-p2, gamma1-2, u0, v0
- Equidistant:
k2-k5, mu, mv, u0, v0
- OCAM:
C, D, E, center_x, center_y, poly, inv_poly
Requirements
camera_models - C++ library (auto-downloaded via gettool if missing)
numpy - Array operations
pywayne.cv.tools.write_cv_yaml - For writing YAML files
Notes
- Library is automatically checked and downloaded via
gettool if not found
- Supports both tuple/list and numpy array inputs for projection methods
- Output from projection methods is always
np.ndarray with dtype=np.float64
1---2name: pywayne-cv-camera-model3description: Camera model wrapper for camera_models C++ library via pybind11. Use when working with pywayne.cv.camera_model module to load camera models from YAML configuration files, access camera properties (model type, image size, parameters), perform projection operations (lift_projective, space_to_plane), and export camera parameters as dictionaries.4---5
6# Pywayne Camera Model
7
8This module wraps the `camera_models` C++ library via pybind11, providing a Python interface for camera operations.
9
10## Quick Start
11
12```python
13from pywayne.cv.camera_model import CameraModel
14from pywayne.cv.tools import write_cv_yaml
15import numpy as np
16
17# Create camera model
18camera = CameraModel()
19
20# Load from YAML file
21camera.load_from_yaml('camera_config.yaml')
22
23# Access properties
24print(f"Model: {camera.model_type}")
25print(f"Size: {camera.image_width}x{camera.image_height}")
26```
27
28## Loading from YAML
29
30```python
31from pathlib import Path
32
33# Sample YAML configuration
34yaml_data = {
35 "model_type": "PINHOLE",
36 "camera_name": "my_camera",
37 "image_width": 1280,
38 "image_height": 720,
39 "distortion_parameters": {"k1": 0.0, "k2": 0.0},
40 "projection_parameters": {"fx": 600.0, "fy": 600.0, "cx": 640.0, "cy": 360.0}
41}
42
43# Write YAML file
44write_cv_yaml('camera_config.yaml', yaml_data)
45
46# Load model
47camera.load_from_yaml('camera_config.yaml')
48```
49
50## Supported Camera Models
51
52| Model Type | Description |
53|------------|-------------|
54| `PINHOLE` | Standard pinhole camera with radial distortion |
55| `PINHOLE_FULL` | Full pinhole model with all distortion parameters |
56| `CATA` | Catadioptric camera model |
57| `EQUIDISTANT` | Equidistant camera model |
58| `OCAM` | Unified camera model |
59
60## Projection Operations
61
62### lift_projective()
63
64Lifts a 2D image point to a 3D projective ray:
65
66```python
67# Input can be tuple, list, or numpy array
68ray_3d = camera.lift_projective([u, v]) # Returns np.ndarray (x, y, z)
69```
70
71### space_to_plane()
72
73Projects a 3D point onto the 2D image plane:
74
75```python
76# Input can be tuple, list, or numpy array
77uv = camera.space_to_plane([x, y, z]) # Returns np.ndarray (u, v)
78```
79
80## Properties
81
82| Property | Description |
83|---------|-------------|
84| `model_type` | Camera model type (enum) |
85| `camera_name` | Name of the loaded camera |
86| `image_width` | Image width in pixels |
87| `image_height` | Image height in pixels |
88
89## Parameters Dictionary
90
91Export all camera parameters as a dictionary:
92
93```python
94params = camera.get_parameters_as_dict()
95print(params)
96```
97
98Includes model-specific parameters:
99- **Pinhole**: `k1`, `k2`, `p1`, `p2`, `fx`, `fy`, `cx`, `cy`
100- **Pinhole Full**: `k1-k6`, `p1-p2`, `fx`, `fy`, `cx`, `cy`
101- **CATA**: `xi`, `k1-k2`, `p1-p2`, `gamma1-2`, `u0`, `v0`
102- **Equidistant**: `k2-k5`, `mu`, `mv`, `u0`, `v0`
103- **OCAM**: `C`, `D`, `E`, `center_x`, `center_y`, `poly`, `inv_poly`
104
105## Requirements
106
107- `camera_models` - C++ library (auto-downloaded via gettool if missing)
108- `numpy` - Array operations
109- `pywayne.cv.tools.write_cv_yaml` - For writing YAML files
110
111## Notes
112
113- Library is automatically checked and downloaded via `gettool` if not found
114- Supports both tuple/list and numpy array inputs for projection methods
115- Output from projection methods is always `np.ndarray` with `dtype=np.float64`