JPG bufffer转Mat

int maxlen=1024*1024;
std::vector<byte> buf;

FILE* f= fopen( "c:/f.jpg", "rb" );
string signature(maxlen, ' ');
maxlen = fread( &signature[0], 1, maxlen, f );
fclose(f);
buf.resize(maxlen);
signature = signature.substr(0, maxlen);

memcpy(&buf[0],&signature[0],maxlen);

cv::Mat ma = cv::imdecode(cv::Mat(buf),1);
imshow("",ma);
cvWaitKey(1000);

posted @ 2013-05-16 15:27  ahuo  阅读(527)  评论(0编辑  收藏  举报