Exemplo n.º 1
0
	/* 
	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));
		}

	}
Exemplo n.º 2
0
	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;
	}