Please see the following blog post for more details about this code Eigenface using OpenCV (C++/Python)