说明:从海康摄像头采集到的数据时YV12类型的,需要转换为RGB24,才能进行数据处理。而从其他的摄像头上面采集到的数据一般都是RGB24的,则可以直接处理。
bool YV12_to_RGB24(unsigned char* pYV12, unsigned char* pRGB24, int iWidth, int iHeight)
{if(!pYV12 || !pRGB24)
return false;
const long nYLen = long(iHeight * iWidth);
const int nHfWidth = (iWidth>>1);
if(nYLen<1 || nHfWidth<1)
return false;
// yv12数据格式,其中Y分量长度为width * height, U和V分量长度都为width * height / 4
// |WIDTH |
// y......y--------
// y......y HEIGHT
// y......y
// y......y--------
// v..v
// v..v
// u..u
// u..u
unsigned char* yData = pYV12;//y的首地址
unsigned char* vData = &yData[nYLen];//u的首地址
unsigned char* uData = &vData[nYLen>>2]; //v的首地址
if(!uData || !vData)

本文介绍了如何将从海康摄像头获取的YV12格式图像转换为RGB24格式,以便进行进一步的数据处理。提供的C++函数`YV12_to_RGB24`接受YV12格式的图像数据、RGB24的目标缓冲区及图像的宽度和高度作为参数。
最低0.47元/天 解锁文章
966

被折叠的 条评论
为什么被折叠?



