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

#include “stdafx.h”
#include"cv.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include
#include
#include “iostream”
#include <opencv/cv.h>
#include <opencv/highgui.h>

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<height;i++) //i 代表 y 轴
{
for(j=0;j<width;j++) //j 代表 x轴
{
s=cvGet2D(img,i,j); // get the (j,i) pixel value
outFile_B<<s.val[0]<<" “;
outFile_G<<s.val[1]<<” “;
outFile_R<<s.val[2]<<” ";
}
outFile_B<<endl;
outFile_G<<endl;
outFile_R<<endl;
}
return 0;
}

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

相关推荐
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页