1

I' m trying to create my own SVM classifier, and i stuck at the beginning. I have two sets of data for positive and negative images, and i want to create training matrix, to pass it into SVM. So i read this fundamental post, and tried to do as it says:

char* path_positive, path_negative;
int numPos, numNeg;
int imageWidth=130;
int imageHeight=160;

numPos= 176;
numNeg= 735;
path_positive= "C:\\SVM\\positive\\";
path_negative= "C:\\SVM\negative\\";

Mat classes(numPos+numNeg, 1, CV_32FC1);
Mat trainingMat(numPos+numNeg, imageWidth*imageHeight, CV_32FC1 );
vector<int> trainingLabels;

for(int file_num=0; file_num < numPos; file_num++)
{
    stringstream ss(stringstream::in | stringstream::out);
    ss << path_positive << file_num << ".jpg";
    Mat img = imread(ss.str(), CV_LOAD_IMAGE_GRAYSCALE);

    int ii = 0; // Current column in training_mat
        for (int i = 0; i<img.rows; i++) {
            for (int j = 0; j < img.cols; j++) {
                trainingMat.at<float>(file_num,ii++) = trainingMat.at<uchar>(i,j);
            }
    }
    trainingLabels.push_back(1);
}

But when i start this code i got Assertation failderror: I know, that i made some stupid mistake, because i'm very new to openCV. Thanks for any help.

EDIT: The error occurs on this : trainingMat.at(file_num,ii++) = trainingMat.at(i,j);

Community
  • 1
  • 1
pavel_s
  • 465
  • 1
  • 7
  • 27

0 Answers0