Ok, I'm trying to train an SVM using BoW. I found some code on the internet but was unable to find some explanations. For now I have this:
string to_string(const int val) {
int i = val;
std::string s;
std::stringstream out;
out << i;
s = out.str();
return s;
}
int main() {
initModule_nonfree();
Ptr<FeatureDetector> detector = FeatureDetector::create("SURF");
Ptr<DescriptorExtractor> descriptors = DescriptorExtractor::create("SURF");
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
TermCriteria tc(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 10, 0.001);
int dictionarySize = 1000;
int retries = 1;
int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor bowDE(descriptors, matcher);
string dir = "./positive_large", filepath;
DIR *dp;
struct dirent *dirp;
struct stat filestat;
dp = opendir( dir.c_str() );
Mat features;
Mat img;
vector<KeyPoint> keypoints;
int i = 0;
while(dirp = readdir(dp)) {
filepath = dir + "/" + dirp->d_name;
cout << "reading: " << filepath << endl;
if (stat( filepath.c_str(), &filestat )) continue;
if (S_ISDIR( filestat.st_mode )) continue;
img = imread(filepath, 0);
detector->detect(img, keypoints);
KeyPointsFilter::retainBest(keypoints, 1000);
descriptors->compute(img, keypoints, features);
bowTrainer.add(features);
drawKeypoints(img, keypoints, img);
string filenum = to_string(i);
string filename = "./detected_features/" + filenum + ".png";
cout << "filename: " << filename << endl;
imwrite(filename, img);
i++;
}
Mat dictionary = bowTrainer.cluster();
bowDE.setVocabulary(dictionary);
return 0;
}
So my question is can somebody explain to me what labels are used for and how to use them? I think I have some idea but a good explanation will be really helpful. Do I have to pot zeros for every negative sample and ones for every positive? What is the next step for me to do when I have the code i posted? Thank you in advance :)