本文整理汇总了C++中BFMatcher::train方法的典型用法代码示例。如果您正苦于以下问题:C++ BFMatcher::train方法的具体用法?C++ BFMatcher::train怎么用?C++ BFMatcher::train使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BFMatcher
的用法示例。
在下文中一共展示了BFMatcher::train方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: train
void YawAngleEstimator::train()
{
printf("YawAngleEstimator:train\n");
vector<vector<KeyPoint>> kp(AngleNum,vector<KeyPoint>());
vector<Mat> descriptors(AngleNum,Mat());
featureExtract(YawTemplate, kp, descriptors, Feature);
if (useIndex)
{
//build Index with Lsh and Hamming distance
for (int i = 0; i < AngleNum; i++)
{
flann::Index tempIndex;
if (Feature == USE_SIFT)
{
tempIndex.build(descriptors[i], flann::KDTreeIndexParams(4), cvflann::FLANN_DIST_L2);
}
else
{
tempIndex.build(descriptors[i], flann::LshIndexParams(12, 20, 2), cvflann::FLANN_DIST_HAMMING);
}
YawIndex.push_back(tempIndex);
}
}
else
{
//build BFMathers
for (int i = 0; i < AngleNum; i++)
{
//record
fss<<"\nKeypoints number of template "<< i <<" is "<< descriptors[i].rows << endl;
BFMatcher tempMatcher;
vector<Mat> train_des(1, descriptors[i]);
tempMatcher.add(train_des);
tempMatcher.train();
matchers.push_back(tempMatcher);
}
}
}
示例2: main
//--------------------------------------【main( )函数】-----------------------------------------
// 描述:控制台应用程序的入口函数,我们的程序从这里开始执行
//-----------------------------------------------------------------------------------------------
int main()
{
//【0】改变console字体颜色
system("color 5F");
ShowHelpText();
//【1】载入图像、显示并转化为灰度图
Mat trainImage = imread("1.jpg"), trainImage_gray;
imshow("原始图",trainImage);
cvtColor(trainImage, trainImage_gray, CV_BGR2GRAY);
//【2】检测SIFT关键点、提取训练图像描述符
vector<KeyPoint> train_keyPoint;
Mat trainDescription;
SiftFeatureDetector featureDetector;
featureDetector.detect(trainImage_gray, train_keyPoint);
SiftDescriptorExtractor featureExtractor;
featureExtractor.compute(trainImage_gray, train_keyPoint, trainDescription);
// 【3】进行基于描述符的暴力匹配
BFMatcher matcher;
vector<Mat> train_desc_collection(1, trainDescription);
matcher.add(train_desc_collection);
matcher.train();
//【4】创建视频对象、定义帧率
VideoCapture cap(0);
unsigned int frameCount = 0;//帧数
//【5】不断循环,直到q键被按下
while(char(waitKey(1)) != 'q')
{
//<1>参数设置
double time0 = static_cast<double>(getTickCount( ));//记录起始时间
Mat captureImage, captureImage_gray;
cap >> captureImage;//采集视频到testImage中
if(captureImage.empty())
continue;
//<2>转化图像到灰度
cvtColor(captureImage, captureImage_gray, CV_BGR2GRAY);
//<3>检测SURF关键点、提取测试图像描述符
vector<KeyPoint> test_keyPoint;
Mat testDescriptor;
featureDetector.detect(captureImage_gray, test_keyPoint);
featureExtractor.compute(captureImage_gray, test_keyPoint, testDescriptor);
//<4>匹配训练和测试描述符
vector<vector<DMatch> > matches;
matcher.knnMatch(testDescriptor, matches, 2);
// <5>根据劳氏算法(Lowe's algorithm),得到优秀的匹配点
vector<DMatch> goodMatches;
for(unsigned int i = 0; i < matches.size(); i++)
{
if(matches[i][0].distance < 0.6 * matches[i][1].distance)
goodMatches.push_back(matches[i][0]);
}
//<6>绘制匹配点并显示窗口
Mat dstImage;
drawMatches(captureImage, test_keyPoint, trainImage, train_keyPoint, goodMatches, dstImage);
imshow("匹配窗口", dstImage);
//<7>输出帧率信息
cout << "\t>当前帧率为:" << getTickFrequency() / (getTickCount() - time0) << endl;
}
return 0;
}