資源簡介
Feature::Feature(const string& detectType, const string& extractType, const string& matchType)
{
assert(!detectType.empty());
assert(!extractType.empty());
assert(!matchType.empty());
m_detectType = detectType;
m_extractType = extractType;
m_matchType = matchType;
initModule_nonfree();
}

代碼片段和文件信息
//??局部圖像特征提取與匹配????
//??Author:??www.icvpr.com??
//??Blog??:??http://blog.csdn.net/icvpr??
??
#include?“LocalFeature.h“??
??
Feature::Feature()??
{??
????m_detectType?=?“SIFT“;??
????m_extractType?=?“SIFT“;??
????m_matchType?=?“FruteForce“;??
????initModule_nonfree();???
}??
??
Feature::~Feature()??
{??
??
}??
??
??
Feature::Feature(const?string&?detectType?const?string&?extractType?const?string&?matchType)??
{??
????assert(!detectType.empty());??
????assert(!extractType.empty());??
????assert(!matchType.empty());??
??
????m_detectType?=?detectType;??
????m_extractType?=?extractType;??
????m_matchType?=?matchType;??
????initModule_nonfree();???
}??
??
??
void?Feature::detectKeypoints(const?Mat&?image?std::vector&?keypoints)???
{??
????assert(image.type()?==?CV_8UC1);??
????assert(!m_detectType.empty());??
??
????keypoints.clear();??
????m_detector?=?FeatureDetector::create(m_detectType);??
????m_detector->detect(image?keypoints);??
??
}??
??
??
??
void?Feature::extractDescriptors(const?Mat&?image?std::vector&?keypoints?Mat&?descriptor)??
{??
????assert(image.type()?==?CV_8UC1);??
????assert(!m_extractType.empty());??
??
????m_extractor?=?DescriptorExtractor::create(m_extractType);??
????m_extractor->compute(image?keypoints?descriptor);??
??
}??
??
??
void?Feature::bestMatch(const?Mat&?queryDescriptor?Mat&?trainDescriptor?std::vector&?matches)???
{??
????assert(!queryDescriptor.empty());??
????assert(!trainDescriptor.empty());??
????assert(!m_matchType.empty());??
??
????matches.clear();??
??
????m_matcher?=?DescriptorMatcher::create(m_matchType);??
????m_matcher->add(std::vector(1?trainDescriptor));??
????m_matcher->train();??
????m_matcher->match(queryDescriptor?matches);??
??
}??
??
??
void?Feature::knnMatch(const?Mat&?queryDescriptor?Mat&?trainDescriptor?std::vector>&?matches?int?k)??
{??
????assert(k?>?0);??
????assert(!queryDescriptor.empty());??
????assert(!trainDescriptor.empty());??
????assert(!m_matchType.empty());??
??
????matches.clear();??
??
????m_matcher?=?DescriptorMatcher::create(m_matchType);??
????m_matcher->add(std::vector(1?trainDescriptor));??
????m_matcher->train();??
????m_matcher->knnMatch(queryDescriptor?matches?k);??
??
}??
??
??
??
void?Feature::saveKeypoints(const?Mat&?image?const?vector&?keypoints?const?string&?saveFileName)??
{??
????assert(!saveFileName.empty());??
??
????Mat?outImage;??
????cv::drawKeypoints(image?keypoints?outImage?Scalar(2552550)?DrawMatchesFlags::DRAW_RICH_KEYPOINTS?);??
??
????//??
????string?saveKeypointsImgName?=?saveFileName?+?“_“?+?m_detectType?+?“.jpg“;??
????imwrite(saveKeypointsImgName?outImage);??
??
}??
??
??
??
void?Feature::saveMatches(const?Mat&?queryImage??
????????????????????????????const?vector&?queryKeypoints??
????????????????????????????const?Mat&?trainImage??
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3667??2017-11-23?16:38??LocalFeature.cpp
?????文件???????1669??2017-11-23?16:37??LocalFeature.h
?????文件??????????0??2017-11-23?16:38??main.txt
-----------?---------??----------?-----??----
?????????????????5336????????????????????3
評論
共有 條評論