基于Video4Linux的USB摄像头图像采集后显示为黑白?
时间:2007-04-15
来源:互联网
我的摄像头,palette为yuv420.抓取一帧图像后在framebuffer里显示为黑白。估计需要把yuv420转rgb,请问谁能提供一下转换代码?网上找的这个代码不行,调用后图像就全黑了~
static long int crv_tab[256];
static long int cbu_tab[256];
static long int cgu_tab[256];
static long int cgv_tab[256];
static long int tab_76309[256];
static unsigned char clp[1024]; //for clip in CCIR601
注:我把一帧的首地址传给src,frambuffer的首地址传给dst_on,width=640 and height=480为一帧的大小。
void YUV2RGB420(unsigned char *src, unsigned char *dst_ori,
int width,int height)
{
unsigned char *src0;
unsigned char *src1;
unsigned char *src2;
int y1,y2,u,v;
unsigned char *py1,*py2;
int i,j, c1, c2, c3, c4;
unsigned char *d1, *d2, *d3;
//Initialization
src0=src;
src1=src+width*height;
src2=src+width*height+width*height/4;
py1=src0;
py2=py1+width;
d1=dst_ori;
d2=d1+3*width;
for (j = 0; j < height; j += 2) {
for (i = 0; i < width; i += 2) {
u = *src1++;
v = *src2++;
c1 = crv_tab[v];
c2 = cgu_tab;
c3 = cgv_tab[v];
c4 = cbu_tab;
//up-left
y1 = tab_76309[*py1++];
*d1++ = clp[384+((y1 + c1)>>16)];
*d1++ = clp[384+((y1 - c2 - c3)>>16)];
*d1++ = clp[384+((y1 + c4)>>16)];
//down-left
y2 = tab_76309[*py2++];
*d2++ = clp[384+((y2 + c1)>>16)];
*d2++ = clp[384+((y2 - c2 - c3)>>16)];
*d2++ = clp[384+((y2 + c4)>>16)];
//up-right
y1 = tab_76309[*py1++];
*d1++ = clp[384+((y1 + c1)>>16)];
*d1++ = clp[384+((y1 - c2 - c3)>>16)];
*d1++ = clp[384+((y1 + c4)>>16)];
//down-right
y2 = tab_76309[*py2++];
*d2++ = clp[384+((y2 + c1)>>16)];
*d2++ = clp[384+((y2 - c2 - c3)>>16)];
*d2++ = clp[384+((y2 + c4)>>16)];
}
d1 += 3*width;
d2 += 3*width;
py1+= width;
py2+= width;
}
}
/****************************************************/
/* Sum the input */
/* Input: input, len */
/* Output: input */
/* Algorithm: add */
/****************************************************/
void InitConvtTbl()
{
long int crv,cbu,cgu,cgv;
int i,ind;
crv = 104597; cbu = 132201; /* fra matrise i global.h */
cgu = 25675; cgv = 53279;
for (i = 0; i < 256; i++) {
crv_tab = (i-128) * crv;
cbu_tab = (i-128) * cbu;
cgu_tab = (i-128) * cgu;
cgv_tab = (i-128) * cgv;
tab_76309 = 76309*(i-16);
}
for (i=0; i<384; i++)
clp =0;
ind=384;
for (i=0;i<256; i++)
clp[ind++]=i;
ind=640;
for (i=0;i<384;i++)
clp[ind++]=255;
}
static long int crv_tab[256];
static long int cbu_tab[256];
static long int cgu_tab[256];
static long int cgv_tab[256];
static long int tab_76309[256];
static unsigned char clp[1024]; //for clip in CCIR601
注:我把一帧的首地址传给src,frambuffer的首地址传给dst_on,width=640 and height=480为一帧的大小。
void YUV2RGB420(unsigned char *src, unsigned char *dst_ori,
int width,int height)
{
unsigned char *src0;
unsigned char *src1;
unsigned char *src2;
int y1,y2,u,v;
unsigned char *py1,*py2;
int i,j, c1, c2, c3, c4;
unsigned char *d1, *d2, *d3;
//Initialization
src0=src;
src1=src+width*height;
src2=src+width*height+width*height/4;
py1=src0;
py2=py1+width;
d1=dst_ori;
d2=d1+3*width;
for (j = 0; j < height; j += 2) {
for (i = 0; i < width; i += 2) {
u = *src1++;
v = *src2++;
c1 = crv_tab[v];
c2 = cgu_tab;
c3 = cgv_tab[v];
c4 = cbu_tab;
//up-left
y1 = tab_76309[*py1++];
*d1++ = clp[384+((y1 + c1)>>16)];
*d1++ = clp[384+((y1 - c2 - c3)>>16)];
*d1++ = clp[384+((y1 + c4)>>16)];
//down-left
y2 = tab_76309[*py2++];
*d2++ = clp[384+((y2 + c1)>>16)];
*d2++ = clp[384+((y2 - c2 - c3)>>16)];
*d2++ = clp[384+((y2 + c4)>>16)];
//up-right
y1 = tab_76309[*py1++];
*d1++ = clp[384+((y1 + c1)>>16)];
*d1++ = clp[384+((y1 - c2 - c3)>>16)];
*d1++ = clp[384+((y1 + c4)>>16)];
//down-right
y2 = tab_76309[*py2++];
*d2++ = clp[384+((y2 + c1)>>16)];
*d2++ = clp[384+((y2 - c2 - c3)>>16)];
*d2++ = clp[384+((y2 + c4)>>16)];
}
d1 += 3*width;
d2 += 3*width;
py1+= width;
py2+= width;
}
}
/****************************************************/
/* Sum the input */
/* Input: input, len */
/* Output: input */
/* Algorithm: add */
/****************************************************/
void InitConvtTbl()
{
long int crv,cbu,cgu,cgv;
int i,ind;
crv = 104597; cbu = 132201; /* fra matrise i global.h */
cgu = 25675; cgv = 53279;
for (i = 0; i < 256; i++) {
crv_tab = (i-128) * crv;
cbu_tab = (i-128) * cbu;
cgu_tab = (i-128) * cgu;
cgv_tab = (i-128) * cgv;
tab_76309 = 76309*(i-16);
}
for (i=0; i<384; i++)
clp =0;
ind=384;
for (i=0;i<256; i++)
clp[ind++]=i;
ind=640;
for (i=0;i<384;i++)
clp[ind++]=255;
}
作者: happytime008 发布时间: 2007-04-15
你用的什么方法才采集的?
read还是mmap?
交流一下?
我用mmap方法采集的,村到1.bmp文件,结果文件打开后什么都没有。
read还是mmap?
交流一下?
我用mmap方法采集的,村到1.bmp文件,结果文件打开后什么都没有。
作者: lcc812 发布时间: 2007-04-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28