It is important that the faces are all aligned together, otherwise the face recognition algorithm might be comparing part of a nose with part of an eye, and so on. The output of face detection just seen will give aligned faces to some extent, but it is not very accurate (that is, the face rectangle will not always be starting from the same point on the forehead).
To have better alignment we will use eye detection to align the face so the positions of the two detected eyes line up perfectly in desired positions. We will do the geometrical transformation using the warpAffine() function, which is a single operation that will do four things: