I've trained my LDA on several thousand images and was keen to save it so that I could load it in the main program that would be doing predictions (rather than running it fresh each time). I knew that with an SVM I can use a command like this to save it:
SVM.save("tag_svm.yml");
So I tried a similar thing for LDA, and that also seemed to work:
lda.save("tag_lda.yml");
Then, in my prediction program, I load the LDA and try to project the new data:
lda.load("tag_lda.yml");
cv::Mat projected = lda.project(testData);
The loading part worked fine, however when I try to project the new data, I get this error:
OpenCV Error: Bad argument (Wrong shapes for given matrices. Was size(src) = (256,30), size(W) = (256,2).) in subspaceProject error: (-5) Wrong shapes for given matrices. Was size(src) = (256,30), size(W) = (256,2). in function subspaceProject
But that doesn't make sense to me: the data I trained the LDA on had 256 columns, it was grayscale pixel values. I did exactly the same processing for my test images as I did for my training images. If I don't bother about loading the LDA and just have the prediction stage in the same program it works perfectly, so I can't understand why this error keeps occurring, unless I'm not loading the LDA correctly.