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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

自己改的代碼,stm32,ov7670識別二值化并識別黑色物體,串口返回坐標值

  [復制鏈接]
跳轉到指定樓層
樓主
ID:320701 發表于 2018-7-18 15:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
自己網上找的代碼,根據要求修改可二值化,識別黑色物體,用紅色框框框起來,串口返回坐標值

單片機源程序如下:
  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. const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"};                                                        //5種光照模式            
  15. const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"};        //7種特效
  16. extern u8 ov_sta;        //在exit.c里 面定義
  17. extern u8 ov_frame;        //在timer.c里面定義
  18. u16 r0,r1;
  19. u16 g0,g1;
  20. u16 b0,b1;
  21.         RESULT Resured;//判定為的目標條件
  22.         RESULT Resugreen;
  23.         RESULT Resublue;
  24.        

  25. //更新LCD顯示
  26. void camera_refresh(void)//讀取FIFO里面的數據
  27. {
  28.         u32 j;
  29.         u16 color;       
  30.   u16  k;       

  31. //  TARGET_CONDI Conditionred={160,160,0,0,240,240,30,30,320,240};        //   API參數  hsl的閾值,識別時用的
  32.     TARGET_CONDI Conditiongreen={0,240,0,240,0,50,30,30,320,240};                //黑色1  API參數  hls的閾值,識別時用的
  33.    
  34.         if(ov_sta)//有幀中斷更新?
  35.         {
  36.                 LCD_Scan_Dir(U2D_L2R);                //從上到下,從左到右  
  37.         if(lcddev.id==0X1963)LCD_Set_Window((lcddev.width-240)/2,(lcddev.height-320)/2,960,640);//將顯示區域設置到屏幕中央
  38.                  else if(lcddev.id==0X5510||lcddev.id==0X5310)LCD_Set_Window(0,0,320,240);//將顯示區域設置到屏幕中央
  39.                 LCD_WriteRAM_Prepare();     //開始寫入GRAM       
  40.                  
  41.                 OV7670_RRST=0;                                //開始復位讀指針
  42.                 OV7670_RCK_L;
  43.                 OV7670_RCK_H;
  44.                 OV7670_RCK_L;
  45.                 OV7670_RRST=1;                                //復位讀指針結束
  46.                 OV7670_RCK_H;
  47.                 for(j=0;j<76800;j++)
  48.                 {
  49.                         OV7670_RCK_L;
  50.                         color=GPIOC->IDR&0XFF;        //讀數據
  51.                         OV7670_RCK_H;
  52.                         color<<=8;  
  53.                         OV7670_RCK_L;
  54.                         color|=GPIOC->IDR&0XFF;        //讀數據
  55.                         OV7670_RCK_H;
  56.                         k=color>>11;//rrrrrggggggbbbb       
  57.                         if(k>=0x0008)
  58.                         {
  59.                                 color=0xffff;//全白
  60.                         }
  61.                         else
  62.                         {
  63.                                 color=0x0000;//全黑
  64.                         }       
  65.                         LCD->LCD_RAM=color;                          
  66.                 }  
  67.        
  68.                         if(Trace1(&Conditiongreen,&Resugreen) )                      //API
  69.                         {               
  70.                                 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
  71.                                 LCD_Fillgreen(Resugreen.x-Resugreen.w/2,Resugreen.y-Resugreen.h/2,Resugreen.x-Resugreen.w/2+1,Resugreen.y+Resugreen.h/2,0xf800);
  72.                                 LCD_Fillgreen(Resugreen.x-Resugreen.w/2,Resugreen.y+Resugreen.h/2,Resugreen.x+Resugreen.w/2,Resugreen.y+Resugreen.h/2+1,0xf800);
  73.                                 LCD_Fillgreen(Resugreen.x+Resugreen.w/2,Resugreen.y-Resugreen.h/2,Resugreen.x+Resugreen.w/2+1,Resugreen.y+Resugreen.h/2,0xf800);
  74.                                 LCD_Fillgreen(Resugreen.x-2,Resugreen.y-2,Resugreen.x+2,Resugreen.y+2,0xf800);               
  75.                                  // LED1=!LED1;
  76.                                   g0=Resugreen.x;
  77.                                   g1=Resugreen.y;
  78.                         }       
  79.                 ov_sta=0;                                        //清零幀中斷標記
  80.                 ov_frame++;
  81.                 LCD_Scan_Dir(DFT_SCAN_DIR);        //恢復默認掃描方向
  82.         }
  83. }          


  84. int main(void)
  85. {         
  86.         u8 key;
  87.         u8 lightmode=0,saturation=2,brightness=2,contrast=2;
  88.         u8 effect=6;         
  89.         u8 i=0;            
  90.         u8 msgbuf[15];                                //消息緩存區
  91.         u8 tm=0;
  92.          
  93.         delay_init();                     //延時函數初始化          
  94.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置中斷優先級分組為組2:2位搶占優先級,2位響應優先級
  95.         uart_init(115200);                 //串口初始化為 115200
  96.         usmart_dev.init(72);                //初始化USMART               
  97.         LED_Init();                                          //初始化與LED連接的硬件接口
  98.         KEY_Init();                                        //初始化按鍵
  99.         LCD_Init();                                           //初始化LCD  
  100.         TPAD_Init(6);                                //觸摸按鍵初始化
  101.         POINT_COLOR=RED;                        //設置字體為紅色
  102.         LCD_ShowString(30,50,200,16,16,"WarShip STM32");       
  103.         LCD_ShowString(30,70,200,16,16,"OV7670 TEST");       
  104.         LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
  105.         LCD_ShowString(30,110,200,16,16,"2015/1/18");
  106.         LCD_ShowString(30,130,200,16,16,"KEY0:Light Mode");
  107.         LCD_ShowString(30,150,200,16,16,"KEY1:Saturation");
  108.         LCD_ShowString(30,170,200,16,16,"KEY2:Brightness");
  109.         LCD_ShowString(30,190,200,16,16,"KEY_UP:Contrast");
  110.         LCD_ShowString(30,210,200,16,16,"TPAD:Effects");         
  111.   LCD_ShowString(30,230,200,16,16,"OV7670 Init...");          
  112.         while(OV7670_Init())//初始化OV7670
  113.         {
  114.                 LCD_ShowString(30,230,200,16,16,"OV7670 Error!!");
  115.                 delay_ms(200);
  116.             LCD_Fill(30,230,239,246,WHITE);
  117.                 delay_ms(200);
  118.         }
  119.         LCD_ShowString(30,230,200,16,16,"OV7670 Init OK");
  120.         delay_ms(1500);                   
  121.         OV7670_Light_Mode(lightmode);
  122.         OV7670_Color_Saturation(saturation);
  123.         OV7670_Brightness(brightness);
  124.         OV7670_Contrast(contrast);
  125.         OV7670_Special_Effects(effect);         //是特效
  126.         TIM6_Int_Init(10000,7199);                        //10Khz計數頻率,1秒鐘中斷                                                                          
  127.         EXTI8_Init();                                                        //使能定時苃 n韃痘?
  128. //        OV7670_Window_Set(12,176,240,320);        //設置窗口       
  129.   OV7670_config_window(12,176,240,320);
  130.   OV7670_CS=0;                                       
  131.         LCD_Clear(BLACK);
  132.         while(1)
  133.         {       
  134.                 key=KEY_Scan(0);//不支持連按
  135.                 if(key)
  136.                 {
  137.                         tm=20;
  138.                         switch(key)
  139.                         {                                    
  140.                                 case KEY0_PRES:        //燈光模式Light Mode
  141.                                         lightmode++;
  142.                                         if(lightmode>4)lightmode=0;
  143.                                         OV7670_Light_Mode(lightmode);
  144.                                         sprintf((char*)msgbuf,"%s",LMODE_TBL[lightmode]);
  145.                                         break;
  146.                                 case KEY1_PRES:        //飽和度Saturation
  147.                                         saturation++;
  148.                                         if(saturation>4)saturation=0;
  149.                                         OV7670_Color_Saturation(saturation);
  150.                                         sprintf((char*)msgbuf,"Saturation:%d",(signed char)saturation-2);
  151.                                         break;
  152.                                 case KEY2_PRES:        //亮度Brightness                                 
  153.                                         brightness++;
  154.                                         if(brightness>4)brightness=0;
  155.                                         OV7670_Brightness(brightness);
  156.                                         sprintf((char*)msgbuf,"Brightness:%d",(signed char)brightness-2);
  157.                                         break;
  158.                                 case WKUP_PRES:        //對比度Contrast                            
  159.                                         contrast++;
  160.                                         if(contrast>4)contrast=0;
  161.                                         OV7670_Contrast(contrast);
  162.                                         sprintf((char*)msgbuf,"Contrast:%d",(signed char)contrast-2);
  163.                                         break;
  164.                         }
  165.                 }         
  166.                 if(TPAD_Scan(0))//檢測到觸摸按鍵
  167.                 {
  168.                         effect++;
  169.                         if(effect>6)effect=0;
  170.                         OV7670_Special_Effects(effect);//設置特效
  171.                          sprintf((char*)msgbuf,"%s",EFFECTS_TBL[effect]);
  172.                         tm=20;
  173.                 }
  174.                 camera_refresh();//更新顯示
  175.                
  176.                 if(tm)
  177.                 {
  178.                         LCD_ShowString((lcddev.width-240)/2+30,(lcddev.height-320)/2+60,200,16,16,msgbuf);
  179.                         tm--;
  180.                 }
  181.                 i++;
  182.                 if(i==15)//DS0閃爍.
  183.                 {
  184.                         i=0;
  185.                         LED0=!LED0;
  186.                         printf("x坐標=%d\r\n",g0);
  187.                         printf("y坐標=%d\r\n",g1);
  188.                 }
  189.         }          
  190. }
復制代碼

所有資料51hei提供下載:
實驗35 攝像頭實驗.rar (394.47 KB, 下載次數: 177)


評分

參與人數 2黑幣 +55 收起 理由
Mr丶朋 + 5 共享資料的黑幣獎勵!
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

沙發
ID:341045 發表于 2018-7-19 12:01 | 只看該作者
收藏備用,謝謝分享
回復

使用道具 舉報

板凳
ID:374851 發表于 2018-7-19 14:47 | 只看該作者
學習了
回復

使用道具 舉報

地板
ID:383374 發表于 2018-11-29 13:58 | 只看該作者
不錯的例程
回復

使用道具 舉報

5#
ID:511417 發表于 2019-4-13 18:58 | 只看該作者
下載試試
回復

使用道具 舉報

6#
ID:524469 發表于 2019-4-29 18:58 | 只看該作者
試試看
回復

使用道具 舉報

7#
ID:466908 發表于 2019-5-1 10:18 | 只看該作者
請問樓主的ov7670有沒有帶FIFO
回復

使用道具 舉報

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

謝謝樓主分享。。。
回復

使用道具 舉報

9#
ID:537523 發表于 2019-5-13 23:10 | 只看該作者
這個用ov7725 都需要改哪些程序
回復

使用道具 舉報

10#
ID:28208 發表于 2019-5-19 13:37 | 只看該作者
挺厲害的!
回復

使用道具 舉報

11#
ID:542507 發表于 2019-5-20 02:17 | 只看該作者
前輩你這個很厲害,比如我電腦屏幕有5種顏色,分別是1 2 3 4 5,假如攝像頭識別到2號顏色 就反饋回一個2號的信息,這個信息到我的舵機控制器里  我控制器再實現我代碼寫好的動作 可以實現嗎?
回復

使用道具 舉報

12#
ID:352976 發表于 2019-5-23 19:36 | 只看該作者
為什么燒錄到 單片機上只有白框   沒有圖像啊  
回復

使用道具 舉報

13#
ID:572726 發表于 2019-7-31 16:47 | 只看該作者
其他顏色怎么改呢
回復

使用道具 舉報

14#
ID:587606 發表于 2019-8-5 15:27 | 只看該作者
if(Trace1(&Conditiongreen,&Resugreen) )                      //API
                        {               
                                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
                                LCD_Fillgreen(Resugreen.x-Resugreen.w/2,Resugreen.y-Resugreen.h/2,Resugreen.x-Resugreen.w/2+1,Resugreen.y+Resugreen.h/2,0xf800);
                                LCD_Fillgreen(Resugreen.x-Resugreen.w/2,Resugreen.y+Resugreen.h/2,Resugreen.x+Resugreen.w/2,Resugreen.y+Resugreen.h/2+1,0xf800);
                                LCD_Fillgreen(Resugreen.x+Resugreen.w/2,Resugreen.y-Resugreen.h/2,Resugreen.x+Resugreen.w/2+1,Resugreen.y+Resugreen.h/2,0xf800);
                                LCD_Fillgreen(Resugreen.x-2,Resugreen.y-2,Resugreen.x+2,Resugreen.y+2,0xf800);               
                                 // LED1=!LED1;
                                  g0=Resugreen.x;
                                  g1=Resugreen.y;
                        }        

能不能請問下這段代碼的含義?
回復

使用道具 舉報

15#
ID:542954 發表于 2019-8-11 17:03 | 只看該作者
菜雞一只314159 發表于 2019-5-1 10:18
請問樓主的ov7670有沒有帶FIFO

你看程序里有寫讀取FIFO的函數 應該是帶的
回復

使用道具 舉報

16#
ID:585455 發表于 2019-8-18 23:29 | 只看該作者
只做過arducam ov2640
感謝分享ov7670
回復

使用道具 舉報

17#
ID:592325 發表于 2019-9-10 14:57 | 只看該作者
能問下是用那個芯片嗎
回復

使用道具 舉報

18#
ID:612668 發表于 2019-10-8 16:19 | 只看該作者
收藏備用,謝謝分享
回復

使用道具 舉報

19#
ID:320701 發表于 2020-5-9 15:46 | 只看該作者
zhang@# 發表于 2019-9-10 14:57
能問下是用那個芯片嗎

STM32F103
回復

使用道具 舉報

20#
ID:625538 發表于 2020-7-20 17:01 | 只看該作者
anzhii 發表于 2019-5-13 23:10
這個用ov7725 都需要改哪些程序

我也是OV7725 請問能直接用嗎
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 高清视频一区二区三区 | 自拍偷拍亚洲欧美 | 日本久久久久久 | 久久久精品网 | 亚洲视频免费在线看 | 日皮视频免费 | 成人在线精品视频 | 国产91久久精品一区二区 | 国产精品久久久久久久久久免费看 | 亚洲a视频 | 国产黄色在线观看 | 爱爱小视频 | 亚洲3级 | 免费国产视频 | 精品一区久久 | 欧美中文字幕一区二区三区亚洲 | 一级片在线播放 | 午夜免费视频 | 黄篇网址| 99精品视频在线观看 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 欧美黑人一区二区三区 | 91九色麻豆 | 天堂精品视频 | 四虎永久免费地址 | japan25hdxxxx日本| 最新国产精品视频 | 日本成人福利 | caoporn国产精品免费公开 | 久久久久国产精品 | 成人av播放 | 日本三级视频 | 欧美精品在线免费 | 国产精品久久精品 | 国产精品久久久久久久久久久久冷 | 亚洲在线成人 | 91久久精品| 午夜成人免费视频 | 一区二区三区在线免费看 | 亚洲成人精品一区 | 国产.com |