从buffer快速保存pgm图片,不借助第三方库

来源:互联网 发布:数据库导入数据的方法 编辑:程序博客网 时间:2024/05/19 10:35

#include <iostream>

#include <stdlib.h>

#include <list>

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

#include <opencv2/opencv.hpp>


using namespacestd;

using namespacecv;


int pgm_encode(constunsigned char *image,int width, int height,int color_byte, unsignedchar *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);

    

    

    return0;

}


pgm相关资料:https://zh.wikipedia.org/wiki/PBM%E6%A0%BC%E5%BC%8F

0 0
原创粉丝点击