示例:
640*480 NV12图像,提取Y部分数据,将Y数据做降采样,隔行隔列取值,保存成文件。
#include <stdio.h>
#include <string.h>
#define WIDTH_ORIGIN (640)
#define HEIGHT_ORIGIN (480)
#define WIDTH_BINNING (320)
#define HEIGHT_BINNING (240)
char image_buffer[WIDTH_ORIGIN * HEIGHT_ORIGIN];
char binn_buffer[WIDTH_BINNING * HEIGHT_BINNING];
int main()
{
int i = 0;
int j = 0;
unsigned int addr = 0;
char *originimage = "640_480.yuv";
FILE *imagefile = fopen(originimage,"a+");
if(NULL == imagefile)
{
printf("open file[%s] failed!\n", originimage);
return -1;
}
memset((void*)image_buffer,0,WIDTH_ORIGIN * HEIGHT_ORIGIN);
fread((void*)image_buffer, 1, WIDTH_ORIGIN* HEIGHT_ORIGIN, imagefile);
fclose(imagefile);
for(i = 0; i < HEIGHT_BINNING; i++)
{
for(j = 0; j < WIDTH_BINNING; j++)
{
binn_buffer[i * WIDTH_BINNING + j] = image_buffer[i * WIDTH_ORIGIN * 2 + 2 * j];
}
}
char *binnimage = "binn.yuv";
FILE *fp_binn = fopen(binnimage,"a+");
if(NULL == fp_binn)
{
printf("open file[%s] failed!\n", binnimage);
return -1;
}
fwrite((void*)binn_buffer, 1, WIDTH_BINNING * HEIGHT_BINNING, fp_binn);
fclose(fp_binn);
}