Opencv中将图片的像素值保存到vector容器中,并保存为文本文档

#include<iostream>
#include<vector>
#include<string>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<fstream>


using namespace std;
using namespace cv;


int main()
{
ifstream file("E://tu//menglu.txt");
ofstream outfile;
outfile.open("E://tu//liu.txt");
if (!outfile)cout << "error" << endl;
string ImgName;
string imgName;
vector <Mat>channels;//定义通道`
vector<int> vec_lie;
vector<int> awai{1, 2 ,3 ,4};
while (getline(file, ImgName))
{

// cout << "处理:" << ImgName << endl;
imgName = "E://tu//" + ImgName ;
Mat img = imread(imgName);
/*cout << "img.type()=" << img.type() << endl;
cout << "img.channel: " << img.channels() << endl;*/


for (int i = 0; i < img.rows; i++)
{
for (int j = 0; j < img.cols; j++)
{
int v = img.at<Vec3b>(i, j)[1];
vec_lie.push_back(v);
}
}
}
for (auto i = vec_lie.begin(); i < vec_lie.end(); i++)
{
cout << *i << " ";
outfile << *i << " ";
}


outfile.close();
//outfile.close();
cout << endl;
cout << vec_lie.size() << endl;


//for (auto j =awai.begin(); j < awai.end(); j++)
//{
// vec_lie.push_back(*j);
//}
//cout << "添加之后的大小为:" << vec_lie.size() << endl;
return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值