## 1.

## Introduction

Projective geometry is an important topic in computer vision because it provides a useful camera imaging model and its fundamental properties.^{1} Some applications of this topic are found in camera motion,^{2} camera calibration,^{3}^{,}^{4} pose estimation for augmented reality,^{5} perspective correction,^{6} and three-dimensional (3-D) surface imaging^{7} among others.

Theoretical concepts of projective geometry are analyzed simply and elegantly using homogeneous coordinates.^{8}^{,}^{9} However, projective geometry is commonly presented in abstract form, leaving a gap in how to apply it in computer vision problems.^{10} Moreover, homogeneous coordinates are used with a notation that masks basic geometrical aspects and may confuse the inexperienced readers.^{11}

In this paper, a simple and intuitive approach to expose some useful concepts of projective geometry is addressed. For this, an alternative notation for homogeneous coordinates based on operators is suggested. To highlight the relevance of this topic in computer vision, the presentation is motivated by a specific problem, namely the perspective correction for a “camera scanner” application.

First, the proposed operators for homogeneous coordinates are defined in Sec. 2. Next, some basic concepts of projective geometry in the one- (1-D) and two-dimensional (2-D) cases are presented in Secs. 3 and 4, respectively. Then, the pinhole camera model is derived in Sec. 5. A perspective correction method, useful for camera document scanning, is described in Sec. 6. Finally, the conclusions of this work are given in Sec. 7. The paper is complemented with two appendices. Appendix A presents the direct linear transformation method for homography matrix estimation. Finally, a simple method to obtain the camera parameters from homographies is explained in Appendix B.

## 2.

## Definition of Operators

## 2.1.

### Operators $\mathcal{H}$ and $\mathcal{S}$

A point in an $n$-dimensional space will be represented by a vector of the form

where ${[\xb7]}^{T}$ denotes the transpose. The homogeneous coordinates of the point are obtained by adding an extra entry to $\mathbf{x}$ with a value equal to the unity. The result is the $(n+1)$-dimensional vector where $\mathcal{H}$ will be referred to as the homogeneous operator.The last entry of a homogeneous vector is known as the scale and will be recovered by the scale operator $\mathcal{S}$. This operator returns the last entry of any given vector. For instance, for the vectors in Eqs. (1) and (2), we have

## (3)

$${x}_{n}=\mathcal{S}[\mathbf{x}],\phantom{\rule[-0.0ex]{1em}{0.0ex}}\text{and}\phantom{\rule[-0.0ex]{1em}{0.0ex}}1=\mathcal{S}[\mathcal{H}[\mathbf{x}]].$$The operator $\mathcal{H}$ sets the scale to unity. Another operator that sets the scale to zero is needed. For this, we define the operator

Note that the operator ${\mathcal{H}}_{0}$ does not affect neither the direction nor the norm of $\mathbf{x}$. In projective geometry, the points represented by homogeneous coordinates of the form## (5)

$${\mathcal{H}}_{0}[\mathbf{x}],\phantom{\rule[-0.0ex]{2em}{0.0ex}}\mathbf{x}\ne {\mathbf{0}}_{n},$$The operators $\mathcal{H}$ and ${\mathcal{H}}_{0}$ can be considered as two particular cases of a more general operator defined as

where $s$ is any scalar.The procedure of adding an extra entry to vectors is reverted by returning the given vector except its last entry. For this, we define the inverse operator ${\mathcal{H}}_{0}^{-1}$ as follows. For any $(n+1)$-dimensional vector

## (7)

$$\mathbf{y}={[\begin{array}{ccccc}{y}_{1}& {y}_{2}& \cdots & {y}_{n}& {y}_{n+1}\end{array}]}^{T},$$## (8)

$${\mathcal{H}}_{0}^{-1}[\mathbf{y}]={[\begin{array}{cccc}{y}_{1}& {y}_{2}& \cdots & {y}_{n}\end{array}]}^{T}.$$## (9)

$${\mathcal{H}}_{s}^{-1}[\mathbf{y}]=\frac{s}{\mathcal{S}[\mathbf{y}]}{\mathcal{H}}_{0}^{-1}[\mathbf{y}].$$The inverse ${\mathcal{H}}_{0}^{-1}$ is a linear operator. That is, for any two scalars ${\lambda}_{1}$ and ${\lambda}_{2}$, we have

## (10)

$${\mathcal{H}}_{0}^{-1}[{\lambda}_{1}{\mathbf{y}}_{1}+{\lambda}_{2}{\mathbf{y}}_{2}]={\lambda}_{1}{\mathcal{H}}_{0}^{-1}[{\mathbf{y}}_{1}]+{\lambda}_{2}{\mathcal{H}}_{0}^{-1}[{\mathbf{y}}_{2}].$$## (11)

$${\mathcal{H}}_{s}^{-1}[\lambda \mathbf{y}]={\mathcal{H}}_{s}^{-1}[\mathbf{y}],\phantom{\rule[-0.0ex]{2em}{0.0ex}}s,\lambda \ne 0.$$## (12)

$${\mathcal{H}}_{s}[\mathbf{x}]={\mathrm{\Xi}}_{s}\mathcal{H}[\mathbf{x}],\phantom{\rule[-0.0ex]{1em}{0.0ex}}\text{and}\phantom{\rule{0ex}{0ex}}{\mathcal{H}}_{s}^{-1}[\mathbf{y}]={\mathcal{H}}^{-1}[{\mathrm{\Xi}}_{s}^{-1}\mathbf{y}],\phantom{\rule[-0.0ex]{1em}{0.0ex}}s\ne 0,$$## (13)

$${\mathrm{\Xi}}_{s}=\left[\begin{array}{cc}{\mathbb{I}}_{n}& {\mathbf{0}}_{n}\\ {\mathbf{0}}_{n}^{T}& s\end{array}\right],$$## 2.2.

### Projection Operator $\mathcal{P}$

In general terms, the homogeneous operator carries the representation of a point from $n$- to $(n+1)$-dimensional vectors while the inverse homogeneous operator returns the representation from $(n+1)$- to $n$-dimensional vectors. An important transformation emerges when, in the $(n+1)$-dimensional space, a linear mapping is applied. Mathematically, we describe this transformation by the projection operator defined as

where $M$ is an $(n+1)\times (n+1)$ matrix. A generalized version of the projection operator is obtained using ${\mathcal{H}}_{s}$ and its inverse as From Eq. (11), it follows that, for $s\ne 0$, the operator ${\mathcal{P}}_{M,s}$ is invariant to nonzero scalar multiplication of the matrix $M$; that is## (16)

$${\mathcal{P}}_{\lambda M,s}[\mathbf{x}]={\mathcal{P}}_{M,s}[\mathbf{x}],\phantom{\rule[-0.0ex]{2em}{0.0ex}}s,\lambda \ne 0.$$## (17)

$${\mathcal{P}}_{M,s}^{-1}[\mathbf{x}]={\mathcal{P}}_{{M}^{-1},s}[\mathbf{x}],\phantom{\rule[-0.0ex]{1em}{0.0ex}}\mathrm{det}\text{\hspace{0.17em}}M\ne 0,$$Using the equations in Eq. (12), the operator ${\mathcal{P}}_{M,s}$ can be expressed in terms of the projection operator, namely

## (18)

$${\mathcal{P}}_{M,s}[\mathbf{x}]={\mathcal{P}}_{{\mathrm{\Xi}}_{s}^{-1}M{\mathrm{\Xi}}_{s}}[\mathbf{x}],\phantom{\rule[-0.0ex]{2em}{0.0ex}}s\ne 0.$$## Table 1

Some useful equalities of the operators S, Hs, and PM,s. In all cases, we consider λ≠0, γ1 and γ2 are any scalars, x is a n-dimensional vector as given in Eq. (1), Ξs is the matrix defined in Eq. (13), y=λHs[x], M is a matrix of size (n+1)×(n+1), and W is a matrix of size m×(n+1).

Property | Description | |
---|---|---|

(P1) | Hs−1[Hs[x]]=x | s≠0 |

(P2) | Hs[Hs−1[y]]=sS[y]y | s≠0 |

(P3) | x=Hs−1[y]↔S[y]sHs[x]=y | s≠0 |

(P4) | Hs[λx]=λHs/λ[x] | |

(P5) | λHs[x]=Hλs[λx] | |

(P6) | Hs[WHs[x]]=[WH[0n]T]Hs[x] | |

(P7) | Hs[x1±x2]=Hs1[x1]±Hs2[x2] | s1±s2=s |

(P8) | Hs−1[λy]=Hs−1[y] | s≠0 |

(P9) | λHs−1[y]=Hλs−1[y] | s≠0 |

(P10) | H0−1[γ1y1+γ2y2]=γ1H0−1[y1]+γ2H0−1[y2] | |

(P11) | S[γ1x1+γ2x2]=γ1S[x1]+γ2S[x2] | |

(P12) | Hs−1[y1+y2]=1S[y1+y2](S[y1]Hs−1[y1]+S[y2]Hs−1[y2]) | s≠0 |

(P13) | Hs−1[y1+y2]−Hs−1[y1]=S[y2]S[y1+y2](Hs−1[y2]−Hs−1[y1]) | s≠0 |

(P14) | Hs[x]=ΞsH[x] | |

(P15) | Hs−1[y]=H−1[Ξs−1y] | s≠0 |

(P16) | PλM,s[x]=PM,s[x] | s≠0 |

(P17) | PM,s−1[x]=PM−1,s[x] | detM≠0 |

(P18) | x2=PM,s[x1]↔PM−1,s[x2]=x1 | det M≠0 |

(P19) | PM,s[λx]=λPM,s/λ[x] | |

(P20) | λPM,s[x]=PM,λs[λx] | |

(P21) | PM2,s[PM1,s[x]]=PM2M1,s[x] | |

(P22) | PIn,s[x]=x | |

(P23) | PM,s[x]=PΞs−1MΞs[x] | s≠0 |

(P24) | Hs[PM,s[x]]=sS[MH[x]]MH[x] | s≠0 |

(P25) | PM,s[Hs−1[y]]=Hs−1[My] | s≠0 |

In the following sections, the defined operators are studied from an intuitive geometrical approach for the 1-D and 2-D cases. Then, the usefulness of this theoretical framework is illustrated by addressing the perspective correction problem for camera document scanning.

## 3.

## One-Dimensional Space

The 1-D real space can be represented as a line as shown in Fig. 1(a). In this space, a point at a finite distance from the origin is represented by a real number $x$; otherwise, the point is represented by the symbol $\infty $.

Alternatively, the 1-D space can be represented by the projective line $y=1$ in the $xy$-plane as shown in Fig. 1(b). Thus, the coordinate $x$ of a point in the line becomes the vector

The coordinate $x$ can be recovered from its homogeneous version $\mathbf{y}$ as the intersection between the line $y=1$ and the line with direction $\mathcal{H}[x]$ passing through the origin as shown in Fig. 1(b). This is described mathematically as Note that the result is invariant to the scalar multiplication of $\mathbf{y}$ by a nonzero scalar [e.g., $\lambda $ and $-\gamma $ as shown in Fig. 1(b)] because the intersection between lines is unaltered. In other words, ${\mathcal{H}}^{-1}[\lambda \mathbf{y}]={\mathcal{H}}^{-1}[-\gamma \mathbf{y}]={\mathcal{H}}^{-1}[\mathbf{y}]$ as stated by Eq. (11).## 3.1.

### Ideal Point

Homogeneous coordinates provide a different form to identify points of the real line. Consider the unit vector

## (21)

$$\mathbf{u}(\theta )=\left[\begin{array}{c}\mathrm{sin}\text{\hspace{0.17em}}\theta \\ \mathrm{cos}\text{\hspace{0.17em}}\theta \end{array}\right].$$Intuitively, the real line in Euclidean representation has two points at infinity, namely $-\infty $ and $+\infty $. However, in projective geometry, the real line has only a single point at infinity given by the homogeneous coordinates

which is associated to $\mathbf{u}(\pi /2)$, as shown in Fig. 2. It could be argued that $\pi /2$ corresponds to $+\infty $ while $-\pi /2$ to $-\infty $. However, note that $\mathbf{u}(-\pi /2)=-\mathbf{\psi}$ is the opposite of $\mathbf{\psi}$. Hence, they represent the same point.Note that ${\mathcal{H}}^{-1}[\mathbf{\psi}]=1/0$ is consistent with the notion that $\mathbf{\psi}$ represents a point at infinity distance from the origin. According to the concepts of projective geometry, the vector $\mathbf{\psi}$ represents an ideal point, see Eq. (5).

## 3.2.

### One-Dimensional Projection

The line $y=0$ can be transformed to any other line by applying a rotation $Q=[{\mathbf{q}}_{1},{\mathbf{q}}_{2}]$ and a translation $\mathbf{s}$. Thus, a point in the line $y=0$, represented by the scalar $x$, becomes a point in the $xy$-plane given by the vector

## (25)

$$\mathbf{p}=q{\mathcal{H}}_{0}[x]+\mathbf{s}\phantom{\rule{0ex}{0ex}}={\mathrm{\Pi}}_{1}\mathcal{H}[x],$$If the matrix ${\mathrm{\Pi}}_{1}$ is singular, the vectors ${\mathbf{q}}_{1}$ and $\mathbf{s}$ are collinear. In this case, the origin is a point of the transformed line (the distance of the line from the origin is zero). The matrix ${\mathrm{\Pi}}_{1}$ is nonsingular when ${\mathbf{q}}_{1}$ and $\mathbf{s}$ are linearly independent. In this case, the origin is not a point of the transformed line.

Let $\mathbf{p}$ in Eq. (25) be the homogeneous coordinates of a point $\alpha $ in the line. Thus, we obtain the 1-D projection

## (27)

$$\alpha ={\mathcal{H}}^{-1}[\mathbf{p}]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[{\mathrm{\Pi}}_{1}\mathcal{H}[x]]\phantom{\rule{0ex}{0ex}}={\mathcal{P}}_{{\mathrm{\Pi}}_{1}}[x].$$## 4.

## Two-Dimensional Space

## 4.1.

### Points and Lines in the Plane

Any point in the 2-D space can be represented as the vector

Moreover, the point $\mathbf{x}$ can be represented by its homogeneous coordinates as shown in Fig. 4(a). Note that $\mathcal{H}$ takes the 2-D vector $\mathbf{x}$ (in the plane $z=0$) and converts it to the 3-D vector $\mathcal{H}[\mathbf{x}]$, where $\mathbf{x}$ is unaltered but now it lies in the projective plane $z=1$. It is worth mentioning that the vector $\mathbf{x}$ can be recovered from $\lambda \mathcal{H}[\mathbf{x}]$ as the point of intersection of the line with points ${\mathbf{0}}_{3}$ and $\lambda \mathcal{H}[\mathbf{x}]$, see Eq. (11). That is,## (30)

$$\mathbf{x}={\mathcal{H}}^{-1}[\lambda \mathcal{H}[\mathbf{x}]],\phantom{\rule[-0.0ex]{2em}{0.0ex}}\lambda \ne 0.$$Let ${\mathbf{x}}_{1}$ and ${\mathbf{x}}_{2}$ be two different points in the $xy$-plane. The vector $\mathbf{l}$ of the line passing through ${\mathbf{x}}_{1}$ and ${\mathbf{x}}_{2}$ can be obtained by the cross product as

By definition of the cross product, the vector $\mathbf{l}$ is orthogonal to $\mathcal{H}[{\mathbf{x}}_{1}]$ and $\mathcal{H}[{\mathbf{x}}_{2}]$. Therefore, these vectors satisfy Eq. (32).Consider two lines defined by the vectors ${\mathbf{l}}_{1}$ and ${\mathbf{l}}_{2}$. If $\mathbf{x}$ is the intersection point of these lines, then $\mathcal{H}[\mathbf{x}]$ is orthogonal to ${\mathbf{l}}_{1}$ and ${\mathbf{l}}_{2}$. That is

where $\lambda =\mathcal{S}[{\mathbf{l}}_{1}\times {\mathbf{l}}_{2}]$. Therefore, the intersection point of the lines ${\mathbf{l}}_{1}$ and ${\mathbf{l}}_{2}$ is## 4.2.

### Parallel Lines

Two different lines are parallel if its defining vectors are of the form

## (36)

$$\mathbf{l}=\left[\begin{array}{c}{l}_{1}\\ {l}_{2}\\ {l}_{3}\end{array}\right],\phantom{\rule[-0.0ex]{2em}{0.0ex}}\overline{\mathbf{l}}=\lambda \left[\begin{array}{c}{l}_{1}\\ {l}_{2}\\ {l}_{3}+\delta \end{array}\right],$$## (37)

$$\mathbf{\alpha}=\mathbf{a}+\gamma \mathbf{d},\phantom{\rule[-0.0ex]{1em}{0.0ex}}\text{and}\phantom{\rule{0ex}{0ex}}\mathbf{\beta}=\mathbf{a}+\gamma \mathbf{d}+\delta \mathbf{t},$$## (38)

$${\mathcal{H}}_{0}[\mathbf{t}]\times {\mathcal{H}}_{0}[\mathbf{d}]=\mathcal{H}[{\mathbf{0}}_{2}],$$## (39)

$$\mathbf{l}=\mathcal{H}[{\mathbf{\alpha}}_{1}]\times \mathcal{H}[{\mathbf{\alpha}}_{2}]\phantom{\rule{0ex}{0ex}}=({\gamma}_{2}-{\gamma}_{1})\mathcal{H}[\mathbf{a}]\times {\mathcal{H}}_{0}[\mathbf{d}],$$## (41)

$$\overline{\mathbf{l}}=\mathcal{H}[{\mathbf{\beta}}_{1}]\times \mathcal{H}[{\mathbf{\beta}}_{2}]\phantom{\rule{0ex}{0ex}}=({\overline{\gamma}}_{2}-{\overline{\gamma}}_{1})(\mathbf{l}+\delta \mathcal{H}[{\mathbf{0}}_{2}])\phantom{\rule{0ex}{0ex}}=\lambda (\mathbf{l}+\delta \mathcal{H}[{\mathbf{0}}_{2}]),$$It is worth mentioning that, if $\mathbf{l}$ is the vector of a line with direction $\mathbf{d}$ [see Eq. (40)], then the vector ${\mathcal{H}}_{0}^{-1}[\mathbf{l}]$ is orthogonal to $\mathbf{d}$, namely

## (42)

$${\mathbf{d}}^{T}{\mathcal{H}}_{0}^{-1}[\mathbf{l}]={\mathbf{d}}^{T}{\mathcal{H}}_{0}^{-1}[\mathcal{H}[\mathbf{a}]\times {\mathcal{H}}_{0}[\mathbf{d}]]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}_{0}{[\mathbf{d}]}^{T}(\mathcal{H}[\mathbf{a}]\times {\mathcal{H}}_{0}[\mathbf{d}])\phantom{\rule{0ex}{0ex}}=0.$$## 4.3.

### Ideal Points and the Line at Infinity

In the Euclidean geometry, two parallel lines in the plane do not intersect. However, in the projective geometry, two different lines always intersect at a point. Consider the parallel lines given by the vectors in Eq. (36). Using Eq. (35), the intersection point is

## (43)

$${\mathcal{H}}^{-1}[\mathbf{l}\times \overline{\mathbf{l}}]={\mathcal{H}}^{-1}[\mathcal{H}[{\mathbf{0}}_{2}]\times \mathbf{l}]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[\mathbf{\psi}],$$The vector $\mathbf{\psi}$ is associated with the direction $\mathbf{d}$ of the line $\mathbf{l}$. This is verified by taking into account that ${\mathcal{H}}_{0}^{-1}[\mathbf{l}]$ is orthogonal to $\mathbf{d}$ [Eq. (42)] as well as to ${\mathcal{H}}_{0}^{-1}[\mathbf{\psi}]$ (${\mathcal{H}}_{0}^{-1}{[\mathbf{\psi}]}^{T}{\mathcal{H}}_{0}^{-1}[\mathbf{l}]=0$), then

where $\lambda $ is some nonzero scalar.All ideal points given by Eq. (44) are collinear. The vector of such a line, known as the line at infinity, is

## (46)

$${\mathbf{l}}_{\infty}=\mathcal{H}[{\mathbf{0}}_{2}]={[\begin{array}{ccc}0& 0& 1\end{array}]}^{T}.$$The ideal point $\mathbf{\psi}$ in Eq. (44) was obtained as the intersection of two parallel lines $\mathbf{l}$ and $\overline{\mathbf{l}}$. However, the intuition suggests that the same result could be obtained by computing the intersection of the line $\mathbf{l}$ and the line at infinity ${\mathbf{l}}_{\infty}$. In fact, we have that

Thus, using Eq. (45), the direction $\mathbf{d}$ of any line $\mathbf{l}$ is given by where $\lambda $ is a nonzero scale factor. For this reason, the line ${\mathbf{l}}_{\infty}$ is interpreted as the set of directions of lines in the plane.Similar to the 1-D case, homogeneous coordinates provide a different form to identify points of the plane. Consider the unit vector

## (49)

$$\mathbf{v}={[\begin{array}{ccc}\mathrm{sin}\text{\hspace{0.17em}}\theta \text{\hspace{0.17em}}\mathrm{cos}\text{\hspace{0.17em}}\varphi & \mathrm{sin}\text{\hspace{0.17em}}\theta \text{\hspace{0.17em}}\mathrm{sin}\text{\hspace{0.17em}}\varphi & \mathrm{cos}\text{\hspace{0.17em}}\theta \end{array}]}^{T},$$The points of the plane at a finite distance from the origin are given by $\mathbf{v}(\theta ,\varphi )$ with $\theta \in [0,\pi /2)$ and $\varphi \in [-\pi ,\pi )$, i.e., the upper hemisphere of the unit sphere, see Fig. 5. The points of the plane at infinity distance from the origin are parameterized by $\theta =\pi /2$ and $\varphi \in (-\pi /2,\pi /2]$. These points have the homogeneous coordinates

## (52)

$${\mathbf{v}}_{\infty}={[\begin{array}{ccc}\mathrm{cos}\text{\hspace{0.17em}}\varphi & \mathrm{sin}\text{\hspace{0.17em}}\varphi & 0\end{array}]}^{T},$$## 4.4.

### Two-Dimensional Projection

Any plane in the 3-D space can be obtained as the plane $z=0$ after a rotation $Q=[{\mathbf{q}}_{1},{\mathbf{q}}_{2},{\mathbf{q}}_{3}]$ and a translation $\mathbf{s}$. Thus, the points represented by $\mathbf{x}={[{x}_{1},{x}_{2}]}^{T}$, becomes

## (53)

$$\mathbf{p}=Q{\mathcal{H}}_{0}[\mathbf{x}]+\mathbf{s}\phantom{\rule{0ex}{0ex}}={\mathrm{\Pi}}_{2}\mathcal{H}[\mathbf{x}],$$## (54)

$${\mathrm{\Pi}}_{2}=[\begin{array}{ccc}{\mathbf{q}}_{1}& {\mathbf{q}}_{2}& \mathbf{s}\end{array}].$$The matrix ${\mathrm{\Pi}}_{2}$ is singular when ${\mathbf{r}}_{1}$, ${\mathbf{r}}_{2}$, and $\mathbf{t}$ are coplanar. In this case, the origin ${\mathbf{0}}_{3}$ is a point of the transformed plane (the distance of the reference plane from the origin is zero). Otherwise, ${\mathrm{\Pi}}_{2}$ is a nonsingular.

Let $\mathbf{p}$ in Eq. (53) be the homogeneous coordinates of a point $\mathbf{\alpha}$ in the projective plane. Thus, the relation between the points $\mathbf{\alpha}$ and $\mathbf{x}$ is given by the 2-D projection ${\mathcal{P}}_{{\mathrm{\Pi}}_{2}}$, namely

## (55)

$$\mathbf{\alpha}={\mathcal{H}}^{-1}[\mathbf{p}]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[{\mathrm{\Pi}}_{2}\mathcal{H}[\mathbf{x}]]\phantom{\rule{0ex}{0ex}}={\mathcal{P}}_{{\mathrm{\Pi}}_{2}}[\mathbf{x}].$$## 4.5.

### Properties of the Two-Dimensional Projection

As shown in Fig. 6, the 2-D projection ${\mathcal{P}}_{{\mathrm{\Pi}}_{2}}$ excludes several geometrical properties; e.g., shape, angles, lengths, and ratio of lengths. Fortunately, there are some geometrical properties that are preserved. Particularly, we are interested in three of them that are very useful in practice: namely straightness, line–line intersection, and parallelism of the normal and line at infinity vectors.

## 4.5.1.

#### Straightness property

This property states that a 2-D projection transforms lines to lines.^{12} This can be shown as follows. Consider a line with vector $\mathbf{l}$ and points $\mathbf{x}$, that is

## (57)

$$0={\mathbf{l}}^{T}\mathcal{H}[{\mathcal{P}}_{{\mathrm{\Pi}}_{2}^{-1}}[\mathbf{\alpha}]]=\frac{{\mathbf{l}}^{T}{\mathrm{\Pi}}_{2}^{-1}\mathcal{H}[\mathbf{\alpha}]}{\mathcal{S}[{\mathrm{\Pi}}_{2}^{-1}\mathcal{H}[\mathbf{\alpha}]]},$$## 4.5.2.

#### Line–line intersection

Preservation of the line–line intersection by a 2-D projection refers to the following. If

is the point where the lines ${\mathbf{l}}_{1}$ and ${\mathbf{l}}_{2}$ intersect, then is the point where intersect the lines## (62)

$${\mathbf{m}}_{1}={\mathrm{\Pi}}_{2}^{-T}{\mathbf{l}}_{1}\phantom{\rule[-0.0ex]{1em}{0.0ex}}\text{and}\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{m}}_{2}={\mathrm{\Pi}}_{2}^{-T}{\mathbf{l}}_{2}.$$## (63)

$${\mathbf{\alpha}}_{0}={\mathcal{H}}^{-1}[{\mathbf{m}}_{1}\times {\mathbf{m}}_{2}]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[({\mathrm{\Pi}}_{2}^{-T}{\mathbf{l}}_{1})\times ({\mathrm{\Pi}}_{2}^{-T}{\mathbf{l}}_{2})]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[{\mathrm{\Pi}}_{2}({\mathbf{l}}_{1}\times {\mathbf{l}}_{2})],$$## (64)

$$(M\mathbf{u})\times (M\mathbf{v})=(\mathrm{det}\text{\hspace{0.17em}}M){M}^{-T}(\mathbf{u}\times \mathbf{v})$$## (65)

$${\mathbf{\alpha}}_{0}={\mathcal{H}}^{-1}[\mathcal{S}[{\mathbf{l}}_{1}\times {\mathbf{l}}_{2}]{\mathrm{\Pi}}_{2}\mathcal{H}[{\mathbf{x}}_{0}]]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[{\mathrm{\Pi}}_{2}\mathcal{H}[{\mathbf{x}}_{0}]]\phantom{\rule{0ex}{0ex}}={\mathcal{P}}_{{\mathrm{\Pi}}_{2}}[{\mathbf{x}}_{0}].$$## 4.5.3.

#### Parallelism of the normal and line at infinity vectors

The normal of the $xy$-plane and the vector ${\mathbf{l}}_{\infty}$ of the line at infinity are parallel. When the projection ${\mathcal{P}}_{{\mathrm{\Pi}}_{2}}$ is applied, the normal ${\mathbf{q}}_{3}$ of the reference plane (with parameters ${\mathrm{\Pi}}_{2}$) and the new line at infinity ${\mathbf{m}}_{\infty}$ still remain parallel; i.e., ${\mathbf{m}}_{\infty}=\lambda {\mathbf{q}}_{3}$, $\lambda \ne 0$. Actually, the reference plane has the normal

see Eq. (54), whereas the vector of the new line at infinity is## (67)

$${\mathbf{m}}_{\infty}={\mathrm{\Pi}}_{2}^{-T}{\mathbf{l}}_{\infty}\phantom{\rule{0ex}{0ex}}=\lambda (\mathrm{cof}\text{\hspace{0.17em}}{\mathrm{\Pi}}_{2}){\mathbf{l}}_{\infty}\phantom{\rule{0ex}{0ex}}=\lambda [\begin{array}{ccc}{\mathbf{q}}_{2}\times \mathbf{s}& -{\mathbf{q}}_{1}\times \mathbf{s}& {\mathbf{q}}_{1}\times {\mathbf{q}}_{2}\end{array}]{\mathbf{l}}_{\infty}\phantom{\rule{0ex}{0ex}}=\lambda {\mathbf{q}}_{3},$$In the following section, the developed theoretical framework is applied in a real problem.

## 5.

## Pinhole Camera Model

In practice, the imaging process is performed by a camera lens device as shown in Fig. 7(a). This device produces high quality images because of a complicated system of lenses that minimizes aberration and distortion. However, the imaging process can be modeled using a single thin lens as shown in Fig. 7(b). Moreover, the imaging model can be easily derived using the equivalent pinhole camera as shown in Fig. 7(c).

In the pinhole camera, the origin of a coordinate system is fixed at the pinhole and the $z$-axis is parallel to the optical axis. The plane $z=-f$, where $f$ is the focal length, is the actual image plane. Note that the image is inverted; therefore, the $x$ and $y$ axes are reverted to describe the image as a magnified version of the object. The inversion of the axes is avoided using the conjugate image plane $z=f$ as shown in Fig. 7(c).

## 5.1.

### Centered Pinhole Camera

A typical representation of a pinhole camera is shown in Fig. 8. The coordinate system ${O}_{c}{x}_{c}{y}_{c}{z}_{c}$ is known as the camera reference frame. Let

be the coordinates of a point in the camera reference frame. The point ${\mathbf{p}}_{c}$ will be imaged in the plane ${z}_{c}=f$ at the point where $\mathbf{\beta}$ will be referred to as the physical image coordinates. The pinhole projection model relates the vectors ${\mathbf{p}}_{c}$ and $\mathbf{\beta}$ by## (70)

$$\left[\begin{array}{c}{\beta}_{x}\\ {\beta}_{y}\\ f\end{array}\right]=\frac{f}{{z}_{c}}\left[\begin{array}{c}{x}_{c}\\ {y}_{c}\\ {z}_{c}\end{array}\right].$$## (71)

$$\mathbf{\beta}={\mathcal{H}}_{f}^{-1}[{\mathbf{p}}_{c}]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[{\mathrm{\Xi}}_{f}^{-1}{\mathbf{p}}_{c}].$$## (73)

$$u=({\beta}_{x}+{\tau}_{x})/{s}_{x}+\sigma {\beta}_{y},\phantom{\rule{0ex}{0ex}}v=({\beta}_{y}+{\tau}_{y})/{s}_{y},$$## (74)

$$\left[\begin{array}{c}u\\ v\\ 1\end{array}\right]=\left[\begin{array}{ccc}1/{s}_{x}& \sigma & {\tau}_{x}/{s}_{x}\\ 0& 1/{s}_{y}& {\tau}_{y}/{s}_{y}\\ 0& 0& 1\end{array}\right]\left[\begin{array}{c}{\beta}_{x}\\ {\beta}_{y}\\ 1\end{array}\right],$$## (75)

$$\mathbf{\mu}={\mathcal{H}}^{-1}[\mathcal{S}\mathcal{H}[\mathbf{\beta}]]\phantom{\rule{0ex}{0ex}}={\mathcal{P}}_{S}[\mathbf{\beta}],$$## (76)

$$S=\left[\begin{array}{ccc}1/{s}_{x}& \sigma & {\tau}_{x}/{s}_{x}\\ 0& 1/{s}_{y}& {\tau}_{y}/{s}_{y}\\ 0& 0& 1\end{array}\right].$$## (77)

$$\mathbf{\mu}={\mathcal{P}}_{S}[{\mathcal{H}}^{-1}[{\mathrm{\Xi}}_{f}^{-1}{\mathbf{p}}_{c}]]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[S{\mathrm{\Xi}}_{f}^{-1}{\mathbf{p}}_{c}]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[K{\mathbf{p}}_{c}],$$## (78)

$$K=\left[\begin{array}{ccc}1/{s}_{x}& \sigma & {\tau}_{x}/f{s}_{x}\\ 0& 1/{s}_{y}& {\tau}_{y}/f{s}_{y}\\ 0& 0& 1/f\end{array}\right].$$Given a point $\mathbf{\mu}$ (in pixel coordinates), the actual coordinates ${\mathcal{H}}_{f}[\mathbf{\beta}]$ of an image point (physical coordinates on the image plane $z=f$) can be obtained from Eq. (75) as

## (79)

$${\mathcal{H}}_{f}[\mathbf{\beta}]={\mathcal{H}}_{f}[{\mathcal{P}}_{{S}^{-1}}[\mathbf{\mu}]]\phantom{\rule{0ex}{0ex}}={\mathrm{\Xi}}_{f}\mathcal{H}[{\mathcal{P}}_{{S}^{-1}}[\mathbf{\mu}]]\phantom{\rule{0ex}{0ex}}={\mathrm{\Xi}}_{f}{S}^{-1}\mathcal{H}[\mathbf{\mu}]/\mathcal{S}[{S}^{-1}\mathcal{H}[\mathbf{\mu}]]\phantom{\rule{0ex}{0ex}}={K}^{-1}\mathcal{H}[\mathbf{\mu}],$$## 5.2.

### Noncentered Pinhole Camera

Let us consider that the pinhole camera is at an arbitrary position and orientation with respect to a world coordinate system $Oxyz$ as shown in Fig. 9. The position and orientation of the camera are defined by the vector $\mathbf{t}$ and the rotation matrix $R$, respectively. Let

be a point in the world coordinate system. Then, the point $\mathbf{p}$ is seen from the camera reference frame as where $L$ is known as the matrix of extrinsic camera parameters having the explicit form By substituting Eq. (81) into Eq. (77), the complete imaging process by a noncentered pinhole camera is given as## (83)

$$\mathbf{\mu}={\mathcal{H}}^{-1}[KL\mathcal{H}[\mathbf{p}]]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[C\mathcal{H}[\mathbf{p}]],$$## 5.3.

### Homography Matrix

In general terms, Eq. (83) describes a transformation of points $\mathbf{p}$ of the 3-D space to points of the 2-D one. A very useful transformation is obtained when $\mathbf{p}$ represents points of a plane in the 3-D space. In this case, Eq. (83) is reduced to a transformation from the 2-D space to itself.

Consider that $\mathbf{p}$ represents the points of a plane in the 3-D space; mathematically, see Eq. (53)

where $\mathbf{\rho}={[{\rho}_{x},{\rho}_{y}]}^{T}$ parameterizes the plane, $\mathrm{\Pi}=[{\mathbf{q}}_{1},{\mathbf{q}}_{2},\mathbf{s}]$ is the matrix of the plane, ${\mathbf{q}}_{1}$ and ${\mathbf{q}}_{2}$ are columns of the rotation matrix $Q={[{\mathbf{q}}_{1},{\mathbf{q}}_{2},{\mathbf{q}}_{3}]}^{T}$, and $\mathbf{s}$ is a translation vector. Next, the points $\mathbf{p}$ are transformed to $\mathbf{\mu}$ by Eq. (83) as## (85)

$$\mathbf{\mu}={\mathcal{H}}^{-1}[C\mathcal{H}[\mathrm{\Pi}\mathcal{H}[\mathbf{\rho}]]]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}\left[C\right[\begin{array}{c}\mathrm{\Pi}\\ \mathcal{H}{[{\mathbf{0}}_{2}]}^{T}\end{array}]\mathcal{H}[\mathbf{\rho}]]\phantom{\rule{0ex}{0ex}}={\mathcal{H}}^{-1}[G\mathcal{H}[\mathbf{\rho}]]\phantom{\rule{0ex}{0ex}}={\mathcal{P}}_{G}[\mathbf{\rho}],$$## (86)

$$G=KL\left[\begin{array}{c}\mathrm{\Pi}\\ \mathcal{H}[{\mathbf{0}}_{2}]\end{array}\right]\phantom{\rule{0ex}{0ex}}=K{R}^{T}[\begin{array}{cc}\mathrm{\Pi}& -\mathbf{t}\mathcal{H}{[\mathbf{0}]}^{T}\end{array}]\phantom{\rule{0ex}{0ex}}=K{R}^{T}\overline{\mathrm{\Pi}},$$## (87)

$$\overline{\mathrm{\Pi}}=[\begin{array}{cc}\mathrm{\Pi}& -\mathbf{t}\mathcal{H}{[\mathbf{0}]}^{T}\end{array}]\phantom{\rule{0ex}{0ex}}=[\begin{array}{ccc}{\mathbf{q}}_{1}& {\mathbf{q}}_{2}& \mathbf{s}-\mathbf{t}\end{array}].$$## (88)

$${\mathcal{H}}_{f}[\mathbf{\beta}]={K}^{-1}\mathcal{H}[\mathbf{\mu}]\phantom{\rule{0ex}{0ex}}={K}^{-1}\mathcal{H}[{\mathcal{P}}_{G}[\mathbf{\rho}]]\phantom{\rule{0ex}{0ex}}={K}^{-1}G\mathcal{H}[\mathbf{\rho}]/\lambda \phantom{\rule{0ex}{0ex}}={R}^{T}\overline{\mathrm{\Pi}}\mathcal{H}[\mathbf{\rho}]/\lambda ,$$The homography matrix is singular when the pinhole is at a point of the reference plane. For any other case, $\mathrm{det}\text{\hspace{0.17em}}G={\mathbf{q}}_{3}^{T}(\mathbf{s}-\mathbf{t})/({s}_{x}{s}_{y}f)$ and Eq. (85) can be inverted as

The homography matrix is very useful for many computer vision tasks. In Appendix A, the direct linear transformation method for homography estimation is described.## 6.

## Perspective Correction for Document Scanning

A camera document scanning application performs several image processing tasks, such as quadrilateral detection, perspective correction, resampling, and image enhancement. In this section, the perspective correction task is addressed to illustrate the application of the proposed approach.

## 6.1.

### Assumptions

In Appendix A, we show that the perspective of a flat object can be easily corrected using the associated homography. For this, at least four correspondences $({\mathbf{\mu}}_{k},{\mathbf{\rho}}_{k})$ must be provided. However, for practical document scanning, the coordinates ${\mathbf{\rho}}_{k}$ are unknown. Instead, it is assumed that the document to be digitized is rectangular and the orthogonality and parallelism properties of its edges are exploited.

The estimation of the homography is greatly simplified by assuming a centered pinhole camera with known intrinsic parameters; e.g., by a previous camera calibration, see Appendix B. Thus, we only require to estimate the reference plane parameters $\mathrm{\Pi}$, i.e., the rotation matrix $Q$ and the translation vector $\mathbf{s}$, see Eq. (84).

## 6.2.

### Estimation of the Reference Plane Parameters

Consider a coordinate system in the reference plane with origin at the center of the document to be scanned as shown in Fig. 10(a). The $x$- and $y$-axes of this coordinate system are parallel with the upper/lower and left/right sides of the paper, respectively. The corners of the document to be digitized have coordinates given by the vectors

In this configuration, the vectors ${\mathbf{\rho}}_{k}$ are symmetric about the $y$-axis; that is## (91)

$${\mathbf{\rho}}_{2}=T{\mathbf{\rho}}_{1},\phantom{\rule{0ex}{0ex}}{\mathbf{\rho}}_{4}=T{\mathbf{\rho}}_{3},$$The points ${\mathbf{\mu}}_{k}$ are used to compute the following lines, see Fig. 10(b),

## (94)

$${\mathbf{m}}_{1}=\mathcal{H}[{\mathbf{\mu}}_{3}]\times \mathcal{H}[{\mathbf{\mu}}_{1}],\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{m}}_{4}=\mathcal{H}[{\mathbf{\mu}}_{1}]\times \mathcal{H}[{\mathbf{\mu}}_{2}],\phantom{\rule{0ex}{0ex}}{\mathbf{m}}_{2}=\mathcal{H}[{\mathbf{\mu}}_{2}]\times \mathcal{H}[{\mathbf{\mu}}_{4}],\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{m}}_{5}=\mathcal{H}[{\mathbf{\mu}}_{4}]\times \mathcal{H}[{\mathbf{\mu}}_{1}],\phantom{\rule{0ex}{0ex}}{\mathbf{m}}_{3}=\mathcal{H}[{\mathbf{\mu}}_{3}]\times \mathcal{H}[{\mathbf{\mu}}_{4}],\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{m}}_{6}=\mathcal{H}[{\mathbf{\mu}}_{2}]\times \mathcal{H}[{\mathbf{\mu}}_{3}].$$## (95)

$${\mathbf{\mu}}_{0}={\mathcal{H}}^{-1}[{\mathbf{m}}_{1}\times {\mathbf{m}}_{2}],\phantom{\rule{0ex}{0ex}}{\mathbf{\mu}}_{a}={\mathcal{H}}^{-1}[{\mathbf{m}}_{3}\times {\mathbf{m}}_{4}],\phantom{\rule{0ex}{0ex}}{\mathbf{\mu}}_{b}={\mathcal{H}}^{-1}[{\mathbf{m}}_{5}\times {\mathbf{m}}_{6}].$$## 6.2.1.

#### Normal vector

Note that the points ${\mathbf{\mu}}_{a}$ and ${\mathbf{\mu}}_{b}$ are the projections of the ideal points

## (97)

$$\mathcal{H}[{\mathbf{\rho}}_{a}]={[\begin{array}{ccc}1& 0& 0\end{array}]}^{T},\phantom{\rule{0ex}{0ex}}\mathcal{H}[{\mathbf{\rho}}_{b}]={[\begin{array}{ccc}0& 1& 0\end{array}]}^{T},$$## (98)

$$\mathbf{n}={\mathcal{H}}_{f}[{\mathbf{\beta}}_{a}]\times {\mathcal{H}}_{f}[{\mathbf{\beta}}_{b}]\phantom{\rule{0ex}{0ex}}={\mathbf{q}}_{3}/\lambda ,$$## (99)

$${\mathbf{q}}_{3}=\mathbf{n}/\Vert \mathbf{n}\Vert \phantom{\rule{0ex}{0ex}}=\frac{{K}^{T}[({\mathbf{m}}_{3}\times {\mathbf{m}}_{4})\times ({\mathbf{m}}_{5}\times {\mathbf{m}}_{6})]}{\Vert {K}^{T}[({\mathbf{m}}_{3}\times {\mathbf{m}}_{4})\times ({\mathbf{m}}_{5}\times {\mathbf{m}}_{6})]\Vert}.$$## 6.2.2.

#### Translation vector

The translation vector $\mathbf{s}$ is obtained by taking into account that ${\mathcal{P}}_{G}$ preserves the line–line intersection. Thus, from Eq. (65) we have ${\mathbf{\mu}}_{0}={\mathcal{P}}_{G}[{\mathbf{\rho}}_{0}]$ with ${\mathbf{\rho}}_{0}={\mathbf{0}}_{2}$. Therefore, from Eq. (88) we have

## (100)

$${\mathcal{H}}_{f}[{\mathbf{\beta}}_{0}]=\overline{\mathrm{\Pi}}\mathcal{H}[{\mathbf{0}}_{2}]/\xi \phantom{\rule{0ex}{0ex}}=\mathbf{s}/\xi ,$$## (101)

$${\mathbf{p}}_{k}={\zeta}_{k}{\mathcal{H}}_{f}[{\mathbf{\beta}}_{k}],\phantom{\rule[-0.0ex]{2em}{0.0ex}}k=1,\cdots ,4,$$## (102)

$${\zeta}_{k}=\xi \frac{{\mathbf{q}}_{3}^{T}{\mathcal{H}}_{f}[{\mathbf{\beta}}_{0}]}{{\mathbf{q}}_{3}^{T}{\mathcal{H}}_{f}[{\mathbf{\beta}}_{k}]}.$$## (103)

$${\xi}_{k}={\Vert \frac{{\mathbf{q}}_{3}^{T}{\mathcal{H}}_{f}[{\mathbf{\beta}}_{0}]}{{\mathbf{q}}_{3}^{T}{\mathcal{H}}_{f}[{\mathbf{\beta}}_{k}]}{\mathcal{H}}_{f}[{\mathbf{\beta}}_{k}]-{\mathcal{H}}_{f}[{\mathbf{\beta}}_{0}]\Vert}^{-1},$$## 6.2.3.

#### Euler angles

The reference plane is fully characterized by six degrees of freedom (DOF), namely position (three coordinates) and orientation (three angles). The vectors ${\mathbf{q}}_{3}$ and $\mathbf{s}$ provide five DOFs. Specifically, the vector $\mathbf{s}$ provides three DOFs that fix the position while ${\mathbf{q}}_{3}$ provides two DOFs defining the orientation by the azimuth and polar angles given, respectively, by

## (105)

$$\mathrm{tan}\text{\hspace{0.17em}}\varphi ={q}_{23}/{q}_{13},\phantom{\rule{0ex}{0ex}}\mathrm{cos}\text{\hspace{0.17em}}\theta ={q}_{33},$$From Eqs. (84) and (53), we have

where the matrix $Q$ is defined as the Euler sequence with ${Q}_{z}$ and ${Q}_{y}$ being the rotation matrices around the $z$- and $y$-axes, respectively. Thus, using Eq. (101), the estimated vector $\mathbf{s}$, and the angles $\theta $ and $\varphi $, we compute the (perspective corrected) points## (108)

$${\mathbf{\delta}}_{k}={\mathcal{H}}_{0}^{-1}[{Q}_{y}^{T}(\theta ){Q}_{z}{(\varphi )}^{T}({\mathbf{p}}_{k}-\mathbf{s})]=\left[\begin{array}{c}{\delta}_{xk}\\ {\delta}_{yk}\end{array}\right],$$## (110)

$${\overline{Q}}_{z}^{T}(\gamma )=\left[\begin{array}{cc}\mathrm{cos}\text{\hspace{0.17em}}\gamma & \mathrm{sin}\text{\hspace{0.17em}}\gamma \\ -\mathrm{sin}\text{\hspace{0.17em}}\gamma & \mathrm{cos}\text{\hspace{0.17em}}\gamma \end{array}\right].$$## (111)

$${\overline{Q}}_{z}^{T}(\gamma ){\mathbf{\delta}}_{2}=T{\overline{Q}}_{z}^{T}(\gamma ){\mathbf{\delta}}_{1},\phantom{\rule{0ex}{0ex}}{\overline{Q}}_{z}^{T}(\gamma ){\mathbf{\delta}}_{4}=T{\overline{Q}}_{z}^{T}(\gamma ){\mathbf{\delta}}_{3}.$$## (113)

$$\mathcal{B}[{\mathbf{\delta}}_{k}]=\left[\begin{array}{cc}{\delta}_{yk}& {\delta}_{xk}\\ -{\delta}_{xk}& {\delta}_{yk}\end{array}\right].$$## (115)

$$\mathbb{B}=\left[\begin{array}{c}\mathcal{B}[{\mathbf{\delta}}_{2}]-T\mathcal{B}[{\mathbf{\delta}}_{1}]\\ \mathcal{B}[{\mathbf{\delta}}_{4}]-T\mathcal{B}[{\mathbf{\delta}}_{3}]\end{array}\right].$$## 6.3.

### Illustrative Example

The functionality of the presented algorithm is illustrated by the following example. The camera described in Appendix B and the estimated intrinsic parameters $K$ given in Eq. (156) are used here.

Figure 11(a) shows the image of a rectangular object acquired by the camera. Then, the four corners of the quadrilateral are marked from the image as shown by the yellow circles in Fig. 11(b). The points ${\mathbf{\mu}}_{0}$, ${\mathbf{\mu}}_{a}$, and ${\mathbf{\mu}}_{b}$ are indicated by the red circles in Fig. 11(b). It is worth mentioning that ${\mathbf{\mu}}_{a}$, or ${\mathbf{\mu}}_{b}$, or both could be points at infinity. Even in these cases, the presented methodology is valid.

The information estimated with the four corners are

## (117)

$$\mathbf{s}={[\begin{array}{ccc}-0.2289& 0.0561& 2.9236\end{array}]}^{T},\phantom{\rule{0ex}{0ex}}\varphi =0.6776,\phantom{\rule{0ex}{0ex}}\theta =0.9879,\phantom{\rule{0ex}{0ex}}\gamma =2.3041.$$## (118)

$$\mathrm{\Pi}=\left[\begin{array}{ccc}-0.7528& 0.1010& -0.2289\\ 0.3478& -0.7779& 0.0561\\ 0.5588& 0.6202& 2.9236\end{array}\right].$$## (119)

$$G=\left[\begin{array}{ccc}-2.0219& 0.2429& -0.7272\\ 0.9237& -2.0786& 0.1298\\ 0.5588& 0.6202& 2.9236\end{array}\right].$$With the correction of perspective, the yellow circles in Fig. 11(b) become the green ones in Fig. 11(c). The region of interest is the rectangle with corners marked by green circles in Fig. 11(c). Finally, a zoom of the region of interest is shown in Fig. 11(d).

## 7.

## Conclusions

An operator-based approach for homogeneous coordinates was proposed. Several basic geometrical concepts and properties of the operators were investigated. With the proposed approach, the pinhole camera model and a simple camera calibration method were described. The study of this work was motivated by developing a perspective correction method useful for a camera document scanning application. Several experimental results illustrate the analyzed theoretical aspects. The proposed approach could be a good starting point to introduce inexperienced students in the scientific discipline of computer vision.

## Appendices

## Appendix A:

### Estimation of the Homography Matrix

In this appendix, we illustrate the method known as direct linear transformation for homography matrix estimation. This method is very useful for illustration purposes because of its simplicity. However, the highest accuracy and robustness are reached with other advanced methods available in the literature.^{9}^{,}^{13}

Let $G$ be the homography matrix defined in Eq. (86). Consider that the matrix $G$ is row partitioned as follows:

## (120)

$$G=\left[\begin{array}{ccc}{g}_{11}& {g}_{12}& {g}_{13}\\ {g}_{21}& {g}_{22}& {g}_{23}\\ {g}_{31}& {g}_{32}& {g}_{33}\end{array}\right]=\left[\begin{array}{c}{\overline{\mathbf{g}}}_{1}^{T}\\ {\overline{\mathbf{g}}}_{2}^{T}\\ {\overline{\mathbf{g}}}_{3}^{T}\end{array}\right],$$## (121)

$${\overline{\mathbf{g}}}_{1}^{T}=[\begin{array}{ccc}{g}_{11}& {g}_{12}& {g}_{13}\end{array}],\phantom{\rule{0ex}{0ex}}{\overline{\mathbf{g}}}_{2}^{T}=[\begin{array}{ccc}{g}_{21}& {g}_{22}& {g}_{23}\end{array}],\phantom{\rule{0ex}{0ex}}{\overline{\mathbf{g}}}_{3}^{T}=[\begin{array}{ccc}{g}_{31}& {g}_{32}& {g}_{33}\end{array}].$$Equation (85), which relates points of the reference and image planes, can be rewritten as

## (122)

$$\mathbf{\mu}=\left[\begin{array}{c}u\\ v\end{array}\right]=\frac{1}{{\overline{\mathbf{g}}}_{3}^{T}\mathcal{H}[\rho ]}\left[\begin{array}{c}{\overline{\mathbf{g}}}_{1}^{T}\mathcal{H}[\mathbf{\rho}]\\ {\overline{\mathbf{g}}}_{2}^{T}\mathcal{H}[\mathbf{\rho}]\end{array}\right],$$## (123)

$$\left[\begin{array}{c}u{\overline{\mathbf{g}}}_{3}^{T}\mathcal{H}[\mathbf{\rho}]\\ v{\overline{\mathbf{g}}}_{3}^{T}\mathcal{H}[\mathbf{\rho}]\end{array}\right]=\left[\begin{array}{c}{\overline{\mathbf{g}}}_{1}^{T}\mathcal{H}[\mathbf{\rho}]\\ {\overline{\mathbf{g}}}_{2}^{T}\mathcal{H}[\mathbf{\rho}]\end{array}\right].$$Furthermore, Eq. (123) can be written in matrix form as

where## (125)

$$A=\left[\begin{array}{ccc}\mathcal{H}{[\mathbf{\rho}]}^{T}& {\mathbf{0}}_{3}^{T}& -u\mathcal{H}{[\mathbf{\rho}]}^{T}\\ {\mathbf{0}}_{3}^{T}& \mathcal{H}{[\mathbf{\rho}]}^{T}& -v\mathcal{H}{[\mathbf{\rho}]}^{T}\end{array}\right],\phantom{\rule{0ex}{0ex}}\overline{\mathbf{g}}={[\begin{array}{ccc}{\overline{\mathbf{g}}}_{1}^{T}& {\overline{\mathbf{g}}}_{2}^{T}& {\overline{\mathbf{g}}}_{3}^{T}\end{array}]}^{T}.$$Equation (124) relates a single point $\mathbf{\rho}$ on the reference plane with the corresponding point $\mathbf{\mu}$ on the image plane. If $n$ pairs $({\mathbf{\rho}}_{k},{\mathbf{\mu}}_{k})$, with $k=\mathrm{1,2},\cdots n$, are available, the $n$ corresponding equations of the form Eq. (124) can be written as

where## (127)

$$\mathbb{A}={[\begin{array}{cccc}{A}_{1}^{T}& {A}_{2}^{T}& \cdots & {A}_{n}^{T}\end{array}]}^{T},\phantom{\rule{0ex}{0ex}}{A}_{k}=\left[\begin{array}{ccc}\mathcal{H}{[{\mathbf{\rho}}_{k}]}^{T}& {\mathbf{0}}_{3}^{T}& -{u}_{k}\mathcal{H}{[{\mathbf{\rho}}_{k}]}^{T}\\ {\mathbf{0}}_{3}^{T}& \mathcal{H}{[{\mathbf{\rho}}_{k}]}^{T}& -{v}_{k}\mathcal{H}{[{\mathbf{\rho}}_{k}]}^{T}\end{array}\right].$$The nontrivial solution $\overline{\mathbf{g}}$ of Eq. (126) can be obtained using the constraint $\Vert \overline{\mathbf{g}}\Vert =1$. Thus, by using the singular value decomposition of $\mathbb{A}$, the solution for $\overline{\mathbf{g}}$ is the right-singular vector corresponding to the smallest singular value of $\mathbb{A}$, see Appendix C of Ref. 14.

The application of this method is illustrated as follows. Consider the image shown in Fig. 12(a). A letter size paper printed with the *Melencolia I* by Albrecht Dürer is in the scene. Using the aspect ratio $1:1.2941$ of the letter paper, the coordinates of the corners are fixed to

## (128)

$${\mathbf{\rho}}_{1}={[1,1.2941]}^{T},\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{\rho}}_{3}=-{\mathbf{\rho}}_{1},\phantom{\rule{0ex}{0ex}}{\mathbf{\rho}}_{2}={[-1,1.2941]}^{T},\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{\rho}}_{4}=-{\mathbf{\rho}}_{2}.$$The coordinates of the imaged corners are

## (129)

$${\mathbf{\mu}}_{1}={[-0.2858,0.5661]}^{T},\phantom{\rule{0ex}{0ex}}{\mathbf{\mu}}_{2}={[0.3826,-0.0938]}^{T},\phantom{\rule{0ex}{0ex}}{\mathbf{\mu}}_{3}={[-0.2884,-0.5403]}^{T},\phantom{\rule{0ex}{0ex}}{\mathbf{\mu}}_{4}={[-0.8479,-0.1135]}^{T},$$## (130)

$$G=\left[\begin{array}{ccc}-0.2437& 0.2292& -0.2442\\ 0.2258& 0.1870& -0.0888\\ -0.0524& -0.0989& 0.8497\end{array}\right].$$The homography $G$ fully defines a pinhole imaging process. Thus, it can be inversed to obtain an undistorted view of the reference plane from its perspective distorted image. Specifically, using Eq. (89) all points $\mathbf{\mu}$ of the image are transformed to points $\mathbf{\rho}$ of the reference plane. Then, the pixels of the image are displayed at the points $\mathbf{\rho}$ as shown in Fig. 12(b). Note that corners of the paper in the corrected image are at the coordinates specified by Eq. (128).

The least number of point correspondences for two-dimensional homography estimation is four. However, the accuracy of the estimation is improved when more than four point correspondences are provided. For this reason, checkerboard patterns^{15} and gratings^{16}^{,}^{17} are useful target objects. In this appendix, the corner points of the imaged rectangle where obtained manually from the image. However, the corner points can be obtained automatically using checkerboard patterns or gratings along with grid detection^{18} or phase demodulation,^{19} respectively.

## Appendix B:

### Camera Parameters from Homographies

The homography matrix involves both intrinsic $K$ and extrinsic $L$ camera parameters as well as the reference plane parameters $\mathrm{\Pi}$. In this appendix, we show how to obtain the intrinsic and extrinsic camera parameters from several homographies.

## B.1.

#### Intrinsic Camera Parameters

Consider that the reference plane is the $xy$-plane of the world coordinate system; i.e., $\mathbf{s}={\mathbf{0}}_{3}$ and

In this case, the homography $G$, defined in Eq. (86), is reduced to

## (132)

$$G=K[\begin{array}{ccc}{\overline{\mathbf{r}}}_{1}& {\overline{\mathbf{r}}}_{2}& -{R}^{T}\mathbf{t}\end{array}],$$## (133)

$$G=\left[\begin{array}{ccc}{g}_{11}& {g}_{12}& {g}_{13}\\ {g}_{21}& {g}_{22}& {g}_{23}\\ {g}_{31}& {g}_{32}& {g}_{33}\end{array}\right]=[\begin{array}{ccc}{\mathbf{g}}_{1}& {\mathbf{g}}_{2}& {\mathbf{g}}_{\mathbf{3}}\end{array}],$$## (134)

$${\mathbf{g}}_{1}=\left[\begin{array}{c}{g}_{11}\\ {g}_{21}\\ {g}_{31}\end{array}\right],\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{g}}_{2}=\left[\begin{array}{c}{g}_{12}\\ {g}_{22}\\ {g}_{32}\end{array}\right],\phantom{\rule[-0.0ex]{1em}{0.0ex}}{\mathbf{g}}_{3}=\left[\begin{array}{c}{g}_{13}\\ {g}_{23}\\ {g}_{33}\end{array}\right].$$Thus, Eq. (132) can be written as

## (135)

$$[\begin{array}{ccc}{\overline{\mathbf{r}}}_{1}& {\overline{\mathbf{r}}}_{2}& -{R}^{T}\mathbf{t}\end{array}]={K}^{-1}[\begin{array}{ccc}{\mathbf{g}}_{1}& {\mathbf{g}}_{2}& {\mathbf{g}}_{3}\end{array}].$$Since ${\overline{\mathbf{r}}}_{1}$ and ${\overline{\mathbf{r}}}_{2}$ are orthonormal vectors (${\overline{\mathbf{r}}}_{1}$ and ${\overline{\mathbf{r}}}_{2}$ are rows of a rotation matrix), we have the following two constraints ${\overline{\mathbf{r}}}_{1}^{T}{\overline{\mathbf{r}}}_{2}=0$ and ${\Vert {\overline{\mathbf{r}}}_{1}\Vert}^{2}={\Vert {\overline{\mathbf{r}}}_{2}\Vert}^{2}$, which can be written as

## (136)

$${\mathbf{g}}_{1}^{T}W{\mathbf{g}}_{2}=0,\phantom{\rule{0ex}{0ex}}{\mathbf{g}}_{1}^{T}W{\mathbf{g}}_{1}={\mathbf{g}}_{2}^{T}W{\mathbf{g}}_{2},$$## (137)

$$W={K}^{-T}{K}^{-1}=\left[\begin{array}{ccc}{w}_{11}& {w}_{12}& {w}_{13}\\ {w}_{12}& {w}_{22}& {w}_{23}\\ {w}_{13}& {w}_{23}& {w}_{33}\end{array}\right].$$The bilinear form ${\mathbf{g}}_{i}^{T}W{\mathbf{g}}_{j}$ can be rewritten as

where## (139)

$${\mathcal{V}}_{ij}[G]={\left[\begin{array}{c}{g}_{1i}{g}_{1j}\\ {g}_{2i}{g}_{2j}\\ {g}_{3i}{g}_{3j}\\ {g}_{2i}{g}_{1j}+{g}_{1i}{g}_{2j}\\ {g}_{3i}{g}_{1j}+{g}_{1i}{g}_{3j}\\ {g}_{3i}{g}_{2j}+{g}_{2i}{g}_{3j}\end{array}\right]}^{T},$$## (140)

$$\mathbf{w}={[\begin{array}{cccccc}{w}_{11}& {w}_{22}& {w}_{33}& {w}_{12}& {w}_{13}& {w}_{23}\end{array}]}^{T}.$$Then, the constraints given by Eq. (136) become

where $V[G]$ is the following $2\times 6$ matrix:## (142)

$$V[G]=\left[\begin{array}{c}{\mathcal{V}}_{12}[G]\\ {\mathcal{V}}_{11}[G]-{\mathcal{V}}_{22}[G]\end{array}\right].$$A nontrivial solution of Eq. (141) for $\mathbf{w}$ can be obtained using several homographies ${G}_{k}$, $k=\mathrm{1,2},\cdots ,m$. For this, we compute the homographies of different images where the position and orientation of the reference plane (or the camera, or both) are varying (in an unknown manner) while the intrinsic camera parameters remain constant. Thus, we solve the new matrix equation

where## (144)

$$\mathbb{V}={[\begin{array}{cccc}V{[{G}_{1}]}^{T}& V{[{G}_{2}]}^{T}& \cdots & V{[{G}_{m}]}^{T}\end{array}]}^{T}.$$In general, at least three homographies ($m=3$) are required. However, two homographies are sufficient assuming zero-skew.

Equation (143) can be solved for $\mathbf{w}$ using the singular value decomposition method, see Appendix C of Ref. 14. Since the obtained solution, labeled as $\tilde{\mathbf{w}}$, is unique up to scale, the associated matrix $\tilde{W}$ is related to $W$ by

where $\lambda \ne 0$ is an unknown constant. With the estimated matrix $\tilde{W}$, the unknown scalar $\lambda $ and the entries ${k}_{ij}$ of the intrinsic parameter matrix## (146)

$$K=\left[\begin{array}{ccc}{k}_{11}& {k}_{12}& {k}_{13}\\ 0& {k}_{22}& {k}_{23}\\ 0& 0& 1\end{array}\right],$$## (147)

$$\lambda =(\mathrm{det}\text{\hspace{0.17em}}\tilde{W})/d,\phantom{\rule{0ex}{0ex}}{k}_{11}=\sqrt{\lambda /{\tilde{w}}_{11}},\phantom{\rule{0ex}{0ex}}{k}_{22}=\sqrt{\lambda {\tilde{w}}_{11}/d},\phantom{\rule{0ex}{0ex}}{k}_{12}=-{\tilde{w}}_{12}\sqrt{\lambda /{\tilde{w}}_{11}d},\phantom{\rule{0ex}{0ex}}{k}_{13}=({\tilde{w}}_{12}{\tilde{w}}_{23}-{\tilde{w}}_{22}{\tilde{w}}_{13})/d,\phantom{\rule{0ex}{0ex}}{k}_{23}=({\tilde{w}}_{12}{\tilde{w}}_{13}-{\tilde{w}}_{11}{\tilde{w}}_{23})/d,$$It is worth mentioning that the intrinsic camera parameters ($f$, ${s}_{x}$, ${s}_{y}$, ${\tau}_{x}$, ${\tau}_{y}$, and $\sigma $) cannot be obtained using only the matrix $K$. Fortunately, the matrix $K$ is sufficient for many computer vision tasks. For the case where the intrinsic camera parameters are required explicitly, we can assume that the skew and size of the pixel are known (e.g., ${s}_{x}$, ${s}_{y}$, and $\sigma $ are consulted in the datasheet of the camera sensor). Thus, the estimation of the remaining intrinsic parameters is a linear problem with the least-squares solution

## B.2.

#### Extrinsic Camera Parameters

Once the matrix $K$ is available, the rotation matrix $R$ and the translation vector $\mathbf{t}$ can be estimated for each provided homography as follows. First, we compute the estimate ${\tilde{R}}^{T}$ of the matrix ${R}^{T}$ as

## (151)

$${\tilde{R}}^{T}=[\begin{array}{ccc}{\mathbf{h}}_{1}& {\mathbf{h}}_{2}& {\mathbf{h}}_{1}\times {\mathbf{h}}_{2}\end{array}],$$## (152)

$${\mathbf{h}}_{1}={K}^{-1}{\mathbf{g}}_{1},\phantom{\rule{0ex}{0ex}}{\mathbf{h}}_{2}={K}^{-1}{\mathbf{g}}_{2}.$$Then, the rotation matrix $R$ is obtained from $\tilde{R}$ ensuring the orthogonality condition of rotation matrices. For this, the singular value decomposition $\tilde{R}=U\mathrm{\Sigma}{V}^{T}$ is obtained and the required rotation matrix is determined as

Finally, the translation vector $\mathbf{t}$ is computed as

## B.3.

#### Illustrative Example

As an example, we describe a simple experiment to obtain the intrinsic parameters of a camera. A camera with a pixel size of $6\text{\hspace{0.17em}\hspace{0.17em}}\mu \mathrm{m}$ (square pixel), resolution of $752\times 480\text{\hspace{0.17em}\hspace{0.17em}}\text{pixel}$, and imaging lens with focal length of 6 mm was used. The $3\times 3$ checkerboard pattern shown in Fig. 13(a) was printed on a letter paper. Then, 15 images of the printed pattern lying on the reference plane were captured from different unknown viewpoints, see Figs. 13(b)–13(i).

We use the coordinates of the corners shown in Fig. 13(a) as the known points ${\mathbf{\rho}}_{k}$ on the reference plane. The corresponding points ${\mathbf{\mu}}_{k}$ in the image plane were obtained by marking the corners of the checkerboard pattern in the image. Then, with the pairs $({\mathbf{\rho}}_{k},{\mathbf{\mu}}_{k})$, an homography matrix ${G}_{k}$ was computed for each acquired image. With these homographies, the matrix $\mathbb{V}$ defined in Eq. (144) was created. Then, Eq. (143) was solved for $\mathbf{w}$, the resulting matrix $\tilde{W}$ is

## (155)

$$\tilde{W}=\left[\begin{array}{ccc}-0.1389& 0.0005& -0.0058\\ 0.0005& -0.1378& -0.0008\\ -0.0058& -0.0008& -0.9806\end{array}\right].$$From this, the intrinsic parameter matrix $K$ was recovered as

## (156)

$$K=\left[\begin{array}{ccc}2.6563& -0.0103& -0.0419\\ 0& 2.6674& -0.0059\\ 0& 0& 1\end{array}\right].$$For validation purposes, we estimate the focal length using the known information ${s}_{x}={s}_{y}=6\text{\hspace{0.17em}\hspace{0.17em}}\mu \mathrm{m}$, and $\sigma =0$. The reader should note that the quantities ${s}_{x}$ and ${s}_{y}$ are defined in this experiment as

## (157)

$${s}_{x}={s}_{y}=\frac{752}{2}6\times {10}^{-3}\text{\hspace{0.17em}\hspace{0.17em}}\mathrm{mm}$$## References

O. Faugeras, Q.-T. Luong and T. Papadopoulo, The Geometry of Multiple Images: the Laws that Govern the Formation of Multiple Images of a Scene and Some of Their Applications, MIT Press, Cambridge (2004).Google Scholar

O. D. Faugeras and S. Maybank, “Motion from point matches: multiplicity of solutions,” Int. J. Comput. Vision 4(3), 225–246 (1990).IJCVEQ0920-5691http://dx.doi.org/10.1007/BF00054997Google Scholar

Z. Zhang, “A flexible new technique for camera calibration,” IEEE Trans. Pattern Anal. Mach. Intell. 22, 1330–1334 (2000).ITPIDJ0162-8828http://dx.doi.org/10.1109/34.888718Google Scholar

Y. Zhao and Y. Li, “Camera self-calibration from projection silhouettes of an object in double planar mirrors,” J. Opt. Soc. Am. A 34, 696–707 (2017).JOAOD60740-3232http://dx.doi.org/10.1364/JOSAA.34.000696Google Scholar

T. Taketomi et al., “Camera pose estimation under dynamic intrinsic parameter change for augmented reality,” Comput. Graphics 44, 11–19 (2014).http://dx.doi.org/10.1016/j.cag.2014.07.003Google Scholar

H. H. Ip and Y. Chen, “Planar rectification by solving the intersection of two circles under 2D homography,” Pattern Recognit. 38(7), 1117–1120 (2005).PTNRA80031-3203http://dx.doi.org/10.1016/j.patcog.2004.12.004Google Scholar

B. Cyganek and J. P. Siebert, An Introduction to 3D Computer Vision Techniques and Algorithms, John Wiley & Sons Ltd., Chichester, West Sussex (2009).Google Scholar

O. Faugeras, Three-Dimensional Computer Vision: a Geometric Viewpoint, Artificial Intelligence, MIT Press, Cambridge (1993).Google Scholar

R. Hartley and A. Zisserman, Multiple View Geometry in Computer Vision, Cambridge University Press, Cambridge (2003).Google Scholar

J. L. Mundy and A. Zisserman, Appendix—Projective Geometry for Machine Vision, pp. 463–519, MIT Press, Cambridge (1992).Google Scholar

W. Burger, “Zhang’s camera calibration algorithm: in-depth tutorial and implementation,” Technical Report HGB16-05, University of Applied Sciences Upper Austria, School of Informatics, Communications and Media, Department of Digital Media, Hagenberg, Austria (2016).Google Scholar

F. Devernay and O. Faugeras, “Straight lines have to be straight,” Mach. Vision Appl. 13(1), 14–24 (2001).MVAPEO0932-8092http://dx.doi.org/10.1007/PL00013269Google Scholar

H. Zeng, X. Deng and Z. Hu, “A new normalized method on line-based homography estimation,” Pattern Recognit. Lett. 29(9), 1236–1244 (2008).PRLEDG0167-8655http://dx.doi.org/10.1016/j.patrec.2008.01.031Google Scholar

Z. Zhang, “A flexible new technique for camera calibration,” Technical Report MSR-TR-98-71, Microsoft Research (1998).Google Scholar

L. Kr “Accurate chequerboard corner localisation for camera calibration,” Pattern Recognit. Lett. 32(10), 1428–1435 (2011).PRLEDG0167-8655http://dx.doi.org/10.1016/j.patrec.2011.04.002Google Scholar

R. Juarez-Salazar et al., “Camera calibration by multiplexed phase encoding of coordinate information,” Appl. Opt. 54, 4895–4906 (2015).APOPAI0003-6935http://dx.doi.org/10.1364/AO.54.004895Google Scholar

R. Juarez-Salazar, L. N. Gaxiola and V. H. Diaz-Ramirez, “Single-shot camera position estimation by crossed grating imaging,” Opt. Commun. 382, 585–594 (2017).OPCOB80030-4018http://dx.doi.org/10.1016/j.optcom.2016.08.041Google Scholar

A. Herout, M. Dubská and J. Havel, Vanishing Points, Parallel Lines, Grids, pp. 41–54, Springer, London (2013).Google Scholar

R. Juarez-Salazar, F. Guerrero-Sanchez and C. Robledo-Sanchez, “Theory and algorithms of an efficient fringe analysis technology for automatic measurement applications,” Appl. Opt. 54, 5364–5374 (2015).APOPAI0003-6935http://dx.doi.org/10.1364/AO.54.005364Google Scholar