(YUV420轉化RGB24)編譯通過

2021-05-22 16:17:52 字數 2156 閱讀 3546

做了一段時間的攝像頭,看了網上很多帖子,也學習了不少東西,自己總結下,希望給需要的人以參考

**自己測試過,沒有問題,廢話少說。說說我的環境吧:

系統:fc4,ubuntu 7.04,8.04 均測試過

攝像頭:網眼v2000

介面:qt3.3

核心首先ov511 預設輸出是yuv420,一下是實現yuv420轉化成rgb24的實現函式

在yuv420torgb.h中:

#ifdef __cplusplus

extern "c" bitmapinfoheader;

typedef struct _bitmapfileheader bitmapfileheader;

#pragma pack(pop)//恢復對齊狀態

// init the arrays for convertion

void yuv2rgb_init();

// doing the convert

int yuv2rgb_convert(unsigned char *src0,unsigned char *src1,

unsigned char *src2, unsigned char *dst_ori, int width, int height);

// write to a file

int yuv2rgb_create_bmp_header(unsigned char *header, int xsize, int ysize);

#ifdef __cplusplus

}#endif

#endif

在yuv420torgb.c中實現如下:

/**  */

#include

#include

#include

#include "lm_yuv2rgb.h"

#define yuv2rgb24(y, u,v,rgbval24) /

#define clip0_255(x) /

((x)>255?255:(x)<0?0:(x))

#define clip16_240(x) /

((x)>240?240:(x)<16?16:(x))

#define clip16_235(x) /

((x)>235?235:(x)<16?16:(x))

long int crv_tab[256];

long int cbu_tab[256];

long int cgu_tab[256];

long int cgv_tab[256];

long int tab_76309[256];

unsigned char clp[1024];

void yuv2rgb_init()

for (i=0; i<384; i++)

clp[i] =0;

ind=384;

for (i=0;i<256; i++)

clp[ind++]=i;

ind=640;

for (i=0;i<384;i++)

clp[ind++]=255;

}int yuv2rgb_convert(unsigned char *src0,unsigned char *src1,

unsigned char *src2,unsigned char *dst_ori,

int width,int height)

d1 += 3*width;

d2 += 3*width;

py1+=   width;

py2+=   width;

}line_len = width * 3;

tmp_buf = (unsigned char *)malloc(line_len);

if(tmp_buf == null)

for (i = 0, j = height - 1; i < j; i++, j--) 

for (i = 0; i < width * height * 3; i += 3)

free(tmp_buf);

return 0;

}int yuv2rgb_create_bmp_header(unsigned char *header, int xsize,

int ysize)

以上實現yuv420轉化成rgb24,

yuv420 轉bmp的方法

yuv420 轉bmp的方法 我找到了乙個c寫的exe 但是c的水平我實在是不敢去修改那個原始碼,所以我乾脆就呼叫這個dll,在c 裡建立了下面這個類,然後呼叫 y2b.exe 來轉換,而且不會顯示出來那個黑屏.要知道怎麼回事,就看 吧 呵呵.using system using system.co...

基於opencv RGB與YUV420的轉換

opencv的cvtcolor函式可以實現rgb與yuv420的轉換 rgb轉化為yuv420範例 片段 int w 2448 寬 int h 2080 高 int buflen w h 3 2 unsigned char pyuvbuf new unsigned char buflen cv ma...

YUY2 YUYV 轉YUV420原始碼分析

原始碼思路 1 yuv有打包 packed 格式和平面 planar 格式。yuy2是packed格式,而yuv420是planar格式,需要轉換。提取出原影象中每個y u v分量,放入陣列中,在根據這些分量組合成新的yuv420格式。2 yuv420相比yuy2,在y分量上沒有變化,對u v進行各...