当前位置: 首页>>代码示例>>C++>>正文


C++ Ptr::addTemplate方法代码示例

本文整理汇总了C++中cv::Ptr::addTemplate方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::addTemplate方法的具体用法?C++ Ptr::addTemplate怎么用?C++ Ptr::addTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv::Ptr的用法示例。


在下文中一共展示了Ptr::addTemplate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadTemplateImages

	// load template images
	bool OfflineTemplatesLoader::loadTemplateImages(
		const ObjectsConfig &objectsConfig,
		cv::Ptr<Detector> &detector, 
		std::map<int, std::vector<cv::Mat> > &images, 
		std::map<int, std::vector<cv::Rect> > &boundingBoxes)
	{
		const int objectNum = objectsConfig.object_config_size();
		CHECK(objectNum>0) << "No template images.";

#pragma omp parallel for
		for(int i=0; i<objectNum; ++i)
		{
			const ObjectConfig &objectConfig = objectsConfig.object_config(i);
			const int classId = objectConfig.id();
			const std::string &className = objectConfig.name();
			const std::string &imagesDir = objectConfig.img_dir();

			//read images
			std::vector<std::string> fileName;
			CHECK(GetFileNames(imagesDir, fileName))
				<< "Cannot get files name in specific directory";

			std::vector<cv::Mat> imgs;
			std::vector<cv::Rect> bbs;
			for(int k=0; k<(int)fileName.size(); ++k)
			{
				std::string file = imagesDir + "/" + fileName[k];
				cv::Mat img=cv::imread( file );					

				//extract a new template for current image
				cv::Rect tmplBoundingBox;
				int template_id = detector->addTemplate(img, classId, &tmplBoundingBox);

				//save all images, it is not a good idea when template images are large
				//but to do matches refinement, there's not good way
				imgs.push_back(img);
				bbs.push_back(tmplBoundingBox);
			}
#pragma omp critical
			{
				images.insert(std::pair<int, std::vector<cv::Mat> >(classId, imgs));
				boundingBoxes.insert(std::pair<int, std::vector<cv::Rect> >(classId, bbs));
			}
		}

		return true;
	}
开发者ID:imbinwang,项目名称:LINE2D,代码行数:48,代码来源:OfflineTemplatesLoader.cpp

示例2: loadTemplateImagesAndPoses

	// load template images, poses of images, obj model file
	bool OfflineTemplatesLoader::loadTemplateImagesAndPoses(
		const ObjectsConfig &objectsConfig,
		cv::Ptr<Detector> &detector, 
		std::map<int, std::vector<cv::Mat> > &images, 
		std::map<int, std::vector<cv::Rect> > &boundingBoxes,
		std::map<int, std::vector<cv::Matx61f> > &poses, 
		std::map<int, GLMmodel*> &objModels)
	{
		const int objectNum = objectsConfig.object_config_size();
		CHECK(objectNum>0) << "No template images.";

		#pragma omp parallel for
		for(int i=0; i<objectNum; ++i)
		{
			const ObjectsConfig_ObjectConfig &objectConfig = objectsConfig.object_config(i);
			const int classId = objectConfig.id();
			const std::string &className = objectConfig.name();
			//const std::string &imagesDir = objectConfig.img_dir();
			//const std::string &posePath = objectConfig.pose_path();
			const std::string &modelPath = objectConfig.model_path();

			//CHECK(!posePath.empty())<< "Please configure the file path of pose file.";
			CHECK(!modelPath.empty())<< "Please configure the file path of obj file.";

#if 0
			// read images
			std::vector<std::string> fileName;
			CHECK(GetFileNames(imagesDir, fileName))
				<< "Cannot get files name in specific directory";

			std::vector<cv::Mat> imgs;
			std::vector<cv::Rect> bbs;
			for(int k=0; k<(int)fileName.size(); ++k)
			{
				std::string file = imagesDir + "/" + fileName[k];
				cv::Mat img=cv::imread( file );					

				//extract a new template for current image
				cv::Rect tmplBoundingBox;
				int template_id = detector->addTemplate(img, classId, &tmplBoundingBox);

				//save all images, it is not a good idea when template images are large
				//but to do matches refinement, there's not good way
				imgs.push_back(img);
				bbs.push_back(tmplBoundingBox);
			}

			// read pose file
			std::ifstream poseInFile(posePath.c_str());
			CHECK(poseInFile.is_open()) << "Cannot open pose file.";

			std::vector<cv::Matx61f> posesParam;
			for(int j=0; j<(int)fileName.size(); ++j)
			{
				cv::Matx61f poseTmp;

				// rotation vector and translation vector
				poseInFile >> poseTmp.val[0] >> poseTmp.val[1] >> poseTmp.val[2]
				>> poseTmp.val[3] >> poseTmp.val[4] >> poseTmp.val[5];

				posesParam.push_back(poseTmp);
			}
#endif

			// read template images and corresponding poses
			std::vector<cv::Mat> imgs;
			std::vector<cv::Rect> bbs;
			std::vector<cv::Matx61f> posesParam;
			for(int j=0; j<objectConfig.imagedir_posefile_pair_size(); ++j)
			{
				const ObjectsConfig_ObjectConfig_ImageDirAndPoseFilePair& imagedir_posefile = objectConfig.imagedir_posefile_pair(j);
				const std::string &imagesDir = imagedir_posefile.img_dir();
				const std::string &posePath = imagedir_posefile.pose_path();

				// read images
				std::vector<std::string> fileName;
				CV_Assert(GetFileNames(imagesDir, fileName));

				for(int k=0; k<(int)fileName.size(); ++k)
				{
					std::string file = imagesDir + "/" + fileName[k];
					cv::Mat img=cv::imread( file );	

					//extract a new template for current image
					cv::Rect tmplBoundingBox;
					int template_id = detector->addTemplate(img, classId, &tmplBoundingBox);

					//save all images, it is not a good idea when template images are large
					//but to do matches refinement, there's not good way
					imgs.push_back(img);
					bbs.push_back(tmplBoundingBox);
				}

				// read poses
				std::ifstream poseInFile(posePath.c_str());
				CV_Assert(poseInFile.is_open());

				for(int j=0; j<(int)fileName.size(); ++j)
				{
//.........这里部分代码省略.........
开发者ID:imbinwang,项目名称:LINE2D,代码行数:101,代码来源:OfflineTemplatesLoader.cpp


注:本文中的cv::Ptr::addTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。