Camera Matrix Computation and Resizing
1. Camera Matrix Computation
Given Parameters
- Sensor Size: 1/2.3" (6.17 mm x 4.55 mm)
- Focal Length (actual): 3.61 mm
- Image Size (4K): 3840 x 2160 pixels
Formulas
To compute the camera matrix, use the following formulas for ( fx ) and ( fy ):
f
x
=
f
×
w
s
w
fx = \frac{f \times w}{s_w}
fx=swf×w
f
y
=
f
×
h
s
h
fy = \frac{f \times h}{s_h}
fy=shf×h
Where:
- f : Focal length (3.61 mm)
- ( w ): Image width in pixels (3840)
- ( h ): Image height in pixels (2160)
- ( s_w ): Sensor width (6.17 mm)
- ( s_h ): Sensor height (4.55 mm)
Calculation
-
Calculate ( fx ):
f x = 3.61 × 3840 6.17 ≈ 2252.38 fx = \frac{3.61 \times 3840}{6.17} \approx 2252.38 fx=6.173.61×3840≈2252.38 -
Calculate ( fy ):
f y = 3.61 × 2160 4.55 ≈ 1707.60 fy = \frac{3.61 \times 2160}{4.55} \approx 1707.60 fy=4.553.61×2160≈1707.60 -
Principal Points:
c x = 3840 2 = 1920 , c y = 2160 2 = 1080 cx = \frac{3840}{2} = 1920, cy = \frac{2160}{2} = 1080 cx=23840=1920,cy=22160=1080
Camera Matrix
The camera matrix ( K ) is structured as follows:
K = [ f x 0 c x 0 f y c y 0 0 1 ] K = \begin{bmatrix} fx & 0 & cx \\ 0 & fy & cy \\ 0 & 0 & 1 \end{bmatrix} K= fx000fy0cxcy1
Substituting the values:
import numpy as np
fx = 2252.38
fy = 1707.60
cx = 1920
cy = 1080
camera_matrix = np.array([[fx, 0, cx],
[0, fy, cy],
[0, 0, 1]], dtype=np.float32)
print("Camera Matrix:")
print(camera_matrix)
2. Adjusting Camera Matrix After Resizing
New Image Size
If the image is resized to half its dimensions:
- New Width: ( 3840 / 2 = 1920 )
- New Height: ( 2160 / 2 = 1080 )
Adjusting Parameters
-
Focal Lengths:
f x ′ = f x 2 ≈ 1126.19 fx' = \frac{fx}{2} \approx 1126.19 fx′=2fx≈1126.19
f y ′ = f y 2 ≈ 853.80 fy' = \frac{fy}{2} \approx 853.80 fy′=2fy≈853.80 -
Principal Points:
c x ′ = c x 2 = 960 cx' = \frac{cx}{2} = 960 cx′=2cx=960
c y ′ = c y 2 = 540 cy' = \frac{cy}{2} = 540 cy′=2cy=540
New Camera Matrix
The adjusted camera matrix for the resized image is:
# New camera matrix for resized image
fx_prime = 1126.19
fy_prime = 853.80
cx_prime = 960
cy_prime = 540
camera_matrix_resized = np.array([[fx_prime, 0, cx_prime],
[0, fy_prime, cy_prime],
[0, 0, 1]], dtype=np.float32)
print("Resized Camera Matrix:")
print(camera_matrix_resized)