# Pinhole camera model

The pinhole camera model describes the mathematical relationship between the coordinates of a 3D point and its projection onto the image plane of an ideal pinhole camera, where the camera aperture is described as a point and no lenses are used to focus light. The model does not include, for example, geometric distortions or blurring of unfocused objects caused by lenses and finite sized apertures. It also does not take into account that most practical cameras have only discrete image coordinates. This means that the pinhole camera model can only be used as a first order approximation of the mapping from a 3D scene to a 2D image. Its validity depends on the quality of the camera and, in general, decreases from the center of the image to the edges as lens distortion effects increase.

Some of the effects that the pinhole camera model does not take into account can be compensated, for example by applying suitable coordinate transformations on the image coordinates, and other effects are sufficiently small to be neglected if a high quality camera is used. This means that the pinhole camera model often can be used as a reasonable description of how a camera depicts a 3D scene, for example in computer vision and computer graphics.

## The geometry and mathematics of the pinhole camera

The geometry related to the mapping of a pinhole camera is illustrated in the figure. (NOTE: The x1-x2-x3 coordinate system in the figure is left-handed, which is risky to one's intuition. A right-handed system may be used, instead). The figure contains the following basic objects

• A 3D orthogonal coordinate system with its origin at O. This is also where the camera aperture is located. The three axes of the coordinate system are referred to as X1, X2, X3. Axis X3 is pointing in the viewing direction of the camera and is referred to as the optical axis, principal axis, or principal ray. The 3D plane which intersects with axes X1 and X2 is the front side of the camera, or principal plane.

{{#invoke:Category handler|main}}{{#invoke:Category handler|main}}[citation needed] }} of the pinhole camera.

• A point R at the intersection of the optical axis and the image plane. This point is referred to as the principal point or image center.
• The projection line of point P into the camera. This is the green line which passes through point P and the point O.

The pinhole aperture of the camera, through which all projection lines must pass, is assumed to be infinitely small, a point. In the literature this point in 3D space is referred to as the optical (or lens or camera) center.

Next we want to understand how the coordinates $(y_{1},y_{2})$ of point Q depend on the coordinates $(x_{1},x_{2},x_{3})$ of point P. This can be done with the help of the following figure which shows the same scene as the previous figure but now from above, looking down in the negative direction of the X2 axis.

In this figure we see two similar triangles, both having parts of the projection line (green) as their hypotenuses. The catheti of the left triangle are $-y_{1}$ and f and the catheti of the right triangle are $x_{1}$ and $x_{3}$ . Since the two triangles are similar it follows that

${\frac {-y_{1}}{f}}={\frac {x_{1}}{x_{3}}}$ or $y_{1}=-{\frac {f\,x_{1}}{x_{3}}}$ A similar investigation, looking in the negative direction of the X1 axis gives

${\frac {-y_{2}}{f}}={\frac {x_{2}}{x_{3}}}$ or $y_{2}=-{\frac {f\,x_{2}}{x_{3}}}$ This can be summarized as

${\begin{pmatrix}y_{1}\\y_{2}\end{pmatrix}}=-{\frac {f}{x_{3}}}{\begin{pmatrix}x_{1}\\x_{2}\end{pmatrix}}$ which is an expression that describes the relation between the 3D coordinates $(x_{1},x_{2},x_{3})$ of point P and its image coordinates $(y_{1},y_{2})$ given by point Q in the image plane.

### Rotated image and the virtual image plane

The mapping from 3D to 2D coordinates described by a pinhole camera is a perspective projection followed by a 180° rotation in the image plane. This corresponds to how a real pinhole camera operates; the resulting image is rotated 180° and the relative size of projected objects depends on their distance to the focal point and the overall size of the image depends on the distance f between the image plane and the focal point. In order to produce an unrotated image, which is what we expect from a camera, there are two possibilities:

• Rotate the coordinate system in the image plane 180° (in either direction). This is the way any practical implementation of a pinhole camera would solve the problem; for a photographic camera we rotate the image before looking at it, and for a digital camera we read out the pixels in such an order that it becomes rotated.
• Place the image plane so that it intersects the X3 axis at f instead of at -f and rework the previous calculations. This would generate a virtual (or front) image plane which cannot be implemented in practice, but provides a theoretical camera which may be simpler to analyse than the real one.

In both cases the resulting mapping from 3D coordinates to 2D image coordinates is given by

${\begin{pmatrix}y_{1}\\y_{2}\end{pmatrix}}={\frac {f}{x_{3}}}{\begin{pmatrix}x_{1}\\x_{2}\end{pmatrix}}$ (same as before except no minus sign)

## Homogeneous coordinates

{{#invoke:main|main}}

The mapping from 3D coordinates of points in space to 2D image coordinates can also be represented in homogeneous coordinates. Let $\mathbf {x}$ be a representation of a 3D point in homogeneous coordinates (a 4-dimensional vector), and let $\mathbf {y}$ be a representation of the image of this point in the pinhole camera (a 3-dimensional vector). Then the following relation holds

$\mathbf {y} \sim \mathbf {C} \,\mathbf {x}$ where $\mathbf {C}$ is the $3\times 4$ camera matrix and the $\,\sim$ means equality between elements of projective spaces. This implies that the left and right hand sides are equal up to a non-zero scalar multiplication. A consequence of this relation is that also $\mathbf {C}$ can be seen as an element of a projective space; two camera matrices are equivalent if they are equal up to a scalar multiplication. This description of the pinhole camera mapping, as a linear transformation $\mathbf {C}$ instead of as a fraction of two linear expressions, makes it possible to simplify many derivations of relations between 3D and 2D coordinates.{{ safesubst:#invoke:Unsubst||date=__DATE__ |\$B= {{#invoke:Category handler|main}}{{#invoke:Category handler|main}}[citation needed] }}