把YUV转化成opencv中的Mat格式的两行代码备份

如果是把YUV灰度图(只有Y分量)转化为Mat
1
cv::Mat cv_img; 2 cv::Mat cv_yuv(height, width, CV_8UC1, pFrame);//pFrame为YUV数据地址 3 cv_img = cv::Mat(height, width, CV_LOAD_IMAGE_COLOR); 4 cv::cvtColor(cv_yuv, cv_img, COLOR_GRAY2BGR);

 如果是把YUV彩色图转化为Mat

1 1 cv::Mat cv_img;
2 2 cv::Mat cv_yuv(height + height/2, width, CV_8UC1, pFrame);//pFrame为YUV数据地址,另外这里就是用 CV_8UC1非 CV_8UC3.
3 3 cv_img = cv::Mat(height, width, CV_8UC3); 
4 4 cv::cvtColor(cv_yuv, cv_img, COLOR_YUV2BGR_I420);

 

posted @ 2019-06-10 17:42  cumtchw  阅读(1075)  评论(0编辑  收藏  举报