void CALLBACK DecCBFun(long lPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2)
{
long lFrameType=pFrameInfo->nType;
if(lFrameType==T_YV12)
{
long iWidth=pFrameInfo->nWidth;
long iHeight=pFrameInfo->nHeight;
unsigned char *pYV12=(unsigned char*)pBuf;
unsigned char* pRGB24=??????;
YV12_to_RGB24( pYV12, pRGB24, iWidth, iHeight);
}
}
int YV12_to_RGB24(unsigned char* pYV12, unsigned char* pRGB24, long iWidth, long iHeight)
{
if(!pYV12 || !pRGB24)
{
cout<<"error "<<endl;
return -1;
}
const long nYLen = long(iHeight * iWidth);
const int nHfWidth = (iWidth>>1);
if(nYLen<1 || nHfWidth<1)
return -1;
unsigned char* yData = pYV12;
unsigned char* vData = &yData[nYLen];
unsigned char* uData = &vData[nYLen>>2];
if(!uData || !vData)
return -1;
int rgb[3];
int i, j, m, n, x, y;
m = -iWidth;
n = -nHfWidth;
for(y=0; y < iHeight; y++)
{
m += iWidth;
if(!(y % 2))
n += nHfWidth;
for(x=0; x < iWidth; x++)
{
i = m + x;
j = n + (x>>1);
rgb[2] = int(yData[i] + 1.370705 * (vData[j] - 128)); // r分量值
rgb[1] = int(yData[i] - 0.698001 * (uData[j] - 128) - 0.703125 * (vData[j] - 128)); // g分量值
rgb[0] = int(yData[i] + 1.732446 * (uData[j] - 128)); // b分量值
j = nYLen - iWidth - m + x;
i = (j<<1) + j;
for(j=0; j<3; j++)
{
if(rgb[j]>=0 && rgb[j]<=255)
pRGB24[i + j] = rgb[j];
else
pRGB24[i + j] = (rgb[j] < 0) ? 0 : 255;
}
// processVideo(pRGB24[i + j]);
}
//Mat img(pRGB24[i+j]);
imshow("window",pRGB24[i+j]);
}
return 0;
}
关于海康摄像头得到的数据,我想用opencv做处理,但是他的视频格式是YV12,我现在用上面这个函数转换,但是我不知道unsigned char* pRGB24=?????该怎么定义,希望大家帮帮忙 ,谢谢大家了