無線圖像(視頻)傳輸系統(tǒng)ARM9+Atmega16+OV7620+nrf24l01(三)
OV7620支持的像素是:VGA(640*480)、QVGA(320*240),我用的是QVGA模式(配合液晶屏顯示)。使用OV7620關(guān)鍵還是正確配置其內(nèi)部寄存器,還有就是SCCB數(shù)據(jù)傳輸協(xié)議的實現(xiàn)。
本文引用地址:http://www.ex-cimer.com/article/148440.htm首先有必要說下OV7620所支持的圖像格式,因為,我對圖像這塊不熟悉,這里只說明OV支持的幾種輸出格式,以及相關(guān)寄存器的配置。
RGB16/8 bit ,這些格式都不是真正的RGB數(shù)據(jù)流,而是Bayer矩陣,所以在終端顯示時,必須將Bayer矩陣轉(zhuǎn)換為RGB。轉(zhuǎn)換的核心思想是通過插值算法將Bayer矩陣中的每個像素值(一個字節(jié))轉(zhuǎn)換為RGB三個字節(jié)(我不懂圖像,只能說出方法,具體算法后面我會貼出)。
本次采用的是RGB raw16 bit 模式,由于OV7620只引出了Y通道,所以配置為one line mode(這里出現(xiàn)了問題,明明RGB三個分量都有,但是通過插值后顯示出來的盡然還是灰度圖像,后面再分析原因)。下面貼出OV7620相關(guān)寄存器的配置:
unsigned char reg_12_w_reset[2]={0x12,0x80};//先清零
unsigned char reg_11_w[2]={0x11,0x00}; //配置PCLK速率 PCLK=(CLK_input/(CLK5:0>+1)*2)),本次為1/2時鐘頻率
unsigned char reg_12_w[2]={0x12,0x2c}; //使能AGC,選擇raw data outtput,并且使能自動白平衡
unsigned char reg_14_w[2]={0x14,0x24};//QVGA digital output format ,RGB gamma on
unsigned char reg_28_w[2]={0x28,0xa0}; //one-line RGB data format ,select Progressive scan mode
下面是Bayer轉(zhuǎn)RGB24的算法(在液晶屏上顯示時還要轉(zhuǎn)為RGB16):
void bayer2rgb24(unsigned char *dst, unsigned char *src, long WIDTH, long HEIGHT)
{
long int i;
unsigned char *rawpt, *scanpt;
long int size;
rawpt = src;
scanpt = dst;
size = WIDTH*HEIGHT;
for ( i = 0; i size; i++ )
{
if ( (i/WIDTH) % 2 == 0 ) //奇數(shù)行
{
if ( (i % 2) == 0 ) //奇數(shù)列
{
/* B */
if ( (i > WIDTH) ((i % WIDTH) > 0) )
{
*scanpt++ = ((long int)*(rawpt-WIDTH-1)+(long int)*(rawpt-WIDTH+1)+
(long int)*(rawpt+WIDTH-1)+(long int)*(rawpt+WIDTH+1))/4; /* R */
*scanpt++ = ((long int)*(rawpt-1)+(long int)*(rawpt+1)+
(long int)*(rawpt+WIDTH)+(long int)*(rawpt-WIDTH))/4; /* G */
*scanpt++ = *rawpt; /* B */
}
else /* first line or left column */
{
*scanpt++ = *(rawpt+WIDTH+1); /* R */
*scanpt++ = ((long int)*(rawpt+1)+(long int)*(rawpt+WIDTH))/2; /* G */
*scanpt++ = *rawpt; /* B */
}
}
else
{
/* (B)G */
if ( (i > WIDTH) ((i % WIDTH) (WIDTH-1)) )
{
*scanpt++ = ((long int)*(rawpt+WIDTH)+(long int)*(rawpt-WIDTH))/2; /* R */
*scanpt++ = *rawpt; /* G */
*scanpt++ = ((long int)*(rawpt-1)+(long int)*(rawpt+1))/2; /* B */
}
else /* first line or right column */
{
*scanpt++ = *(rawpt+WIDTH); /* R */
*scanpt++ = *rawpt; /* G */
*scanpt++ = *(rawpt-1); /* B */
}
}
}
else //偶數(shù)行
{
if ( (i % 2) == 0 ) //奇數(shù)列
{
/* G(R) */
if ( (i (WIDTH*(HEIGHT-1))) ((i % WIDTH) > 0) )
{
*scanpt++ = ((long int)*(rawpt-1)+(long int)*(rawpt+1))/2; /* R */
*scanpt++ = *rawpt; /* G */
*scanpt++ = ((long int)*(rawpt+WIDTH)+(long int)*(rawpt-WIDTH))/2; /* B */
}
else
{
/* bottom line or left column */
*scanpt++ = *(rawpt+1); /* R */
*scanpt++ = *rawpt; /* G */
*scanpt++ = *(rawpt-WIDTH); /* B */
}
}
else
{
/* R */
if ( i (WIDTH*(HEIGHT-1)) ((i % WIDTH) (WIDTH-1)) )
{
*scanpt++ = *rawpt; /* R */
*scanpt++ = ((long int)*(rawpt-1)+(long int)*(rawpt+1)+
(long int)*(rawpt-WIDTH)+(long int)*(rawpt+WIDTH))/4; /* G */
*scanpt++ = ((long int)*(rawpt-WIDTH-1)+(long int)*(rawpt-WIDTH+1)+
(long int)*(rawpt+WIDTH-1)+(long int)*(rawpt+WIDTH+1))/4; /* B */
} else {
/* bottom line or right column */
*scanpt++ = *rawpt; /* R */
*scanpt++ = ((long int)*(rawpt-1)+(long int)*(rawpt-WIDTH))/2; /* G */
*scanpt++ = *(rawpt-WIDTH-1); /* B */
}
}
}
rawpt++;
}
}
評論