【发布时间】:2012-11-21 07:08:24
【问题描述】:
我有一个包含各个角度的汽车图像的文件夹。我想使用词袋方法来训练系统识别汽车。训练完成后,我希望如果给出那辆车的图像,它应该能够识别它。
为了完成这项工作,我一直在尝试学习 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 documentation。
我认为在这个阶段我的系统已经过训练。下一步就是预测。
这是我不知道该怎么做的地方。如果我使用SVM 或NormalBayesClassifier,它们都使用术语训练和预测。
在此之后我如何预测和训练?任何指导将不胜感激。如何将分类器的训练连接到我的 `bowDE` 函数?
【问题讨论】:
-
您是如何确定 TermCriteria 和 dictionarySize、tc、retries、flags 的值的?
标签: opencv machine-learning sift feature-detection