本文整理汇总了C++中Pattern::getSimilarity方法的典型用法代码示例。如果您正苦于以下问题:C++ Pattern::getSimilarity方法的具体用法?C++ Pattern::getSimilarity怎么用?C++ Pattern::getSimilarity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pattern
的用法示例。
在下文中一共展示了Pattern::getSimilarity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFindResults
vector<FindResult>
Vision::find(ScreenImage simg, Pattern ptn) {
// SYSTEMTIME begin, end;
// GetSystemTime(&begin);
Mat screenImage = simg.getMat();
vector<FindResult> results;
if (ptn.bAll()){
results = getFindResults(screenImage, ptn, true, ptn.getSimilarity());
if (ptn.getOrdering() == TOPDOWN){
sort(results.begin(), results.end(), sort_by_y_asc);
}else if (ptn.getOrdering() == BOTTOMUP){
sort(results.begin(), results.end(), sort_by_y_dsc);
}else if (ptn.getOrdering() == LEFTRIGHT){
sort(results.begin(), results.end(), sort_by_x_asc);
}else if (ptn.getOrdering() == RIGHTLEFT){
sort(results.begin(), results.end(), sort_by_x_dsc);
}
}else{
if (ptn.where() != ANYWHERE){
results = getFindResults(screenImage, ptn, true, ptn.getSimilarity());
cout << "found " << results.size() << " matches." << endl;
if (!results.empty()){
// Filter Results
FindResult r = results[0];
for (int i=1; i<results.size(); ++i){
FindResult& ri = results[i];
if ((ptn.where() == TOPMOST && ri.y < r.y) ||
(ptn.where() == BOTTOMMOST && ri.y > r.y) ||
(ptn.where() == LEFTMOST && ri.x < r.x) ||
(ptn.where() == RIGHTMOST && ri.x > r.x))
r = ri;
}
results.clear();
results.push_back(r);
}
}
else {
results = getFindResults(screenImage, ptn, false, ptn.getSimilarity());
}
}
vector<FindResult> final_results;
int n = min((int)results.size(), (int)ptn.getLimit());
for (int i=0; i< n; ++i){
final_results.push_back(results[i]);
}
// GetSystemTime(&end);
// WORD elapsed_ms = (end.wSecond - begin.wSecond)*1000+(end.wMilliseconds - begin.wMilliseconds);
// cout << elapsed_ms << " ms." << endl;
return final_results;
}
示例2: match
vector<Match>
Region::doFind(Pattern target) {
dout << "[Region::doFind] Searching in (" << xo+x << "," << yo+y << ")-(" << xo+x+w << "," << yo+y+h << ")" << endl;
ScreenImage simg = capture();
FindInput* fi;
if (target.isText())
fi = new FindInput(simg.getMat(), TARGET_TYPE_TEXT, target.getText());
else
fi = new FindInput(simg.getMat(), TARGET_TYPE_IMAGE, target.getImageURL());
FindInput& input = *fi;
input.setFindAll(target.bAll());
input.setLimit(target.getLimit());
input.setSimilarity(target.getSimilarity());
if (!target.bAll() && target.where() != ANYWHERE){
input.setFindAll(true);
}
vector<FindResult> results = Vision::find(input);
delete fi;
if (target.getOrdering() == TOPDOWN){
sort(results.begin(), results.end(), sort_by_y_asc);
}else if (target.getOrdering() == BOTTOMUP){
sort(results.begin(), results.end(), sort_by_y_dsc);
}else if (target.getOrdering() == LEFTRIGHT){
sort(results.begin(), results.end(), sort_by_x_asc);
}else if (target.getOrdering() == RIGHTLEFT){
sort(results.begin(), results.end(), sort_by_x_dsc);
}
if (!target.bAll() && target.where() != ANYWHERE){
if (!results.empty()){
// Filter Results
FindResult r = results[0];
for (int i=1; i<results.size(); ++i){
FindResult& ri = results[i];
if ((target.where() == TOPMOST && ri.y < r.y) ||
(target.where() == BOTTOMMOST && ri.y > r.y) ||
(target.where() == LEFTMOST && ri.x < r.x) ||
(target.where() == RIGHTMOST && ri.x > r.x))
r = ri;
}
results.clear();
results.push_back(r);
}
}
vector<Match> matches;
int n = min((int)results.size(), (int)target.getLimit());
for (int i=0; i< n; ++i){
FindResult& r = results[i];
Match match(inner(r.x,r.y,r.w,r.h),r.score);
matches.push_back(match);
}
if (!matches.empty()){
SikuliUI::sikuliUI->handleMatchFound(*this, target, matches);
setLastMatch(matches[0]);
setLastMatches(matches);
}
// TODO: setTargetOffset
//match.setTargetOffset(ptn.getTargetOffset());
return matches;
}