OPENCV imencode与imdecode用法

来源:互联网 发布:oracle数据库中文版 编辑:程序博客网 时间:2024/06/03 20:29


上代码直接跑:

#include<iostream>#include<opencv2/core/core.hpp>#include<opencv2/opencv.hpp>using namespace std;using namespace cv;//this program is used for testing opencv encode and decode for jgeg picturesint main(){    Mat tstMat=imread("/home/lisa/dataset/02m16001200/0.jpg");   // imshow("picture",tstMat);    vector<unsigned char> inImage;    imencode(".jpg",tstMat,inImage);    size_t datalen=inImage.size();    unsigned char *msgImage=new char[datalen];    for(int i=0;i<datalen;i++)    {        msgImage[i]=inImage[i];        cout<<msgImage[i]<<endl;    }    vector<unsigned char> buff;    for(int i=0;i<datalen;i++)    {           buff.push_back(msgImage[i]);    }    Mat show=imdecode(buff,CV_LOAD_IMAGE_COLOR);    imshow("picture",show);    cv::waitKey(0);    cout<<"hello world"<<endl;    return 0;}


原创粉丝点击