opencv1.0,IplImage类型存储图像数据,3通道
void print_img(IplImage* img)
{
int x,y;
FILE *file;
file = fopen("1.txt", "w");
uchar* data = (uchar *)img->imageData;
int step = img->widthStep / sizeof(uchar);
int channels = img->nChannels;
for (int i = 0; i<img->height; i++)
for (int j = 0; j<img->width; j++)
{
fprintf(file, "%d %d %d ", data[i*step + j*channels + 0], data[i*step + j*channels + 1], data[i*step + j*channels + 2]);
}
fclose(file);
}
opencv2.4.9,Mat类型存储图像数据,3通道
void print_img(Mat img)
{
int x,y;
FILE *file;
file = fopen("1.txt", "w");
for (int x = 0; x<img.rows; x++)
{
for (int y = 0; y<img.cols; y++)
{
fprintf(file, "%d %d %d ", img.at<Vec3b>(x, y)[0], img.at<Vec3b>(x, y)[1], img.at<Vec3b>(x, y)[2]);
}
}
}