I’m trying to generate Eigenvectors of positive and negative Eigenfaces and here is the following code:
model = cv2.face.EigenFaceRecognizer_create() model.train(np.asarray(faces), np.asarray(labels)) # Save model results model.save(test_config.TRAINING_FILE) mean = model.getMean().reshape(faces.shape) cv2.imwrite(MEAN_FILE, normalize(mean, 0, 255, dtype=np.uint8)) eigenvectors = model.getEigenVectors() pos_eigenvector = eigenvectors[:,0].reshape(faces.shape) cv2.imwrite(POSITIVE_EIGENFACE_FILE, normalize(pos_eigenvector, 0, 255, dtype=np.uint8)) neg_eigenvector = eigenvectors[:,1].reshape(faces.shape) cv2.imwrite(NEGATIVE_EIGENFACE_FILE, normalize(neg_eigenvector, 0, 255, dtype=np.uint8))
I’m getting an error from this block:
neg_eigenvector = eigenvectors[:,1].reshape(faces.shape) IndexError: index 1 is out of bounds for axis 1 with size 1
After Inspecting and Debugging the block I found out that, the line:
eigenvectors = model.getEigenVectors()
the above line is producing a black image and its vectors
[[ 0.] [ 0.] [ 0.] ..., [ 0.] [ 0.] [ 0.]]
I don’t know what happened, the eigenvectors are not generated in the first place. So, is there any fix or any other alternative ways for generating Positive and Negative Eigefaces from mean Image?
Here is the Full Code.