#include <iostream>
#include <stdlib.h>
#include <list>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int pgm_encode(const unsigned char *image, int width, int height, int color_byte, unsigned char *pgm_buf, int *buf_size);
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
char filename[256] = "testImages/1.bmp";
Mat testImage = imread(filename,0);
if (testImage.data == NULL ) {
cout<<"load image error"<<endl;
exit(1);
}
FILE* pfile = fopen("test.pbm","wb");
int w = testImage.cols;
int h = testImage.rows;
fprintf(pfile, "P%d\n%d %d\n255\n", 5, w, h);
fwrite(testImage.data, 1, w*h, pfile);
return 0;
}
pgm相关资料:https://zh.wikipedia.org/wiki/PBM%E6%A0%BC%E5%BC%8F