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

版权声明:本文为博主原创文章,转载请注明链接,[email protected],欢迎交流 https://blog.csdn.net/liboxiu/article/details/84621975

#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博客园

猜你喜欢

转载自blog.csdn.net/liboxiu/article/details/84621975