Note that our matrix is created in the line pcaset = Mat::eye(rows,cols,CV_64F) and that enough space is allocated for 2*k values. After the two for loops load the data into the matrix, the PCA constructor is called with the data—an empty matrix—that could be our precomputed mean vector, if we wish to make it only once. We also indicate that our vectors will be stored as matrix rows and that we wish to keep the same number of given rows as the number of components, though we could use just a few ones.