本文整理汇总了C++中Matches类的典型用法代码示例。如果您正苦于以下问题:C++ Matches类的具体用法?C++ Matches怎么用?C++ Matches使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Matches类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findClosestMatch
/*
* Find the closest match in db, return as element of matches
*/
void SemanticDescriptor::findClosestMatch(Database & db, Matches & matches)
{
SemanticDescriptor bestMatch = (*(db.dDB.begin())).first;
//matches.insert((*(db.dDB.begin())).second);
SemanticDescriptor compareID;
int matchStrength;
map<SemanticDescriptor, string>::iterator iter;
for (iter = db.dDB.begin(); iter != db.dDB.end(); ++iter) {
compareID = iter->first;
matchStrength = closerMatch(compareID, bestMatch, db);
/* If compareID is a better match, reset matches */
if (matchStrength > 0)
if (compareID.coverage(*this, db) >= .5) {
matches.clear();
matches.insert(iter->second);
bestMatch = compareID;
}
/* If compareID is an equal match, then add it to the set of matches */
if (matchStrength == 0)
if (compareID.coverage(*this, db) >= .5)
matches.insert(iter->second);
}
}
示例2: findHomography
bool ImageTransformation::findHomography( const Keypoints& source, const Keypoints& result, const Matches& input, Matches& inliers, cv::Mat& homography)
{
if (input.size() < 8)
return false;
std::vector<cv::Point2f> srcPoints, dstPoints;
const int pointsCount = input.size();
for (int i=0; i<pointsCount; i++)
{
srcPoints.push_back(source[input[i].trainIdx].pt);
dstPoints.push_back(result[input[i].queryIdx].pt);
}
std::vector<unsigned char> status;
cv::findHomography(srcPoints, dstPoints, CV_FM_RANSAC, 3, status);
inliers.clear();
for (int i=0; i<pointsCount; i++)
{
if (status[i])
{
inliers.push_back(input[i]);
}
}
return true;
}
示例3: getHash
void TestRunner::getHash(Testable* testable, unsigned char result[]){
Matches matches = testable->collect();
std::sort(matches.begin(), matches.end(), Match::sortFun);
Matches::iterator it;
SHA1_Init(&shaCtx);
for(it=matches.begin(); it!=matches.end(); ++it){
std::string matchStr = (*it).toString();
SHA1_Update(&shaCtx, matchStr.c_str(), matchStr.size());
}
SHA1_Final(result, &shaCtx);
}
示例4: findExactMatches
/*
* Find exact matches for the semantic descriptor in the database
*/
bool SemanticDescriptor::findExactMatches(Database & db, Matches & matches)
{
SemanticDescriptor compareID;
map<SemanticDescriptor, string>::iterator iter;
for (iter = db.dDB.begin(); iter != db.dDB.end(); ++iter) {
compareID = iter->first;
if (equals(compareID, db)) {
matches.insert(iter->second);
}
}
return matches.size();
}
示例5: MatchPersistenceFromJSON
MatchPersistence MatchPersistenceFromJSON(const Value &value) {
auto executableName = value["executableName"].GetString();
auto matcherName = value["matcherName"].GetString();
auto executableArchitecture = value["executableArchitecture"].GetString();
auto realTime = value["realTime"].GetDouble();
auto cpuTime = value["cpuTime"].GetDouble();
Matches matches;
auto &matchesValue = value["matches"];
for (rapidjson::SizeType i = 0; i < matchesValue.Size(); ++i) {
auto match = MatchFromJSON(matchesValue[i]);
if (match) {
matches.push_back(match);
}
}
return MatchPersistence(executableName,matcherName,executableArchitecture,realTime,cpuTime,matches);
}
示例6: computeMatchesDistanceStatistics
bool computeMatchesDistanceStatistics(const Matches& matches, float& meanDistance, float& stdDev)
{
if (matches.empty())
return false;
std::vector<float> distances(matches.size());
for (size_t i=0; i<matches.size(); i++)
distances[i] = matches[i].distance;
cv::Scalar mean, dev;
cv::meanStdDev(distances, mean, dev);
meanDistance = static_cast<float>(mean.val[0]);
stdDev = static_cast<float>(dev.val[0]);
return false;
}
示例7: ratioTest
void ratioTest(const std::vector<Matches>& knMatches, float maxRatio, Matches& goodMatches)
{
goodMatches.clear();
for (size_t i=0; i< knMatches.size(); i++)
{
const cv::DMatch& best = knMatches[i][0];
const cv::DMatch& good = knMatches[i][1];
assert(best.distance <= good.distance);
float ratio = (best.distance / good.distance);
if (ratio <= maxRatio)
{
goodMatches.push_back(best);
}
}
}
示例8: generateSummary
static void generateSummary( Summary &summary, char *htmlInput, const char *queryStr, const char *urlStr ) {
Xml xml;
ASSERT_TRUE(xml.set(htmlInput, strlen(htmlInput), 0, CT_HTML));
Words words;
ASSERT_TRUE(words.set(&xml, true));
Bits bits;
ASSERT_TRUE(bits.set(&words));
Url url;
url.set(urlStr);
Sections sections;
ASSERT_TRUE(sections.set(&words, &bits, &url, "", CT_HTML));
Query query;
ASSERT_TRUE(query.set2(queryStr, langEnglish, true));
LinkInfo linkInfo;
memset ( &linkInfo , 0 , sizeof(LinkInfo) );
linkInfo.m_lisize = sizeof(LinkInfo);
Title title;
ASSERT_TRUE(title.setTitle(&xml, &words, 80, &query, &linkInfo, &url, NULL, 0, CT_HTML, langEnglish));
Pos pos;
ASSERT_TRUE(pos.set(&words));
Bits bitsForSummary;
ASSERT_TRUE(bitsForSummary.setForSummary(&words));
Phrases phrases;
ASSERT_TRUE(phrases.set(&words, &bits));
Matches matches;
matches.setQuery(&query);
ASSERT_TRUE(matches.set(&words, &phrases, §ions, &bitsForSummary, &pos, &xml, &title, &url, &linkInfo));
summary.setSummary(&xml, &words, §ions, &pos, &query, 180, 3, 3, 180, &url, &matches, title.getTitle(), title.getTitleLen());
}
示例9: Localize
bool HybridTracker::Localize(const Marker& target, const Frame& scene, Matches& out) {
vector<cv::DMatch> matches;
methods.Match(target.descriptor, scene.descriptor, matches);
out.clear();
for(auto& it : matches) {
out._targetPts.push_back(target.keys[it.queryIdx]);
out._scenePts.push_back(scene.keys[it.trainIdx]);
out._error.push_back(it.distance);
}
return matches.size() > 20;
}
示例10: initRouteMatrix
/*
* Function: initRouteMatrix()
* Comments: Initializes global route matrix for this Solution
*/
void Solution::initRouteMatrix()
{
if(matrixInitType == FLUSH || myInternalMatrix.use_count() == 0)
{
Matches matches;
Riders riders;
for(MatchesMap::iterator it = myMatches.begin();
it != myMatches.end();
it++)
{
matches.push_back(it->second);
for(Riders::iterator rider = it->second.confirmedRiders.begin();
rider != it->second.confirmedRiders.end();
rider++){
riders.push_back(*rider);
}
}
for(RidersMap::iterator it = myRiders.begin();
it != myRiders.end();
it++)
{
riders.push_back(it->second);
}
Drivers emptyDrivers;
if(useLocalMatrix){
myInternalMatrix.reset(new RouteMatrixLocal(emptyDrivers,riders,matches));
}else{
myInternalMatrix.reset(new RouteMatrix<>(emptyDrivers,riders,matches));
}
}
else
{
//std::cout << "Using old route Matrix" <<std::endl;
}
routeMatrix = myInternalMatrix;
}
示例11: if
bool performEstimation
(
const FeatureAlgorithm& alg,
const ImageTransformation& transformation,
const cv::Mat& sourceImage,
std::vector<FrameMatchingStatistics>& stat
)
{
Keypoints sourceKp;
Descriptors sourceDesc;
cv::Mat gray;
if (sourceImage.channels() == 3)
cv::cvtColor(sourceImage, gray, CV_BGR2GRAY);
else if (sourceImage.channels() == 4)
cv::cvtColor(sourceImage, gray, CV_BGRA2GRAY);
else if(sourceImage.channels() == 1)
gray = sourceImage;
if (!alg.extractFeatures(gray, sourceKp, sourceDesc))
return false;
std::vector<float> x = transformation.getX();
stat.resize(x.size());
const int count = x.size();
cv::Mat transformedImage;
Keypoints resKpReal;
Descriptors resDesc;
Matches matches;
// To convert ticks to milliseconds
const double toMsMul = 1000. / cv::getTickFrequency();
#pragma omp parallel for private(transformedImage, resKpReal, resDesc, matches)
for (int i = 0; i < count; i++)
{
float arg = x[i];
FrameMatchingStatistics& s = stat[i];
transformation.transform(arg, gray, transformedImage);
int64 start = cv::getTickCount();
alg.extractFeatures(transformedImage, resKpReal, resDesc);
// Initialize required fields
s.isValid = resKpReal.size() > 0;
s.argumentValue = arg;
if (!s.isValid)
continue;
if (alg.knMatchSupported)
{
std::vector<Matches> knMatches;
alg.matchFeatures(sourceDesc, resDesc, 2, knMatches);
ratioTest(knMatches, 0.75, matches);
// Compute percent of false matches that were rejected by ratio test
s.ratioTestFalseLevel = (float)(knMatches.size() - matches.size()) / (float) knMatches.size();
}
else
{
alg.matchFeatures(sourceDesc, resDesc, matches);
}
int64 end = cv::getTickCount();
Matches correctMatches;
cv::Mat homography;
bool homographyFound = ImageTransformation::findHomography(sourceKp, resKpReal, matches, correctMatches, homography);
// Some simple stat:
s.isValid = homographyFound;
s.totalKeypoints = resKpReal.size();
s.consumedTimeMs = (end - start) * toMsMul;
// Compute overall percent of matched keypoints
s.percentOfMatches = (float) matches.size() / (float)(std::min(sourceKp.size(), resKpReal.size()));
s.correctMatchesPercent = (float) correctMatches.size() / (float)matches.size();
// Compute matching statistics
computeMatchesDistanceStatistics(correctMatches, s.meanDistance, s.stdDevDistance);
}
return true;
}
示例12: setCompletionItems
void LookupWidget::setCompletionItems(const Matches& matches) {
ui_->word_input->completionObject()->setItems(matches.words());
}
示例13: assert
typename PointMatcher<T>::ErrorMinimizer::ErrorElements& PointMatcher<T>::ErrorMinimizer::getMatchedPoints(
const DataPoints& requestedPts,
const DataPoints& sourcePts,
const Matches& matches,
const OutlierWeights& outlierWeights)
{
typedef typename Matches::Ids Ids;
typedef typename Matches::Dists Dists;
assert(matches.ids.rows() > 0);
assert(matches.ids.cols() > 0);
assert(matches.ids.cols() == requestedPts.features.cols()); //nbpts
assert(outlierWeights.rows() == matches.ids.rows()); // knn
const int knn = outlierWeights.rows();
const int dimFeat = requestedPts.features.rows();
const int dimReqDesc = requestedPts.descriptors.rows();
// Count points with no weights
const int pointsCount = (outlierWeights.array() != 0.0).count();
if (pointsCount == 0)
throw ConvergenceError("ErrorMnimizer: no point to minimize");
Matrix keptFeat(dimFeat, pointsCount);
Matrix keptDesc;
if(dimReqDesc > 0)
keptDesc = Matrix(dimReqDesc, pointsCount);
Matches keptMatches (Dists(1,pointsCount), Ids(1, pointsCount));
OutlierWeights keptWeights(1, pointsCount);
int j = 0;
int rejectedMatchCount = 0;
int rejectedPointCount = 0;
bool matchExist = false;
this->weightedPointUsedRatio = 0;
for (int i = 0; i < requestedPts.features.cols(); ++i) //nb pts
{
matchExist = false;
for(int k = 0; k < knn; k++) // knn
{
if (outlierWeights(k,i) != 0.0)
{
if(dimReqDesc > 0)
keptDesc.col(j) = requestedPts.descriptors.col(i);
keptFeat.col(j) = requestedPts.features.col(i);
keptMatches.ids(0, j) = matches.ids(k, i);
keptMatches.dists(0, j) = matches.dists(k, i);
keptWeights(0,j) = outlierWeights(k,i);
++j;
this->weightedPointUsedRatio += outlierWeights(k,i);
matchExist = true;
}
else
{
rejectedMatchCount++;
}
}
if(matchExist == false)
{
rejectedPointCount++;
}
}
assert(j == pointsCount);
this->pointUsedRatio = double(j)/double(knn*requestedPts.features.cols());
this->weightedPointUsedRatio /= double(knn*requestedPts.features.cols());
assert(dimFeat == sourcePts.features.rows());
const int dimSourDesc = sourcePts.descriptors.rows();
Matrix associatedFeat(dimFeat, pointsCount);
Matrix associatedDesc;
if(dimSourDesc > 0)
associatedDesc = Matrix(dimSourDesc, pointsCount);
// Fetch matched points
for (int i = 0; i < pointsCount; ++i)
{
const int refIndex(keptMatches.ids(i));
associatedFeat.col(i) = sourcePts.features.block(0, refIndex, dimFeat, 1);
if(dimSourDesc > 0)
associatedDesc.col(i) = sourcePts.descriptors.block(0, refIndex, dimSourDesc, 1);
}
this->lastErrorElements.reading = DataPoints(
keptFeat,
requestedPts.featureLabels,
keptDesc,
requestedPts.descriptorLabels
);
this->lastErrorElements.reference = DataPoints(
associatedFeat,
sourcePts.featureLabels,
//.........这里部分代码省略.........
示例14: refPtCount
void InspectorsImpl<T>::AbstractVTKInspector::dumpDataLinks(
const DataPoints& ref,
const DataPoints& reading,
const Matches& matches,
const OutlierWeights& featureOutlierWeights,
std::ostream& stream)
{
const Matrix& refFeatures(ref.features);
const int refPtCount(refFeatures.cols());
//const int featDim(refFeatures.rows());
const Matrix& readingFeatures(reading.features);
const int readingPtCount(readingFeatures.cols());
const int totalPtCount(refPtCount+readingPtCount);
stream << "# vtk DataFile Version 3.0\n";
stream << "comment\n";
stream << "ASCII\n";
stream << "DATASET POLYDATA\n";
stream << "POINTS " << totalPtCount << " float\n";
if(refFeatures.rows() == 4)
{
// reference pt
stream << refFeatures.topLeftCorner(3, refFeatures.cols()).transpose() << "\n";
// reading pt
stream << readingFeatures.topLeftCorner(3, readingFeatures.cols()).transpose() << "\n";
}
else
{
// reference pt
stream << refFeatures.transpose() << "\n";
// reading pt
stream << readingFeatures.transpose() << "\n";
}
const int knn = matches.ids.rows();
stream << "LINES " << readingPtCount*knn << " " << readingPtCount*knn * 3 << "\n";
//int j = 0;
for(int k = 0; k < knn; k++) // knn
{
for (int i = 0; i < readingPtCount; ++i)
{
stream << "2 " << refPtCount + i << " " << matches.ids(k, i) << "\n";
}
}
stream << "CELL_DATA " << readingPtCount*knn << "\n";
stream << "SCALARS outlier float 1\n";
stream << "LOOKUP_TABLE default\n";
//stream << "LOOKUP_TABLE alphaOutlier\n";
for(int k = 0; k < knn; k++) // knn
{
for (int i = 0; i < readingPtCount; ++i) //nb pts
{
stream << featureOutlierWeights(k, i) << "\n";
}
}
//stream << "LOOKUP_TABLE alphaOutlier 2\n";
//stream << "1 0 0 0.5\n";
//stream << "0 1 0 1\n";
}
示例15: main
int main()
{
std::string port=":9000";
int listenQueueBacklog = 400;
if ( FCGX_Init() )
{
exit( 1 );
}
int listen_socket = FCGX_OpenSocket( port.c_str(), listenQueueBacklog );
if ( listen_socket < 0 )
{
exit( 1 );
}
FCGX_Request request;
if ( FCGX_InitRequest( &request, listen_socket, 0 ) )
{
exit( 1 );
}
std::string header = "Content-type: text/html\r\n\r\n";
NumTable db;
std::map<Number,Number> posts;
try
{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
driver = get_driver_instance();
con = driver->connect( "tcp://127.0.0.1:3306", "wiki_bot", "31415" );
con->setSchema( "orpheus" );
stmt = con->createStatement();
res = stmt->executeQuery( "SELECT hash, track_id FROM hashes_all" );
while ( res->next() )
{
Number h = res->getUInt64( "hash" );
db.push_back( h );
posts[h] = res->getUInt64( "track_id" );
}
delete res;
delete stmt;
delete con;
}
catch ( sql::SQLException &e )
{
std::cout << "# ERR: SQLException in " << __FILE__;
std::cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << std::endl;
std::cout << "# ERR: " << e.what();
std::cout << " (MySQL error code: " << e.getErrorCode();
std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
}
std::cout << "Start building." << std::endl;
HEngine_sn e( 7 );
e.build( db );
std::cout << "Building done." << std::endl;
while ( FCGX_Accept_r( &request ) == 0 )
{
std::cout << "Have request. " << std::endl;
NumTable q;
Number hash;
std::string query = FCGX_GetParam( "QUERY_STRING", request.envp );
std::stringstream ss( query );
while ( ss >> hash )
{
q.push_back( hash );
if ( ss.peek() == ',' )
{
ss.ignore();
}
}
std::string body = header;
int c = 0;
for ( auto &h: q )
{
Matches res = e.query( h );
c += res.size();
for ( auto &r: res )
{
body += std::to_string( posts[r.first] ) + ":" + std::to_string( r.first ) + ":" + std::to_string( r.second ) + "<br/>";
}
}
FCGX_PutS( body.c_str(), request.out );
FCGX_Finish_r( &request );
}
//.........这里部分代码省略.........