本文整理汇总了C++中cv::Ptr::getTemplates方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::getTemplates方法的具体用法?C++ Ptr::getTemplates怎么用?C++ Ptr::getTemplates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Ptr
的用法示例。
在下文中一共展示了Ptr::getTemplates方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*
find the corresponding bounding boxes for each grouped matches
*/
void CvtGroupedMatches2Rects(const std::map<int,std::vector<Match*> > &classMatchMap,
const cv::Ptr<Detector> &detector,
std::map<int, std::vector<cv::Rect> > &classRectMap)
{
classRectMap.clear();
int classMatchMapSize = static_cast<int>(classMatchMap.size());
for(std::map<int, std::vector<Match*> >::const_iterator mit = classMatchMap.begin(),
mend = classMatchMap.end(); mit != mend; ++mit)
{
size_t matchNum = mit->second.size();
std::vector<cv::Rect> cur_rects(matchNum);
for(size_t i = 0; i<matchNum; ++i)
{
std::vector<Template> templatePyramid
= detector->getTemplates(mit->second[i]->class_id, mit->second[i]->template_id);
int templateWidth = templatePyramid[0].width;
int templateHeight = templatePyramid[0].height;
cur_rects[i] = cv::Rect(mit->second[i]->x, mit->second[i]->y, templateWidth, templateHeight);
}
classRectMap.insert(std::make_pair(mit->first, cur_rects));
}
}
示例2: DrawMatches
bool DrawMatches(const std::vector<Match> &matches,
const cv::Ptr<Detector> &detector,
const ObjectsConfig &objectsConfig,
int draw_match_num,
cv::Mat &displayImg)
{
CHECK(draw_match_num>0) << "Invalid match number for drawing on original image.";
draw_match_num = draw_match_num>(int)matches.size() ? (int)matches.size():draw_match_num;
//LOG(INFO)<<"Draw "<<draw_match_num<<" matching results.";
for(int i=0; i<draw_match_num; ++i)
{
const Match &m = matches[i];
int x = m.x;
int y = m.y;
float similarity = m.similarity;
int class_id = m.class_id;
int template_id = m.template_id;
// get the predefined color from configuration file
const const ObjectsConfig_ObjectConfig& objectConfig = objectConfigById(objectsConfig, class_id);
const ObjectsConfig_ObjectConfig_RGB &bb_color = objectConfig.bounding_box_color();
std::vector<Template> templatePyramid = detector->getTemplates(class_id, template_id);
int templateWidth = 0;
int templateHeight = 0;
if(templatePyramid.size()>0)
{
std::vector<Feature> &fs = templatePyramid[0].features;
templateWidth = templatePyramid[0].width;
templateHeight = templatePyramid[0].height;
// draw matching points in the largest scale pyramid
DrawFeatures(fs, cv::Point(x,y), CV_RGB(bb_color.r(),bb_color.g(),bb_color.b()), displayImg);
}else
return false;
// draw the best match with bold bounding box
if( i==0)
{
cv::rectangle(displayImg, cv::Rect(x, y, templateWidth, templateHeight),
CV_RGB(0,0,0), 3);
cv::rectangle(displayImg, cv::Rect(x, y, templateWidth, templateHeight),
CV_RGB(bb_color.r(),bb_color.g(),bb_color.b()), 2);
}else
{
cv::rectangle(displayImg, cv::Rect(x, y, templateWidth, templateHeight),
CV_RGB(0,0,0), 2);
cv::rectangle(displayImg, cv::Rect(x, y, templateWidth, templateHeight),
CV_RGB(bb_color.r(),bb_color.g(),bb_color.b()), 1);
}
}
return true;
}