OPENCV imencode與imdecode用法


上代碼直接跑:

#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 pictures
int 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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章