opencv 保存灰度图像的像素值

#include<opencv2/opencv.hpp>
 #include <fstream>
#include<iostream>
using namespace std;
using namespace cv;

 

 
 int main(int argc, char* argv[])
 {
     IplImage* img =  cvLoadImage("e:\\kankan\\baihe.jpg",0);
     CvScalar p;
     ofstream outfile1("d:\\gray.txt");
     outfile1<<"图像宽和高:"<<img->width<<"*"<<img->height<<endl;
     outfile1<<"图像像素值"<<endl;
     //cvFlip(img);
     for(int j=0;j<img->height;j++)
     {
         for(int i=0;i<img->width;i++)
         {
             p = cvGet2D(img,j,i);//(j,i)
             outfile1<<p.val[0]<<" ";
         }
         outfile1<<endl;
     }    //*/
 
     return 0;
 }

2 灰度图像

①输入:一副灰度图像gray.jpg

②输出:gray.txt


你可能感兴趣的:(opencv 保存灰度图像的像素值)