Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

for 6 x 10 images, you will need to put 60 hog feature vectors into a single Mat, each on a row of its own, and 60 integer labels, one for each feature:

Mat features;
Mat labels;
for (each image) // a bit pseudo here, idk, how you organize your data
{
      Mat drawing = ... // ?
      int label =   ... // ? a number between 1 and 6
      Mat descr;
      hog.compute(drawing, descr, Size(1, 1), Size(0, 0));
      features.push_back(descr);
      labels.push_back(label);
}

// now you can train the svm:
Ptr<ml::SVM> svm = ml::SVM::create();
svm->setType(ml::SVM::C_SVC);
svm->setKernel(ml::SVM::LINEAR);
svm->setGamma(3);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));

Ptr<ml::TrainData> tData = ml::TrainData::create(features, ml::ROW_SAMPLE, labels);
svm->train(tData);    
svm->save("testing.xml");

for 6 x 10 images, you will need to put 60 hog feature vectors into a single Mat, each on a row of its own, and 60 integer labels, one for each feature:

Mat features;
Mat labels;
for (each image) // a bit pseudo here, idk, how you organize your data
{
      Mat drawing = ... // ?
      int label =   ... // ? a number between 1 and 6
      Mat descr;
vector<float> descriptors;
      vector<Point> location;
      hog.compute(drawing, descr, Size(1, 1), Size(0, 0));
descriptors, Size( 8, 8 ), Size( 0, 0 ), location );
      Mat descr = Mat(descriptors,true).reshape(1,1); 
      features.push_back(descr);
      labels.push_back(label);
}

// now you can train the svm:
Ptr<ml::SVM> svm = ml::SVM::create();
svm->setType(ml::SVM::C_SVC);
svm->setKernel(ml::SVM::LINEAR);
svm->setGamma(3);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));

Ptr<ml::TrainData> tData = ml::TrainData::create(features, ml::ROW_SAMPLE, labels);
svm->train(tData);    
svm->save("testing.xml");