Error on SVM using images
I am using SVM using opencv and below is the code i did :
string YourImagesDirectory="D:\\Cars\\";
Mat output_img;
vector<string> files=listFilesInDirectory(YourImagesDirectory+"*.jpg");
float labels[] = {1.0, 1.0, 1.0, 1.0 , 1.0 , 1.0 , 1.0 };
for(int image_in_file=0;image_in_file<files.size();image_in_file++)
{
Mat input_mat_positive=imread(YourImagesDirectory+files[image_in_file],0);
resize(input_mat_positive,output_img,Size(40,30));
Mat img_mat=output_img;
int image_area=40*30;
Mat training_mat(image_in_file,image_area,CV_32FC1);
Mat labels(image_in_file,1,CV_32FC1);
int ii=0; //current column in training_mat
for(int k=0;k<img_mat.rows;k++)
{
for(int j=0; j<img_mat.cols ; j++)
{
training_mat.at<float>(image_in_file,ii++)=img_mat.at<uchar>(k,j);
}
}
CvSVMParams Params;
Params.svm_type=CvSVM::C_SVC;
Params.kernel_type=CvSVM::LINEAR;
Params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
Params.gamma=3;
CvSVM svm;
svm.train(training_mat,labels,Mat(),Mat(),Params);
//svm.save("File_to_save");
//svm.load("File_to_save");*/
}
I do the code by getting help from here http://stackoverflow.com/questions/14694810/using-opencv-and-svm-with-images , but i am getting the following runtime
error :
Getting the value of int ii=0; consistently zero
that may be the cause of error , but how to solve it
I have only ONE FILE which contain images , its not so many FILES