I am using SVM using opencv and below is the code i did :
string YourImagesDirectory="D:\\PIK\\";
Mat output_img;
vector<string> files=listFilesInDirectory(YourImagesDirectory+"*.jpg");
for(int i=0;i<files.size();i++)
{
Mat input_mat_positive=imread(YourImagesDirectory+files[i]);
//imshow("mainwin" , img);
resize(input_mat_positive,output_img,Size(500,300));
Mat img_mat=output_img;
int image_area=500*300;
Mat training_mat(i,image_area,CV_32FC1);
//Mat img_mat=imread(img,0);
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>(i,ii++)=img_mat.at<uchar>(i,j);
}
}
Mat labels(i,1,CV_32FC1);
CvSVMParams Params;
Params.svm_type=CvSVM::C_SVC;
Params.kernel_type=CvSVM::POLY;
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 :
I want to train my image and than i want it to recognize it from video