如何将YUV文件中每帧的数据转换成OpenCV中的Ipl
2016-09-15 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517186
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
实现代码如下:
int colorchannel = 3;
IplImage *pCurrFrame = NULL;
pInFile = fopen(input.infile, "rb");
if (pInFile == NULL)
{
printf("Error: Can\'t open input YUV file\\n");
exit(-1);
}
fseek(pInFile, 0, SEEK_SET);
pCurrFrame = cvCreateImageHeader( cvSize(input.img_width,input.img_height),
IPL_DEPTH_8U, colorchannel);
cvNamedWindow("CurrFrame", 1);
for(framenum = 0; framenum<input.no_frames; framenum++)
{
posstep = img_size;
fseek(pInFile, posstep, SEEK_CUR);
if (fread(org_yuv_buffer, 1, img_size, pInFile)<(Byte)img_size)
printf("Error: File end!\\n");
//****************************Readin pixel values
//store 1/1 pixel value - luma
for (j =0; j < input.img_height; j++)
for (i = 0; i < input.img_width; i++)
original_frame[0][j] = org_yuv_buffer[j * input.img_width + i];
//store 1/1 pixel value - chroma
for (j = 0; j < input.img_height/2; j++)
for (i = 0; i < input.img_width/2; i++)
{
original_frame[1][j] = org_yuv_buffer[img_Y_size + j * input.img_width/2 + i];
original_frame[2][j] = org_yuv_buffer[img_Y_size + img_UV_size + j * input.img_width/2 + i];
}
//****************************Convert YUV format to RGB format
for (j =0; j < input.img_height; j++)
for (i = 0; i < input.img_width; i++)
{
// Color B
rgb_frame[j*input.img_width*colorchannel+i*colorchannel+0] = (Byte) (1.164*(original_frame[0][j] - 16) + 2.018*(original_frame[1][j/2][i/2] - 128));
// Color G
rgb_frame[j*input.img_width*colorchannel+i*colorchannel+1] = (Byte) (1.164*(original_frame[0][j] - 16) - 0.813*(original_frame[2][j/2][i/2] - 128)
- 0.391*(original_frame[1][j/2][i/2] - 128));
// Color R
rgb_frame[j*input.img_width*colorchannel+i*colorchannel+2] = (Byte) (1.164*(original_frame[0][j] - 16) + 1.596*(original_frame[2][j/2][i/2] - 128));
}
cvSetData(pCurrFrame, rgb_frame, input.img_width*colorchannel);
cvShowImage("CurrFrame", pCurrFrame);
if( cvWaitKey(33) >= 0 )
break;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询