Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error on SVM using images

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 :

enter image description here

I want to train my image and than i want it to recognize it from video

Error on SVM using images

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);
training_mat.at<float>(i,ii++)=img_mat.at<uchar>(k,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 :

enter image description here

I want to train my image and than i want it to recognize it from video

Error on SVM using images

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>(k,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 :

enter image description here

Getting the value of int ii=0; consistently zero that may be the cause of error , but how to solve it

I want to train my image and than i want it to recognize it from video

Error on SVM using images

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);
input_mat_positive=imread(YourImagesDirectory+files[i],0);
         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);
    Mat labels(i,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>(i,ii++)=img_mat.at<uchar>(k,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 :

enter image description here

Getting the value of int ii=0; consistently zero that may be the cause of error , but how to solve it

I want to train my image and than i want it to recognize it from video

Error on SVM using images

I am using SVM using opencv and below is the code i did :

string YourImagesDirectory="D:\\PIK\\";
YourImagesDirectory="D:\\Cars\\";
Mat output_img;
vector<string> files=listFilesInDirectory(YourImagesDirectory+"*.jpg");
Mat training_mat(i,image_area,CV_32FC1);
Mat labels(i,1,CV_32FC1);
for(int i=0;i<files.size();i++)
    {
         Mat input_mat_positive=imread(YourImagesDirectory+files[i],0);
         resize(input_mat_positive,output_img,Size(500,300));
resize(input_mat_positive,output_img,Size(40,30));
         Mat img_mat=output_img;
         Mat labels(i,1,CV_32FC1);
         int image_area=500*300;
         Mat training_mat(i,image_area,CV_32FC1);
             Mat labels(i,1,CV_32FC1);
image_area=40*30;
         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>(k,j);
             }
         }
}
         CvSVMParams Params;
         Params.svm_type=CvSVM::C_SVC;
         Params.kernel_type=CvSVM::POLY;
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");
//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 :

enter image description here

Getting the value of int ii=0; consistently zero that may be the cause of error , but how to solve it

I want to train my image and than i want it to recognize it from video

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");
Mat training_mat(i,image_area,CV_32FC1);
Mat labels(i,1,CV_32FC1);
for(int i=0;i<files.size();i++)
    {
         Mat input_mat_positive=imread(YourImagesDirectory+files[i],0);
         resize(input_mat_positive,output_img,Size(40,30));
         Mat img_mat=output_img;
         Mat labels(i,1,CV_32FC1);
         int image_area=40*30;
         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>(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 :

enter image description here

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

I want to train my image and than i want it to recognize it from video

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");
for(int image_in_file=0;image_in_file<files.size();image_in_file++)
    {
         Mat training_mat(i,image_area,CV_32FC1);
Mat labels(i,1,CV_32FC1);
for(int i=0;i<files.size();i++)
    {
         Mat input_mat_positive=imread(YourImagesDirectory+files[i],0);
input_mat_positive=imread(YourImagesDirectory+files[image_in_file],0);
         resize(input_mat_positive,output_img,Size(40,30));
         Mat img_mat=output_img;
         Mat labels(i,1,CV_32FC1);
         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>(i,ii++)=img_mat.at<uchar>(k,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 :

enter image description here

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

I want to train my image and than i want it to recognize it from video

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 :

enter image description here

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

I want to train my image and than i want it to recognize it from video

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 :

enter image description here

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

I want to train my image and than i want it to recognize it from video

Now runtime error this time: image description

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 :

enter image description here

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

I want to train my image and than i want it to recognize it from video

Now runtime error this time: image description