获取图片所有对应坐标中的像素值。直接上代码了
#include <iostream>
#include "cv.h"
#include <highgui.h>
#include<fstream>
using namespace std;
int main()
{
IplImage *img = cvLoadImage("C:\\Users\\Sunstarisme\\Desktop\\Lemon\\All Frames\\2.bmp", CV_LOAD_IMAGE_COLOR);
uchar *data = (uchar *)img->imageData;
int step = img->widthStep / sizeof(uchar);
int channels = img->nChannels;
int R, G, B;
ofstream fout;
fout.open("RGB.txt", ios::app);
for(int i = 0; i < img->height; i++)
{
for(int j = 0; j < img->width; j++)
{
B = (int)data[i * step + j * channels + 0];
G = (int)data[i * step + j * channels + 1];
R = (int)data[i * step + j * channels + 2];
fout << "( " << i << ", " << j << " ) = ( " << R << "," << G << "," << B << ")" << endl;
}
}
fout.close();
return 0;
}
结果是: