Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

try with a multiclass SVM first, it's far easier than juggling multiple SVM instances.

Mat trainData, trainLabels; // initially empty
for each video in the trainset {
       // extract the feature, put it into a Mat
       feature.convertTo(feature, CV_32F); // make sure we got float data
       trainData.push_back(feature.reshape(1,1)); // as a flat column
       trainLabels.push_back(7); // the classlabel of your video as *integer* number
}

at this point, your trainData should be [sizeOfYourFeatures x numVideos] (CV_32F)

and the trainLabels should be [1 x numVideos] (CV_32S)

Ptr<SVM> svm = SVM::create();
svm->train(trainingData, ROW_SAMPLE, trainLabels);

testing goes similar:

int correct = 0;
for each video in the testset {
       // extract the feature, put it into a Mat
       feature.convertTo(feature, CV_32F); // make sure we got float data
       int predicted = svm->predict(feature.reshape(1,1)); // as a flat column
       int groundtruth = ??? // the expected classlabel for your video
       correct += (predicted == groundtruth);
}

float accuracy = (float)correct / numTestVideos;

try with a multiclass SVM first, it's far easier than juggling multiple SVM instances.

Mat trainData, trainLabels; // initially empty
for each video in the trainset {
       // extract the feature, put it into a Mat
       feature.convertTo(feature, CV_32F); // make sure we got float data
       trainData.push_back(feature.reshape(1,1)); // as a flat column
       trainLabels.push_back(7); // the classlabel of your video as *integer* number
}

at this point, your trainData should be [sizeOfYourFeatures x numVideos] (CV_32F)

and the trainLabels should be [1 x numVideos] (CV_32S)

Ptr<SVM> svm = SVM::create();
svm->train(trainingData, svm->train(trainData, ROW_SAMPLE, trainLabels);

testing goes similar:

int correct = 0;
for each video in the testset {
       // extract the feature, put it into a Mat
       feature.convertTo(feature, CV_32F); // make sure we got float data
       int predicted = svm->predict(feature.reshape(1,1)); // as a flat column
       int groundtruth = ??? // the expected classlabel for your video
       correct += (predicted == groundtruth);
}

float accuracy = (float)correct / numTestVideos;