久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9254|回復: 16
打印 上一主題 下一主題
收起左側

利用ov7670識別紅綠藍物體與定位

  [復制鏈接]
跳轉到指定樓層
樓主
ID:239323 發表于 2017-10-14 10:25 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
利用ov7670實現物體的簡單識別及定位

單片機源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "lcd.h"
  6. #include "usart.h"         
  7. #include "string.h"
  8. #include "ov7670.h"
  9. #include "tpad.h"
  10. #include "timer.h"
  11. #include "exti.h"
  12. #include "usmart.h"
  13. #include "EasyTracered.h"

  14. /************************************************
  15. ALIENTEK精英STM32開發板實驗33
  16. 攝像頭OV7670 實驗
  17. 作者:正點原子 @ALIENTEK
  18. ************************************************/


  19. const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"};                                                        //5種光照模式            
  20. const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"};        //7種特效
  21. extern u8 ov_sta;        //在exit.c里 面定義
  22. extern u8 ov_frame;        //在timer.c里面定義                 
  23. u16 r0,r1;
  24. u16 g0,g1;
  25. u16 b0,b1;
  26. //更新LCD顯示
  27. void camera_refresh(void)
  28. {
  29.   
  30.         RESULT Resured;//判定為的目標條件
  31.         RESULT Resugreen;
  32.         RESULT Resublue;
  33.         
  34.   TARGET_CONDI Conditionred={215,240,20,240,30,160,30,30,320,240};        //紅色1   API參數  hsl的閾值,識別時用的
  35.   TARGET_CONDI Conditiongreen={70,110,20,240,50,100,30,30,320,240};        //綠色1  API參數  hls的閾值,識別時用的
  36.   TARGET_CONDI Conditionblue={120,160,20,240,30,90,30,30,150,150};        //藍色1   API參數  hsl的閾值,識別時用的

  37.         u32 j;
  38.          u16 color;         
  39.         if(ov_sta)//有幀中斷更新?
  40.         {
  41.                 LCD_Scan_Dir(U2D_L2R);                //從上到下,從左到右  
  42.                 if(lcddev.id==0X1963)LCD_Set_Window((lcddev.width-240)/2,(lcddev.height-320)/2,240,320);//將顯示區域設置到屏幕中央
  43.                 else if(lcddev.id==0X5510||lcddev.id==0X5310)LCD_Set_Window((lcddev.width-320)/2,(lcddev.height-240)/2,320,240);//將顯示區域設置到屏幕中央
  44.                 LCD_WriteRAM_Prepare();     //開始寫入GRAM        
  45.                 OV7670_RRST=0;                                //開始復位讀指針
  46.                 OV7670_RCK_L;
  47.                 OV7670_RCK_H;
  48.                 OV7670_RCK_L;
  49.                 OV7670_RRST=1;                                //復位讀指針結束
  50.                 OV7670_RCK_H;
  51.                 for(j=0;j<76800;j++)
  52.                 {
  53.                         OV7670_RCK_L;
  54.                         color=GPIOC->IDR&0XFF;        //讀數據
  55.                         OV7670_RCK_H;
  56.                         color<<=8;  
  57.                         OV7670_RCK_L;
  58.                         color|=GPIOC->IDR&0XFF;        //讀數據
  59.                         OV7670_RCK_H;
  60.                         LCD->LCD_RAM=color;   
  61.                 }   

  62.      if(Trace(&Conditionred,&Resured) )                      //API
  63.                         {                                
  64.                                 LCD_Fillred(Resured.x-Resured.w/2,Resured.y-Resured.h/2,Resured.x+Resured.w/2,Resured.y-Resured.h/2+1,0xf800);//u16 x,u16 y,u16 width,u16 hight,u16 Color
  65.                                 LCD_Fillred(Resured.x-Resured.w/2,Resured.y-Resured.h/2,Resured.x-Resured.w/2+1,Resured.y+Resured.h/2,0xf800);
  66.                                 LCD_Fillred(Resured.x-Resured.w/2,Resured.y+Resured.h/2,Resured.x+Resured.w/2,Resured.y+Resured.h/2+1,0xf800);
  67.                                 LCD_Fillred(Resured.x+Resured.w/2,Resured.y-Resured.h/2,Resured.x+Resured.w/2+1,Resured.y+Resured.h/2,0xf800);
  68.                                 LCD_Fillred(Resured.x-2,Resured.y-2,Resured.x+2,Resured.y+2,0xf800);        
  69.                                   //LED1=!LED1;
  70.                                   r0=Resured.x;
  71.                                   r1=Resured.y;
  72.                         }               
  73.                         if(Trace1(&Conditiongreen,&Resugreen) )                      //API
  74.                         {                                
  75.                                 LCD_Fillgreen(Resugreen.x-Resugreen.w/2,Resugreen.y-Resugreen.h/2,Resugreen.x+Resugreen.w/2,Resugreen.y-Resugreen.h/2+1,0xf800);//u16 x,u16 y,u16 width,u16 hight,u16 Color
  76.                                 LCD_Fillgreen(Resugreen.x-Resugreen.w/2,Resugreen.y-Resugreen.h/2,Resugreen.x-Resugreen.w/2+1,Resugreen.y+Resugreen.h/2,0xf800);
  77.                                 LCD_Fillgreen(Resugreen.x-Resugreen.w/2,Resugreen.y+Resugreen.h/2,Resugreen.x+Resugreen.w/2,Resugreen.y+Resugreen.h/2+1,0xf800);
  78.                                 LCD_Fillgreen(Resugreen.x+Resugreen.w/2,Resugreen.y-Resugreen.h/2,Resugreen.x+Resugreen.w/2+1,Resugreen.y+Resugreen.h/2,0xf800);
  79.                                 LCD_Fillgreen(Resugreen.x-2,Resugreen.y-2,Resugreen.x+2,Resugreen.y+2,0xf800);               
  80.                                  // LED1=!LED1;
  81.                                   g0=Resugreen.x;
  82.                                   g1=Resugreen.y;
  83.                         }               
  84.      if(Trace2(&Conditionblue,&Resublue) )                      //API
  85.                         {                                
  86.                                 LCD_Fillblue(Resublue.x-Resublue.w/2,Resublue.y-Resublue.h/2,Resublue.x+Resublue.w/2,Resublue.y-Resublue.h/2+1,0xf800);//u16 x,u16 y,u16 width,u16 hight,u16 Color
  87.                                 LCD_Fillblue(Resublue.x-Resublue.w/2,Resublue.y-Resublue.h/2,Resublue.x-Resublue.w/2+1,Resublue.y+Resublue.h/2,0xf800);
  88.                                 LCD_Fillblue(Resublue.x-Resublue.w/2,Resublue.y+Resublue.h/2,Resublue.x+Resublue.w/2,Resublue.y+Resublue.h/2+1,0xf800);
  89.                                 LCD_Fillblue(Resublue.x+Resublue.w/2,Resublue.y-Resublue.h/2,Resublue.x+Resublue.w/2+1,Resublue.y+Resublue.h/2,0xf800);
  90.                                 LCD_Fillblue(Resublue.x-2,Resublue.y-2,Resublue.x+2,Resublue.y+2,0xf800);               
  91.                                  // LED1=!LED1;
  92.                                   b0=Resublue.x;
  93.                                   b1=Resublue.y;
  94.                         }                                       
  95.                  ov_sta=0;                                        //清零幀中斷標記
  96.                 ov_frame++;
  97.                 LCD_Scan_Dir(DFT_SCAN_DIR);        //恢復默認掃描方向
  98.         }
  99. }           


  100. int main(void)
  101. {         

  102.         u8 lightmode=0,saturation=2,contrast=2;
  103.         u8 effect=0;         
  104.          u8 i=0;            
  105.         u8 msgbuf[15];                                //消息緩存區
  106.         u8 tm=0;

  107.         delay_init();                     //延時函數初始化         
  108.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置中斷優先級分組為組2:2位搶占優先級,2位響應優先級
  109.         uart_init(115200);                 //串口初始化為 115200
  110.          usmart_dev.init(72);                //初始化USMART               
  111.          LED_Init();                                          //初始化與LED連接的硬件接口
  112.         KEY_Init();                                        //初始化按鍵
  113.         LCD_Init();                                           //初始化LCD  
  114.         TPAD_Init(6);                                //觸摸按鍵初始化
  115.          POINT_COLOR=RED;                        //設置字體為紅色
  116.         LCD_ShowString(30,50,200,16,16,"ELITE STM32F103 ^_^");        
  117.   LCD_ShowString(30,210,200,16,16,"OV7670 Init...");         
  118.         while(OV7670_Init())//初始化OV7670
  119.         {
  120.                 LCD_ShowString(30,210,200,16,16,"OV7670 Error!!");
  121.                 delay_ms(200);
  122.             LCD_Fill(30,210,239,246,WHITE);
  123.                 delay_ms(200);
  124.         }
  125.          LCD_ShowString(30,210,200,16,16,"OV7670 Init OK");
  126.         delay_ms(1500);                    
  127.         OV7670_Light_Mode(lightmode);
  128.         OV7670_Color_Saturation(saturation);
  129.         OV7670_Contrast(contrast);
  130.          OV7670_Special_Effects(effect);         
  131.         
  132.         TIM6_Int_Init(10000,7199);                        //10Khz計數頻率,1秒鐘中斷                                                                          
  133.         EXTI8_Init();                                                //使能定時器捕獲
  134.         OV7670_Window_Set(12,176,240,320);        //設置窗口         
  135.           OV7670_CS=0;                        
  136.         LCD_Clear(BLACK);                                                         
  137.          while(1)
  138.         {        
  139.          
  140.                 camera_refresh();//更新顯示
  141.                  if(tm)
  142.                 {
  143.                         LCD_ShowString((lcddev.width-240)/2+30,(lcddev.height-320)/2+60,200,16,16,msgbuf);
  144.                         tm--;
  145.                 }
  146.                 i++;
  147.                 if(i==15)//DS0閃爍.
  148.                 {
  149.                         i=0;
  150.                         LED0=!LED0;
  151.                  }
  152.         }           
  153. }

復制代碼

所有資料51hei提供下載:
識別紅綠藍并鎖定.rar (392.16 KB, 下載次數: 156)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏8 分享淘帖 頂2 踩
回復

使用道具 舉報

沙發
ID:221722 發表于 2017-10-15 11:15 | 只看該作者
感謝樓主分享
回復

使用道具 舉報

板凳
ID:288639 發表于 2018-3-7 12:42 | 只看該作者
感謝樓主分享
回復

使用道具 舉報

地板
ID:159774 發表于 2018-5-3 10:53 | 只看該作者
感謝樓主分享
回復

使用道具 舉報

5#
ID:322777 發表于 2018-5-5 14:31 | 只看該作者
謝謝樓主分享
回復

使用道具 舉報

6#
ID:319344 發表于 2018-5-6 11:08 | 只看該作者
在正點原子OV7670的基礎上做了一些更改,去掉了按鍵相關部分,main.c的更新顯示函數,在照片更新后進行判斷,追蹤顏色,然后那一塊兒就被紅或綠或藍圍了一個框,中間還有一個點。屏幕你用的是7寸屏吧?圖片是640*480的,真是貧窮限制了我的想象,不過你設置的顯示窗口是320*240,我不太理解
內部的那些函數還沒看很懂,不過還是學到了些東西,函數的參數&,然后就可以將其值返回,之后可以直接使用,很有用。
可能是我能力還有所欠缺吧,看得很慢,而且因為參數多,注釋少,現在還是云里霧里,等我完全看懂后,添加上注釋發一份吧,方便大家理解
回復

使用道具 舉報

7#
ID:138852 發表于 2018-5-14 17:23 | 只看該作者
樓主看懂了嗎,有沒有注釋版,求分享
回復

使用道具 舉報

8#
ID:308469 發表于 2018-6-7 23:03 | 只看該作者
wenzedong 發表于 2018-5-6 11:08
在正點原子OV7670的基礎上做了一些更改,去掉了按鍵相關部分,main.c的更新顯示函數,在照片更新后進行判斷 ...

看懂了嗎?能解釋解釋?
回復

使用道具 舉報

9#
ID:267330 發表于 2019-2-26 18:38 | 只看該作者
感謝樓主分享
回復

使用道具 舉報

10#
ID:267330 發表于 2019-2-28 17:52 | 只看該作者
看懂了嗎?能解釋解釋?
回復

使用道具 舉報

11#
ID:267330 發表于 2019-3-5 16:00 | 只看該作者
謝謝樓主分享,正在學習
回復

使用道具 舉報

12#
ID:138247 發表于 2019-5-2 15:28 | 只看該作者

謝謝樓主分享。。
回復

使用道具 舉報

13#
ID:199471 發表于 2019-6-14 09:20 | 只看該作者
謝謝樓主,好東西啊
回復

使用道具 舉報

14#
ID:411625 發表于 2019-8-2 20:09 | 只看該作者

感謝樓主分享
回復

使用道具 舉報

15#
ID:612668 發表于 2019-10-8 16:23 | 只看該作者
感謝樓主分享感謝樓主分享感謝樓主分享
回復

使用道具 舉報

16#
ID:620995 發表于 2019-10-9 11:39 | 只看該作者
感謝樓主分享
回復

使用道具 舉報

17#
ID:641287 發表于 2019-12-5 10:08 | 只看該作者

你下載這個程序代碼可以直接打開工程嗎,還是自己建一個
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产成人免费在线观看 | 日本精品视频在线观看 | 999视频在线播放 | 午夜专区 | 色999视频| 日韩精品一区二区三区中文在线 | 亚洲在线一区 | 国产剧情一区二区三区 | 国产日韩免费视频 | 一区二区三区四区毛片 | 美女艹b | 国产黄色大片网站 | 成人三级视频 | 3级毛片 | 成人精品免费视频 | 国产成人精品一区二区三 | 青青久久| 国产精久久久 | 国产精品久久久久久久久图文区 | 久久久久久成人 | 亚洲激情在线视频 | 国产精久久久久久久妇剪断 | 欧美久久综合 | 色婷婷av一区二区三区软件 | 国产精品免费在线 | 午夜免费av | 亚洲成人国产 | 国产乱码久久久久久一区二区 | 午夜精品一区二区三区在线观看 | 中文字幕亚洲欧美日韩在线不卡 | 天天躁日日躁aaaa视频 | 精品一区国产 | 久久久五月天 | 九九亚洲精品 | 久久精品二区 | 欧美日日 | 国产成人综合一区二区三区 | 91极品欧美视频 | 黄色一级毛片 | 精品一区在线 | 99久久久久 |