赞
踩
opencv的cvtColor函数可以实现RGB与YUV420的转换
RGB转化为YUV420范例代码片段:
- <pre name="code" class="cpp"><span style="white-space:pre"> </span>int w = 2448;<span style="white-space:pre"> </span>//宽
- int h= 2080;<span style="white-space:pre"> </span>//高
- int bufLen = w * h * 3 / 2;
- unsigned char* pYuvBuf = new unsigned char[bufLen];
-
-
- cv::Mat srcImg;
- cv::Mat yuvImg;
- cv::Mat convertImg;
-
- srcImg = cv::imread("d:\\1.jpg");//读入一个2448*2080图像
-
- imshow("src",srcImg);//显示原图像
- cvWaitKey(1000);
- destroyAllWindows();
-
-
- cvtColor(srcImg, yuvImg, CV_BGR2YUV_I420);
- memcpy(pYuvBuf, yuvImg.data, bufLen * sizeof(unsigned char));//pYuvBuf即为所获取的YUV420数据
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。