利用Opencv读取图片RGB值并存储在txt文件中
2013-05-18 18:17
429 查看
// 交通标志检测.cpp : 定义控制台应用程序的入口点。
//
#include
#include"stdlib.h" //system需要调用这个
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include
#include
#include
#include
#include "highgui.h"
#include
#include
#include
using namespace std;
int main( int argc, char** argv )
{
IplImage *img=cvLoadImage("fuzaother.jpg",1);
ofstream fout("Bmat.txt");
CvScalar s;
cout<<"\n 开始保存咯\n";
int q=0;
for(int i=0; iheight; i++)
{
for(int j=0; jwidth; j++)
{
s=cvGet2D(img,i,j); //获取src图像中坐标为(i,j)的像素点的值
//s.val[0] 代表src图像BGR中的B通道的值~
fout<<s.val[0];
fout<<"\t";
fout<<s.val[1];
fout<<"\t";
fout<<s.val[2];
fout<<"\t";
cvSet2D(img,i,j,s); //set the (i,j) pixel value
q++;
}
}
cout<<"\n 保存完毕! \n";
cout<<"矩阵一共有"<<q<<"行"<<'\n';
system("PAUSE");
}
程序运行……
保存的txt文件如下
//
#include
#include"stdlib.h" //system需要调用这个
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include
#include
#include
#include
#include "highgui.h"
#include
#include
#include
using namespace std;
int main( int argc, char** argv )
{
IplImage *img=cvLoadImage("fuzaother.jpg",1);
ofstream fout("Bmat.txt");
CvScalar s;
cout<<"\n 开始保存咯\n";
int q=0;
for(int i=0; iheight; i++)
{
for(int j=0; jwidth; j++)
{
s=cvGet2D(img,i,j); //获取src图像中坐标为(i,j)的像素点的值
//s.val[0] 代表src图像BGR中的B通道的值~
fout<<s.val[0];
fout<<"\t";
fout<<s.val[1];
fout<<"\t";
fout<<s.val[2];
fout<<"\t";
cvSet2D(img,i,j,s); //set the (i,j) pixel value
q++;
}
}
cout<<"\n 保存完毕! \n";
cout<<"矩阵一共有"<<q<<"行"<<'\n';
system("PAUSE");
}
程序运行……
保存的txt文件如下
相关文章推荐
- 利用Opencv读取图片RGB值并存储在txt文件中
- OpenCV读取一张图片的Mat数据类型到.txt文件
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- 利用Python读取文件名并生成txt文件——以图片文件为例
- OpenCV读取一张图片的Mat数据类型到.txt文件
- Opencv读取图片像素值并保存为txt文件
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- 用opencv提取rgb,并存储到txt文件
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- opencv读取彩色/灰度图片像素值并存储在本地文件中c++代码实例及运行结果
- [Head First Python]4.读取文件datafile.txt, 去除两边空格, 存储到列表,从列表格式化(nester.py)后输出到文件man.out,other.out
- linux下opencv读取图片并存储到mysql数据库中
- OpenCV应用笔记】(彩色/灰度)图像像素值读取并保存到txt文件