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


C++ ImageLoader::getTrainingData方法代码示例

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


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

示例1: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	//std::string path("D:/GitHub/Image-Understanding-Classification/Image-Understanding02/101_ObjectCategories");
	std::string path("../101_ObjectCategories");
	ImageLoader LoadImages = ImageLoader(path);
	FeatureExtractor GetFeatures;
	DecisionMaker GetClassification;

	std::vector<cv::Mat> trainingImages;
	std::vector<int> trainingLabels;

	std::vector<cv::Mat> testImages;
	std::vector<int> testLabels;

	std::vector<std::vector< cv::Mat >> FeatureVectorsTraining;
	cv::Mat ReshapedFeatureVectorsTraining;
	cv::Mat ReducedFeatureVectorsTraining;
	std::vector<std::vector< cv::Mat >> FeatureVectorsTest;
	cv::Mat ReshapedFeatureVectorsTest;
	cv::Mat ReducedFeatureVectorsTest;

	std::vector<int> ResultsTest;
	std::vector<int> ResultsTraining;
	
	std::vector<std::string> classNames;
	int NumberOfSamples;
	int NumberOfClasses;

	std::vector<std::string> folders;
	folders.push_back("accordion");
	//folders.push_back("airplanes");
	folders.push_back("anchor");
	folders.push_back("ant");
	folders.push_back("barrel");
	folders.push_back("bass");
	folders.push_back("beaver");
	folders.push_back("binocular");
	folders.push_back("bonsai");
	

	for (int i = 0; i < 10; ++i)
	{
		//LoadImages.LoadImagesFromSubfolders(folders);
		LoadImages.LoadImages();
		LoadImages.getTrainingData(trainingImages, trainingLabels);
		LoadImages.getTestData(testImages, testLabels);

		FeatureVectorsTraining.clear();
		FeatureVectorsTraining.resize(trainingImages.size());

		GetFeatures.computeHOGFeatures(trainingImages, FeatureVectorsTraining);
		//GetFeatures.computeColorFeatures(trainingImages, FeatureVectorsTraining);

		GetClassification.ReshapeFeatures(FeatureVectorsTraining, ReshapedFeatureVectorsTraining);

		//GetClassification.constructPCA(ReshapedFeatureVectorsTraining);
		//GetClassification.reduceFeaturesPCA(ReshapedFeatureVectorsTraining, ReducedFeatureVectorsTraining);

		//GetClassification.TrainRandomTrees(ReshapedFeatureVectorsTraining, trainingLabels);
		GetClassification.TrainSVM(ReshapedFeatureVectorsTraining, trainingLabels);
		std::cout << "Training done." << std::endl;

		//GetClassification.PredictRandomTrees(ReshapedFeatureVectorsTraining, ResultsTraining);
		GetClassification.PredictSVM(ReshapedFeatureVectorsTraining, ResultsTraining);

		FeatureVectorsTest.clear();
		FeatureVectorsTest.resize(testImages.size());

		GetFeatures.computeHOGFeatures(testImages, FeatureVectorsTest);
		//GetFeatures.computeColorFeatures(testImages, FeatureVectorsTest);

		GetClassification.ReshapeFeatures(FeatureVectorsTest, ReshapedFeatureVectorsTest);
		//GetClassification.reduceFeaturesPCA(ReshapedFeatureVectorsTest, ReducedFeatureVectorsTest);

		//GetClassification.PredictRandomTrees(ReshapedFeatureVectorsTest, ResultsTest);
		GetClassification.PredictSVM(ReshapedFeatureVectorsTest, ResultsTest);
		
		LoadImages.getClassNames(classNames);
		NumberOfClasses = classNames.size();
		LoadImages.getSampleSize(NumberOfSamples);

		EvaluationUnit GetTrainingEvaluation(trainingLabels, NumberOfClasses, NumberOfSamples);
		double TrainingPercent = GetTrainingEvaluation.EvaluateResultSimple(ResultsTraining);
		std::cout << " Training Data Simple Percentage: " + std::to_string(TrainingPercent) << std::endl;

		std::vector<double> classPercentageTraining;
		std::vector<std::vector<int>> TrainingStatistics;
		GetTrainingEvaluation.EvaluateResultComplex(ResultsTraining, classPercentageTraining, TrainingStatistics);
		//for (int i = 0; i < classPercentageTraining.size(); i++)
		//{
		//	std::cout << "   " + classNames[i] + ": " + std::to_string(classPercentageTraining[i]) << std::endl;
		//}

		EvaluationUnit GetTestEvaluation(testLabels, NumberOfClasses, NumberOfSamples);
		double TestPercent = GetTestEvaluation.EvaluateResultSimple(ResultsTest);
		std::cout << " Test Data Simple Percentage: " + std::to_string(TestPercent) << std::endl;

		/*std::vector<double> classPercentageTest;
		std::vector<std::vector<int>> TestStatistics;
		GetTestEvaluation.EvaluateResultComplex(ResultsTest, classPercentageTest, TestStatistics);
//.........这里部分代码省略.........
开发者ID:Aerl,项目名称:Image-Understanding-Classification,代码行数:101,代码来源:Classification01.cpp


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