opencv 如何缩放 YUV420 数据
我从文件中读取 一帧 yuv420 的数据,保存到一个数组中,
请问 如何使用opencv 对yuv数据进行缩放?
或者不用opencv 使用其他的函数?
[解决办法]
yuv转rgb的函数:
void YUV420_C_RGB( char* pYUV, unsigned char* pRGB, int height, int width)
{
char* pY = pYUV;
char* pU = pYUV+height*width;
char* pV = pU+(height*width/4);
unsigned char* pBGR = NULL;
unsigned char R = 0;
unsigned char G = 0;
unsigned char B = 0;
char Y = 0;
char U = 0;
char V = 0;
double tmp = 0;
for ( int i = 0; i < height; ++i )
{
for ( int j = 0; j < width; ++j )
{
pBGR = pRGB+ i*width*3+j*3;
Y = *(pY+i*width+j);
U = *pU;
V = *pV;
//B
tmp = MB(Y, U, V);
//B = (tmp > 255) ? 255 : (char)tmp;
//B = (B<0) ? 0 : B;
B = (unsigned char)tmp;
//G
tmp = MG(Y, U, V);
//G = (tmp > 255) ? 255 : (char)tmp;
// G = (G<0) ? 0 : G;
G = (unsigned char)tmp;
//R
tmp = MR(Y, U, V);
//R = (tmp > 255) ? 255 : (char)tmp;
//R = (R<0) ? 0 : R;
R = (unsigned char)tmp;
*pBGR = R;
*(pBGR+1) = G;
*(pBGR+2) = B;
if ( i%2 == 0 && j%2 == 0)
{
*pU++;
//*pV++;
}
else
{
if ( j%2 == 0 )
{
*pV++ ;
}
}
}
}
}