读取csv数据并保存成图像

40 篇文章 1 订阅

int main(int argc, char* argv[])
{
	ifstream file("******.csv");
	string value;
	int i = 0;
	int j = 0;
	while (file.good())
	{
		getline(file, value, '\n');
		//cout << string(value, 0, value.length()) << endl;
		if (i > 0)
		{
			value.erase(0, 2);
			value.erase(value.length() - 9);
			//cout << string(value, 0, value.length()) << endl;
			char split = ' ';			
			std::vector<int> matrix(2304);
			int count1 = 0;
			for (int numPixel = 0; numPixel < 2304; numPixel++)
			{			
				char p[8] = { 0 };
				int f;
				for (int index = 0; index < value.length(); index++)
				{	
					f = value.find_first_of(split);
					if (index < f)
					{
						p[index] = value[index];
					}
					else
					{
						break;
					}
				}
			
				if (count1 == 2303)
				{
					for (int index = 0; index < value.length(); index++)
					{
					     p[index] = value[index];
					}
				}
				value.erase(0, f + 1);
				int pushData = atoi(p);  //这儿做的有些脑残
				//cout << "this is " << pushData << endl;
				matrix[count1] = pushData;
				count1++;
				//cout << "this is the " << numPixel << " th number\n";
			}

			int count = 0;
			Mat mat(48, 48, CV_8UC1, Scalar(100));
			for (int matGX = 0; matGX < 48; matGX++)
			{
				for (int matGY = 0; matGY < 48; matGY++)
				{				
						mat.at<char>(matGX, matGY) = matrix[count];
						//cout << mat.at<char>(matGX, matGY) << "fuzhi \n";
						count++;
						//cout << "count" << count << endl;
				}
			}

			namedWindow("Lena", CV_WINDOW_AUTOSIZE);
			imshow("Lena", mat);
			waitKey(33);
			char nameJpg[8];
			_itoa(j, nameJpg, 10);
			printf("nameJpg = %s\n", nameJpg);
			string nameJpgS = nameJpg;
			string path = "D:\\Facial\\";
			string imgPath = path + nameJpgS + ".jpg";
			imwrite(imgPath, mat);

			j++;
			//cout << matrix.size() << endl;	
			matrix.clear();
		}
		i++;
		cout << i << endl;
		if (i==3588)
		{
			break;
		}
	}
	return 0;
}

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值