19,467
社区成员
发帖
与我相关
我的任务
分享
void WriteYuv()
{
cv::VideoCapture vc;
bool flag = vc.open("S1000008.avi");
if (!flag)
{
printf("avi file open error \n");
system("pause");
exit(-1);
}
int frmCount = vc.get(CV_CAP_PROP_FRAME_COUNT);
frmCount -= 5;
printf("frmCount: %d \n", frmCount);
int w = vc.get(CV_CAP_PROP_FRAME_WIDTH);
int h = vc.get(CV_CAP_PROP_FRAME_HEIGHT);
int bufLen = w*h*3/2;
unsigned char* pYuvBuf = new unsigned char[bufLen];
FILE* pFileOut = fopen("result.yuv", "w+");
if (!pFileOut)
{
printf("pFileOut open error \n");
system("pause");
exit(-1);
}
printf("pFileOut open ok \n");
for (int i=0; i<frmCount; i++)
{
printf("%d/%d \n", i+1, frmCount);
cv::Mat srcImg;
vc>>srcImg;
cv::imshow("img", srcImg);
cv::waitKey(1);
cv::Mat yuvImg;
cv::cvtColor(srcImg, yuvImg, CV_BGR2YUV_I420);
memcpy(pYuvBuf, yuvImg.data, bufLen*sizeof(unsigned char));
fwrite(pYuvBuf, bufLen*sizeof(unsigned char), 1, pFileOut);
}
fclose(pFileOut);
delete[] pYuvBuf;
}
[/quote]
RGB565 编码是16位 前五位表示R 中间六位表示G 最后五位表示B
YUV420 是一个U和V共用四个Y
公式就是这个
Y'= 0.299*R' + 0.587*G' + 0.114*B'
U'= -0.147*R' - 0.289*G' + 0.436*B' = 0.492*(B'- Y')
V'= 0.615*R' - 0.515*G' - 0.100*B' = 0.877*(R'- Y')
