【opencv---Mat&&数组】

在opencv自带的机器学习中经常用到对数据的预处理,本片博客纯属为了练习熟悉转化过程;

1.将txt文本数据内的带空格间隔的二维数字数组转化到Mat的训练中

#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<fstream>
using namespace std;


void main() {
	float a[3][3]{ {0} };
	string str;
	vector<float>s;
	ifstream fin("123.txt");
	int k = 0;
	while(getline(fin,str))
	{
		int x = 0;
		float i;
		stringstream ss(str);
		while (ss>>i)
		{
			a[k][x]=i;
			cout << i << " ";
			x++;
		}
		k++;
		cout << endl;
	}


	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < 3;j++) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	getchar();

}

猜你喜欢

转载自blog.csdn.net/qq_35054151/article/details/83316742