Lda projection in opencv c++ return Mat with nan values ? there is a explanation ??
Lda train with images, reshaped(1,1) and integers labels.
vector<Mat> train_vect;
Mat labels;
Mat test, test_label;
vector<Mat> test_vect;
int SI = 60;
for (int i = 1; i <= 4; i++) {
String name = names[0];
string file_name = name + to_string(i) + ".pgm";
Mat img = imread("test_images\\" + file_name, CV_LOAD_IMAGE_GRAYSCALE);
resize(img, img, Size(SI, SI));
img.convertTo(img, CV_32FC1);
vector<Mat> fusion = get_layers_fusion(img);
if (i < 3) {
for (Mat cur : fusion) train_vect.push_back(cur), labels.push_back(1);
}
else {
for (Mat cur : fusion) test_vect.push_back(cur), test_label.push_back(1);
}
}
for (int i = 1; i <= 4; i++) {
String name = names[1];
string file_name = name + to_string(i) + ".pgm";
Mat img = imread("test_images\\" + file_name, CV_LOAD_IMAGE_GRAYSCALE);
resize(img, img, Size(SI, SI));
img.convertTo(img, CV_32FC1);
vector<Mat> fusion = get_layers_fusion(img);
if (i < 3) {
for (Mat cur : fusion) train_vect.push_back(cur), labels.push_back(2);
}
else {
for (Mat cur : fusion) test_vect.push_back(cur), test_label.push_back(2);
}
}
for (int i = 0; i < train_vect.size(); i++) { train.push_back(train_vect[i].reshape(1, 1)); } for (int i = 0; i < test_vect.size(); i++) { test.push_back(test_vect[i].reshape(1, 1)); } LDA lda(train, labels , 2);
cout << "fin compute " << endl;
Mat project_train = lda.project(train);
Mat test_projection = lda.project(test);
cout << "project_Train " << project_train << endl;
cout << "prject_test " << test_projection << endl;
do you have a small, reproducable example ? please add to your question
yeaah, i add a example.
sorry, but that's not at all "a minimal, reproducable example" (noone can run it)
apart from that, try normalizing your features to [0..1]
thank you, it work when i normalize features to [0..1] :D