title: How to train my data only once
body: <p>This is my code , which i am using for train the dataset but whenever i run the code it again start vectorization and feature counting training etc , and it takes time every time whenever i start , i want it that it should train ones and not takes time again and again</p>
  
  <pre><code>    int _tmain(int argc, _TCHAR* argv[])
      {
  
      int i,j;
      IplImage *img2;
      cout&lt;&lt;"Vector quantization..."&lt;&lt;endl;
      collectclasscentroids();
      vector&lt;Mat&gt; descriptors = bowTrainer.getDescriptors();
      int count=0;
      for(vector&lt;Mat&gt;::iterator iter=descriptors.begin();iter!=descriptors.end();iter++)
      {
         count += iter-&gt;rows;
      }
      cout&lt;&lt;"Clustering "&lt;&lt;count&lt;&lt;" features"&lt;&lt;endl;
      //choosing cluster's centroids as dictionary's words
      Mat dictionary = bowTrainer.cluster();
      bowDE.setVocabulary(dictionary);
      cout&lt;&lt;"extracting histograms in the form of BOW for each image "&lt;&lt;endl;
      Mat labels(0, 1, CV_32FC1);
      Mat trainingData(0, dictionarySize, CV_32FC1);
      int k = 0;
      vector&lt;KeyPoint&gt; keypoint1;
      Mat bowDescriptor1;
      //extracting histogram in the form of bow for each image 
     for(j = 1; j &lt;= 4; j++)
      for(i = 1; i &lt;= 60; i++)
              {
                sprintf( ch,"%s%d%s%d%s","train/",j," (",i,").jpg");
                const char* imageName = ch;
                img2 = cvLoadImage(imageName, 0); 
                detector.detect(img2, keypoint1);
                bowDE.compute(img2, keypoint1, bowDescriptor1);
                trainingData.push_back(bowDescriptor1);
                labels.push_back((float) j);
               }
      //Setting up SVM parameters
      CvSVMParams params;
      params.kernel_type = CvSVM::RBF;
      params.svm_type = CvSVM::C_SVC;
      params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 0.000001);
      CvSVM svm;
  
  
  
      printf("%s\n", "Training SVM classifier");
  
      bool res = svm.train(trainingData, labels, cv::Mat(), cv::Mat(), params);
  
      cout&lt;&lt;"Processing evaluation data..."&lt;&lt;endl;
  
  
      Mat groundTruth(0, 1, CV_32FC1);
      Mat evalData(0, dictionarySize, CV_32FC1);
      k = 0;
      vector&lt;KeyPoint&gt; keypoint2;
      Mat bowDescriptor2;
  
  
      Mat results(0, 1, CV_32FC1);;
      for(j = 1; j &lt;= 4; j++)
        for(i = 1; i &lt;= 60; i++)
           {
             sprintf( ch, "%s%d%s%d%s", "eval/", j, " (",i,").jpg");
             const char* imageName = ch;
             img2 = cvLoadImage(imageName,0);
             detector.detect(img2, keypoint2);
             bowDE.compute(img2, keypoint2, bowDescriptor2);
             evalData.push_back(bowDescriptor2);
             groundTruth.push_back((float) j);
             float response = svm.predict(bowDescriptor2);
             results.push_back(response);
           }
  </code></pre>
  
  <p>I just learn about the method to save the file of trained data like <code>train.xml</code> and than use it in prediction , but i am not clear about it and its use</p>