Lda projection in opencv c++ return Mat with nan values ? there is a explanation ??

asked 2019-04-15 11:35:08 -0500

omarlahia gravatar image

updated 2019-04-15 11:51:37 -0500

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;
edit retag flag offensive close merge delete

Comments

do you have a small, reproducable example ? please add to your question

berak gravatar imageberak ( 2019-04-15 11:44:30 -0500 )edit

yeaah, i add a example.

omarlahia gravatar imageomarlahia ( 2019-04-15 11:52:34 -0500 )edit

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]

berak gravatar imageberak ( 2019-04-17 02:14:02 -0500 )edit

thank you, it work when i normalize features to [0..1] :D

omarlahia gravatar imageomarlahia ( 2019-04-17 07:45:46 -0500 )edit