Construct a camera intrinsic matrix from its parameters.
The camera intrinsic matrix K describes the internal parameters of a camera that transform 3D camera coordinates to 2D pixel coordinates:
K=fx00sfy0cxcy1
where:
fx,fy are the focal lengths in pixels (horizontal and vertical)
(cx,cy) is the principal point (usually near image center)
s is the skew coefficient (usually 0 for modern cameras)
The focal length in pixels is computed as: fpixels=fmm×sensor_widthimage_width
For a standard camera with square pixels, fx=fy and s=0.
Example
Input
intrinsic_matrix(1000, 1000, 320, 240, 0)
Output
[[1000, 0, 320], [0, 1000, 240], [0, 0, 1]]
Reasoning
Inputs:fx=1000 and fy=1000 are the horizontal and vertical focal lengths in pixels, (cx,cy)=(320,240) is the principal point (the centre of a 640×480 image), and skew=0 means the pixel axes are perfectly perpendicular.
Top row: horizontal pixel position depends on fx, the skew s and the offset cx, so it reads (1000,0,320).
Middle row: vertical position does not depend on the camera's x coordinate, so its first entry is 0; then fy=1000 and cy=240, giving (0,1000,240).
Bottom row:(0,0,1) never changes. It carries depth through so the result can be divided by it.
Check: a point on the optical axis, (0,0,1), maps to K(0,0,1)T=(320,240,1), which is exactly the principal point.
Output:[[1000, 0, 320], [0, 1000, 240], [0, 0, 1]], an upper triangular 3×3 matrix. Notice that a nonzero skew such as 0.1 would change only the top row, second column.
The task is to compute and assemble the 3×3 intrinsic matrixK from given camera parameters; conceptually this is a straightforward parameter-to-matrix mapping problem rather than an algorithmically complex one.
1. Background Knowledge
In pinhole camera geometry, a 3D point in camera coordinates(Xc,Yc,Zc) is projected to image (pixel) coordinates(u,v) via a projection equation of the form:
λuv1=KXcYcZc,
where K is the intrinsic matrix and λ is a scale factor. K encodes how real-world distances (in meters or millimeters) map to pixel units on the sensor, as well as where the principal point (optical center) lies in the image.
The intrinsic matrix is typically written as:
K=fx00sfy0cxcy1,
where:
fx,fy: focal length in pixels along x and y,
(cx,cy): principal point coordinates in pixels,
s: skew (non-orthogonality between image axes, usually 0 for modern cameras).
To get focal length in pixels from focal length in millimeters, you use the relationship between sensor size and image resolution:
fpixels=fmm×sensor_width_mmimage_width_pixels
(and similarly for height if needed).
2. Algorithm / Approach
This problem is essentially:
Convert focal length units (mm → pixels) using sensor size and image size.
Assign parameters into the 3×3 matrix in the correct positions.
Use known simplifications for standard cameras:
Square pixels: fx=fy,
Zero skew: s=0,
Principal point near image center: often (cx,cy)=(\frac{W}{2},\frac{H}{2}) if not otherwise specified.
The implementation pattern is: compute scalar parameters → construct a fixed‑shape matrix → return it.
3. Step-by-Step Strategy
Assuming you are given:
Focal length fmm in millimeters,
Sensor width (and optionally height) in millimeters,
Return or print the matrix in the required format (e.g., NumPy array).
4. Common Pitfalls
Mixing units:
Make sure all focal lengths are converted to pixels before filling K. Do not directly plug fmm into the matrix.
Using wrong image dimension:
When computing fpixels, match sensor width with image width, and sensor height with image height.
Integer vs float division:
In languages like Python 2 or some other languages, integer division can truncate. Ensure you use float division to get precise fx,fy.
Principal point off by 0.5:
Some conventions use (W/2,H/2), others (W/2−0.5,H/2−0.5). Follow the convention used by your platform or tests; in many educational problems, W/2,H/2 is expected.
Matrix order:
Do not swap rows or columns. The matrix must match the canonical form:
fx00sfy0cxcy1
5. Time & Space Complexity
Time complexity:
All operations are basic arithmetic and constant-size matrix construction, so O(1).
Space complexity:
You store a fixed 3×3 matrix and a few scalars, so O(1) additional space.