【发布时间】:2014-06-03 05:29:25
【问题描述】:
我有一个从跳跃运动控制器收集数据的应用程序,因为用户将其运动定义为具有特定类型的手势,因此每个手势记录都归类在特定索引下。
在用户记录自己的每个手势后,我使用该数据做一些工作并提取时刻(如果需要更多解释,我会提供)。
在另一个应用程序中,我应该根据数据集来识别手势,所以我决定使用我写的 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();
}
由于某种原因,我无法理解它总是抛出异常
在:cvPreprocessCategoricalResponses error code -5 err = "response #0 is not integral"
如果需要更多信息,我会提供。
【问题讨论】:
标签: c++ opencv classification svm leap-motion