opencv读取图像像素值读取并保存到txt文件(一)RGB

#include “stdafx.h”
#include"cv.h"
#include
#include
#include
#include
#include
#include “iostream”
#include
#include

using namespace std;

int main()
{
IplImage* img = 0;
int height,width,step,channels;
int i,j,k;
img = cvLoadImage(“k:\lena.jpg”,-1);
CvScalar s;
height = img->height;
width = img->width;
ofstream outFile_B;
ofstream outFile_G;
ofstream outFile_R;
outFile_B.open(“k:\out_B.txt”);
outFile_G.open(“k:\out_G.txt”);
outFile_R.open(“k:\out_R.txt”);

//get the pixel value

//CvScalar s;
for(i=0;i {
for(j=0;j {
s=cvGet2D(img,i,j); // get the (j,i) pixel value
outFile_B< outFile_G< outFile_R< }
outFile_B< outFile_G< outFile_R< }
return 0;
}

备注:
参考博客 opencv中文网
SkySeraph博客园

你可能感兴趣的:(图像处理与机器视觉)