我有一份汽车各个角度的图像文件夹。我想使用词袋方法来训练系统识别这辆车。训练完成后,如果给出该汽车的图像,它应该能够识别它。
我一直在尝试学习OpenCV中的BOW函数,以使这项工作顺利进行,并已经达到了一个水平,现在不知道该怎么做,需要一些指导。
这是我用来制作词袋的代码:
Ptr<FeatureDetector> features = FeatureDetector::create("SIFT");
Ptr<DescriptorExtractor> descriptors = DescriptorExtractor::create("SIFT");
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
//defining terms for bowkmeans trainer
TermCriteria tc(MAX_ITER + 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);
//training data now
Mat features;
Mat img = imread("c:\\1.jpg", 0);
Mat img2 = imread("c:\\2.jpg", 0);
vector<KeyPoint> keypoints, keypoints2;
features->detect(img, keypoints);
features->detect(img2,keypoints2);
descriptor->compute(img, keypoints, features);
Mat features2;
descripto->compute(img2, keypoints2, features2);
bowTrainer.add(features);
bowTrainer.add(features2);
Mat dictionary = bowTrainer.cluster();
bowDE.setVocabulary(dictionary);
这一切都基于BOW文档。
我认为在这个阶段我的系统已经被训练好了,下一步就是预测。
这就是我不知道该怎么做的地方。如果我使用SVM
或者NormalBayesClassifier
,它们都会用到"train"和"predict"这些术语。
我该如何进行预测和训练呢?非常感谢任何指导。我应该如何将分类器的训练与我的`bowDE`函数连接起来?