CxImage類型與Mat類互轉

轉自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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章