CxImage类型与Mat类互转

来源:互联网 发布:unity3d 怎么加模型 编辑:程序博客网 时间:2024/06/09 22:42

转自http://blog.csdn.net/liulina603/article/details/43053957

CxImage转Mat

    CxImage img;    uint8_t *buf=NULL;    int32_t len=0;    bool rs =img.Encode(buf,len,CXIMAGE_FORMAT_BMP);    cv::Mat temp2;    vector<uchar> buff2;    buff2.resize(len);    memcpy(&buff2[0],buf,len);    temp2= cv::imdecode(buff2,1);    delete []buf; //要释放buf,这个buf在函数里分配了内存    cv::imshow("111",temp2);    cv::waitKey();

Mat转CxImage

    Mat temp2;    vector<uchar> buff;    cv::imencode(".bmp",temp2,buff);    CxImage img2(&buff[0],buff.size(),CXIMAGE_FORMAT_BMP);
原创粉丝点击