// Generate an approximately reconstructed face by back-projecting the eigenvectors & eigenvalues of the given (preprocessed) face.
        public static Mat ReconstructFace(BasicFaceRecognizer model, Mat preprocessedFace)
        {
            // Since we can only reconstruct the face for some types of FaceRecognizer models (ie: Eigenfaces or Fisherfaces),
            // we should surround the OpenCV calls by a try/catch block so we don't crash for other models.
            try
            {
                // Get some required data from the FaceRecognizer model.
                Mat eigenvectors   = model.getEigenVectors();
                Mat averageFaceRow = model.getMean();

                int faceHeight = preprocessedFace.rows();

                // Project the input image onto the PCA subspace.
                Mat projection = subspaceProject(eigenvectors, averageFaceRow, preprocessedFace.reshape(1, 1));
                //printMatInfo(projection, "projection");

                // Generate the reconstructed face back from the PCA subspace.
                Mat reconstructionRow = subspaceReconstruct(eigenvectors, averageFaceRow, projection);
                //printMatInfo(reconstructionRow, "reconstructionRow");

                // Convert the float row matrix to a regular 8-bit image. Note that we
                // shouldn't use "getImageFrom1DFloatMat()" because we don't want to normalize
                // the data since it is already at the perfect scale.

                // Make it a rectangular shaped image instead of a single row.
                Mat reconstructionMat = reconstructionRow.reshape(1, faceHeight);
                // Convert the floating-point pixels to regular 8-bit uchar pixels.
                Mat reconstructedFace = new Mat(reconstructionMat.size(), CvType.CV_8UC1);
                reconstructionMat.convertTo(reconstructedFace, CvType.CV_8UC1, 1, 0);
                //printMatInfo(reconstructedFace, "reconstructedFace");

                return(reconstructedFace);
            }
            catch (CvException e)
            {
                Debug.Log("WARNING: Missing FaceRecognizer properties." + e);
                return(new Mat());
            }
        }