Assuming that you know what you are doing by modifying the image and using it to train your SVM, the most likely reason for this is that your
Mat img = Highgui.imread(file.getAbsolutePath());
failed to read the image, creating an img matrix with the null data property, which ultimately will cause the following in OpenCV code:
// check parameter types and sizes if( !CV_IS_MAT(train_data) || CV_MAT_TYPE(train_data->type) != CV_32FC1 ) CV_ERROR( CV_StsBadArg, "train data must be floating-point matrix" );
Basically, train_data does not satisfy the first condition (which is a valid matrix), and not the rejection of the second condition (of type CV_32FC1).
In addition, although a change to the *this object is performed, it acts like a filter and its effect is not permanent. If it is used in one statement without immediate use or assignment of another variable, it will be useless. Change the following lines in your code:
img.reshape(1, 1); trainingImages.push_back(img);
in
trainingImages.push_back(img.reshape(1, 1));
source share