2014-04-18 3 views
0

사용자가 특정 유형의 동작으로 동작을 정의하므로 모든 동작 레코드가 특정 인덱스로 분류되므로 윤곽 컨트롤러에서 데이터를 수집하는 응용 프로그램이 있습니다.openCV를 사용하여 데이터를 분류하는 SVM

사용자가 각 제스처에 대해 자신을 기록한 후에 데이터를 사용하여 작업을하고 순간을 추출합니다 (자세한 설명이 필요하면 제공 할 것입니다). 나는 데이터의 집합에 따라 제스처를 식별 할 수 있겠 다른 응용 프로그램에서

, 그래서 내가 쓴 SVM을 사용하기로 결정했습니다 :

void CRecognition::SVM::SVMTrain() 
    { 
     CvSVMParams params; 
     params.svm_type = CvSVM::C_SVC; 
     params.kernel_type = CvSVM::LINEAR; 
     params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6); 

     int numberofsamples = m_gMap.size(); 
     float ** labels; 
     labels = new float*[numberofsamples]; 
    int numofTotMoments = 0; 
     for(int i = 0 ; i < numberofsamples ; i++) 
     { 
      numofTotMoments += m_gMap[i]->getNumofSamples(); 
      labels[i] = new float[1]; 
      labels[i][0] = (float)(i+1); 
     } 

     double ** Newlabels = new double *[numofTotMoments]; 
     double ** templbls = Newlabels; 
     double ** trainingData = new double *[numofTotMoments]; 
     double ** temp = trainingData; 

     for (int i = 0 ; i < numberofsamples ; i++) 
     { 
      Utils::Gesture * g = m_gMap[i]; 
      for (int j = 0 ; j < m_gMap[i]->getNumofSamples() ; j++) 
      { 
       *templbls = new double [1];  
       *templbls[0] = (double)i+1; 
       *temp = (*g)[j]; //direct the pointer to an vector of moments of that gesture 
       temp++; 
       templbls++; 
      } 

     } 
    Mat matlabesls(numofTotMoments,1, CV_32FC1, Newlabels); 


     Mat mattrainingDataMat(numofTotMoments, NUM_OF_MOMENTS, CV_32FC1,trainingData); 
     try 
     { 
      // ... Contents of your main 
      m_svm.train(mattrainingDataMat,matlabesls,Mat(),Mat(),params); 
     } 
     catch (cv::Exception & e) 
     { 
      cout << e.msg() << endl; 
      cout<< "hh"; 
     } 


     this->SaveSVM(); 
    } 

어떤 이유로, 나는 항상 예외가 발생 이해할 수 없다 at : cvPreprocessCategoricalResponses error code -5 err = "response #0 is not integral"

추가 정보가 필요하면 알려주십시오.

답변

0

좋아, 내가 매트릭스 내가 공급이 배열로 초기화있어하지 않았다 어떤 이유로, 문제를 발견, 그래서 내가 루프

int countRow = 0; 
     for (int i = 0 ; i < numberofsamples ; i++) 
     { 
      Utils::Gesture * g = m_gMap[i]; 
      for (int j = 0 ; j < m_gMap[i]->getNumofSamples() ; j++) 
      { 
       *templbls = new float [1];  
       *templbls[0] = (float)i+1; 
       matlabesls1.at<float>(countRow,0) = (float)i+1; 
       templbls++; 
       *temp = new float[NUM_OF_MOMENTS]; 
       for (int k = 0 ; k < NUM_OF_MOMENTS ; k++) 
       { 
        float num = (float)((*g)[j])[k]; 
        mattrainingDataMat1.at<float>(countRow,k) = num; 
        (*temp)[k] = num; //direct the pointer to an vector of moments of that gesture 
       } 
       temp++; 
       countRow++; 
      } 

     } 

어떤 방식 덕분에 모든 사람을 위해 함께 행렬을 시작!

관련 문제