Ejemplo n.º 1
0
void AnnHelper::LoadResponsesForTraining_new(std::vector<std::string> _files, cv::Mat& _response)
{
	FileUtils futils;
	MathUtils mathUtils;
	MatUtils matutils;
	Mat responses;

	for (string filename : _files)
	{
		//获取图片信息文件路径
		string fileinfo = filename.substr(0, filename.find_last_of('\\'));//目录
		fileinfo += "\\training_data_new.txt";
		//读取结果矩阵
		vector<string> matNames;
		vector<string> matStrs;
		futils.ReadMatFile(matStrs, matNames, fileinfo);
		assert(matStrs.size() > 0);

		int bcodeIndex = 0;//数值矩阵
		int bitIndex = 0;//位数矩阵

		for (int i = 0; i < matNames.size(); i++)
		{
			if (matNames[i] == "code")
			{
				bcodeIndex = i;
			}
			if (matNames[i] == "bit")
			{
				bitIndex = i;
			}
		}

		string bcode = "";
		Mat decCodeMat = matutils.ToMat(matStrs[bcodeIndex]);
		Mat bitMat = matutils.ToMat(matStrs[bitIndex]);
		assert(decCodeMat.cols == bitMat.cols);
		int bitNum=0;
		int bit = 0;
		for (int i = 0; i < decCodeMat.cols; i++)
		{
			bitNum = decCodeMat.at<float>(0, i);
			bit = bitMat.at<float>(0, i);
			bcode += mathUtils.ConvertToBinary(bitNum, bit);
		}
		stringstream ss;
		Mat resMat(1, bcode.length(), CV_32F);
		for (int i = 0; i < resMat.cols; i++)
		{
			ss << bcode[i];
			float ib = 0.;
			ss >> ib;
			resMat.at<float>(0, i) = ib;
			ss.clear();
		}
		matutils.AddMatRow(responses, resMat, responses);
	}
	_response = responses;
}
Ejemplo n.º 2
0
void AnnHelper::LoadResponsesForTraining(std::vector<string> _files, cv::Mat& _response)
{
	FileUtils futils;
	MatUtils matutils;
	Mat responses;

	for (string filename : _files)
	{
		//获取图片信息文件路径
		string fileinfo = filename.substr(0, filename.find_last_of('\\'));//目录
		fileinfo += "\\training_data.txt";
		//读取结果矩阵
		vector<string> matNames;
		vector<string> matStrs;
		futils.ReadMatFile(matStrs, matNames, fileinfo);
		assert(matStrs.size()>0);
		
		Mat response = matutils.ToMat(matStrs[0]);
		matutils.AddMatRow(responses, response, responses);

	}
	_response = responses;
}