1.針對于ov7670輸出的rgb565格式進行黑白二值化,可能會丟掉R、G、B中低3或2位的精確度,,實測中沒有太大影響;
2.試驗環境針對于STM32F10的板子,理想計算幀數應為每秒20幀左右,實際幀數達到每秒15幀左右;
3.此算法沒有綠波,相對較為簡單。
4.引腳連接請查看文件中README.TXT
5.圖像查看,請查看LCD屏
所有資料51hei提供下載:
ov7670攝像頭實驗黑白二值化.rar
(386.18 KB, 下載次數: 165)
2017-8-10 22:44 上傳
點擊文件名下載附件
二值化
stm32單片機源程序(主程序)如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "string.h"
- #include "ov7670.h"
- #include "tpad.h"
- #include "timer.h"
- #include "exti.h"
- #include "usmart.h"
-
- /************************************************
- ALIENTEK戰艦STM32開發板實驗35
- 攝像頭OV7670 實驗
- ************************************************/
- const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"}; //5種光照模式
- const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"}; //7種特效
- extern u8 ov_sta; //在exit.c里 面定義
- extern u8 ov_frame; //在timer.c里面定義
- unsigned char txbuf[4];
- void camera_refresh(void)
- {
- u8 v=140,h=105;
- u8 color_r,color_g,color_b;
- u16 k;
- u8 j;
- u16 color;
- if(ov_sta)//有幀中斷更新?
- {
- LCD_Scan_Dir(U2D_L2R); //從上到下,從左到右
- if(lcddev.id==0X1963)LCD_Set_Window((lcddev.width-240)/2,(lcddev.height-320)/2,240,320);//將顯示區域設置到屏幕中央
- else if(lcddev.id==0X5510||lcddev.id==0X5310)LCD_Set_Window((lcddev.width-320)/2,(lcddev.height-240)/2,320,240);//將顯示區域設置到屏幕中央
- LCD_WriteRAM_Prepare(); //開始寫入GRAM
- OV7670_RRST=0; //開始復位讀指針
- OV7670_RCK_L;
- OV7670_RCK_H;
- OV7670_RCK_L;
- OV7670_RRST=1; //復位讀指針結束
- OV7670_RCK_H;
- for(j=0;j<240;j++)
- {
- for(k=0;k<320;k++){
- OV7670_RCK_L;
- color=GPIOC->IDR&0XFF; //讀數據
- OV7670_RCK_H;
- color<<=8;
- OV7670_RCK_L;
- color|=GPIOC->IDR&0XFF; //讀數據
- OV7670_RCK_H;
-
- // LCD->LCD_RAM=color;
-
- color_r=color>>11;
- color_g=(color&0x07ff)>>5;
- color_b=color&0x001f;
- color_g=(color_g<<2)*58;
- color_b=(color_b<<3)*11;
- color=(color_r+color_g+color_b+50)/100;
- if(color>100){
- LCD->LCD_RAM=0xffff;
- }
- else{
- LCD->LCD_RAM=0;
- }
-
-
- }
- }
-
- }
- ov_sta=0; //清零幀中斷標記
- ov_frame++;
- LCD_Scan_Dir(DFT_SCAN_DIR); //恢復默認掃描方向
- }
- }
- int main(void)
- {
-
- u8 key;
- u8 lightmode=0,saturation=2,brightness=2,contrast=2;
- u8 effect=0;
- u8 i=0;
- u8 msgbuf[15]; //消息緩存區
- u8 tm=0;
- txbuf[0]=0x01;
- txbuf[1]=0x02;
- txbuf[2]=0x03;
- txbuf[3]=0x04;
-
- delay_init(); //延時函數初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置中斷優先級分組為組2:2位搶占優先級,2位響應優先級
- uart_init(115200); //串口初始化為 115200
- usmart_dev.init(72); //初始化USMART
- LED_Init(); //初始化與LED連接的硬件接口
- KEY_Init(); //初始化按鍵
- LCD_Init(); //初始化LCD
- TPAD_Init(6); //觸摸按鍵初始化
- POINT_COLOR=RED; //設置字體為紅色
- LCD_ShowString(30,50,200,16,16,"WarShip STM32");
- LCD_ShowString(30,70,200,16,16,"OV7670 TEST");
- LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
- LCD_ShowString(30,110,200,16,16,"2015/1/18");
- LCD_ShowString(30,130,200,16,16,"KEY0:Light Mode");
- LCD_ShowString(30,150,200,16,16,"KEY1:Saturation");
- LCD_ShowString(30,170,200,16,16,"KEY2:Brightness");
- LCD_ShowString(30,190,200,16,16,"KEY_UP:Contrast");
- LCD_ShowString(30,210,200,16,16,"TPAD:Effects");
- LCD_ShowString(30,230,200,16,16,"OV7670 Init...");
- while(OV7670_Init())//初始化OV7670
- {
- LCD_ShowString(30,230,200,16,16,"OV7670 Error!!");
- delay_ms(200);
- LCD_Fill(30,230,239,246,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(30,230,200,16,16,"OV7670 Init OK");
- delay_ms(1500);
- OV7670_Light_Mode(lightmode);
- OV7670_Color_Saturation(saturation);
- OV7670_Brightness(brightness);
- OV7670_Contrast(contrast);
- OV7670_Special_Effects(effect);
- TIM6_Int_Init(10000,7199); //10Khz計數頻率,1秒鐘中斷
- EXTI8_Init(); //使能定時器捕獲
- OV7670_Window_Set(12,176,240,320); //設置窗口
- OV7670_CS=0;
- LCD_Clear(BLACK);
- while(1)
- {
- key=KEY_Scan(0);//不支持連按
- if(key)
- {
- tm=20;
- switch(key)
- {
- case KEY0_PRES: //燈光模式Light Mode
- lightmode++;
- if(lightmode>4)lightmode=0;
- OV7670_Light_Mode(lightmode);
- sprintf((char*)msgbuf,"%s",LMODE_TBL[lightmode]);
- break;
- case KEY1_PRES: //飽和度Saturation
- saturation++;
- if(saturation>4)saturation=0;
- OV7670_Color_Saturation(saturation);
- sprintf((char*)msgbuf,"Saturation:%d",(signed char)saturation-2);
- break;
- case KEY2_PRES: //亮度Brightness
- brightness++;
- if(brightness>4)brightness=0;
- OV7670_Brightness(brightness);
- sprintf((char*)msgbuf,"Brightness:%d",(signed char)brightness-2);
- break;
- case WKUP_PRES: //對比度Contrast
- contrast++;
- if(contrast>4)contrast=0;
- OV7670_Contrast(contrast);
- sprintf((char*)msgbuf,"Contrast:%d",(signed char)contrast-2);
- break;
- }
- }
- if(TPAD_Scan(0))//檢測到觸摸按鍵
- {
- effect++;
- if(effect>6)effect=0;
- OV7670_Special_Effects(effect);//設置特效
- sprintf((char*)msgbuf,"%s",EFFECTS_TBL[effect]);
- tm=20;
- }
- camera_refresh();//更新顯示
- if(tm)
- {
- LCD_ShowString((lcddev.width-240)/2+30,(lcddev.height-320)/2+60,200,16,16,msgbuf);
- tm--;
- }
- i++;
- if(i==15)//DS0閃爍.
- {
- i=0;
- LED0=!LED0;
- }
- }
- }
復制代碼
|