找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3468|回复: 1
打印 上一主题 下一主题
收起左侧

OV7670图像采集处理+定位黑线的stm32源码

[复制链接]
跳转到指定楼层
楼主
ID:329637 发表于 2018-5-14 15:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
单片机源程序如下:
  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 "dma.h"
  14. #include "Pic_Process.h"



  15. const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"};                                                        //5种光照模式            
  16. const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"};        //7种特效
  17. extern u8 ov_sta;           //在exit.c里 面定义
  18. extern u8 ov_frame;          //在timer.c里面定义                 
  19. //更新LCD显示
  20. //#define SEND_BUF_SIZE 76802
  21. //u8 SendBuff[19201]={0xff};                //发送数据缓冲区

  22. //#define Send_Uart
  23. void camera_refresh(void);

  24. u8 cmd[4]={0, 255, 1, 0 };

  25. /*---图像处理需要的外部变量---*/
  26. extern u8 Pic_Buff[V][H];
  27. extern u8 Black_Line[60];
  28. extern u16 middle_dot;
  29. extern u8 Search_Cnt;    //


  30. u16 color_r;
  31. u16 color_g;
  32. u16 color_b;
  33. u16 v=0,h=0;
  34. u16 row,col;

  35. typedef struct{
  36.         u16 Cnt;
  37. }Point;

  38. Point WhitePoint;
  39. Point BlackPoint;

  40. int main(void)
  41. {         
  42.         u8 i,j;
  43.         u8 lightmode=0,saturation=2,brightness=2,contrast=2;
  44.         u8 effect=0;         
  45. //         u8 i=0;            
  46.         //u8 msgbuf[15];                                //消息缓存区
  47. //        u8 tm=0;
  48.        
  49.         delay_init();                     //延时函数初始化          
  50.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
  51.         uart_init(115200);                 //串口初始化为 115200
  52.         usmart_dev.init(72);                //初始化USMART               
  53.         LED_Init();                                          //初始化与LED连接的硬件接口
  54.         KEY_Init();                                        //初始化按键
  55.         LCD_Init();                                           //初始化LCD
  56. //        MYDMA_Config(DMA1_Channel4,(u32)&USART1->DR,(u32)SendBuff,1);//DMA1通道4,外设为串口1,存储器为SendBuff,长度SEND_BUF_SIZE.
  57. //        TPAD_Init(6);                                //触摸按键初始化
  58.         POINT_COLOR=RED;                        //设置字体为红色
  59.         LCD_ShowString(30,50,200,16,16,"WarShip STM32");       
  60.         LCD_ShowString(30,70,200,16,16,"OV7670 TEST");       
  61.         LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
  62.         LCD_ShowString(30,110,200,16,16,"2015/1/18");
  63.         LCD_ShowString(30,130,200,16,16,"KEY0:Light Mode");
  64.         LCD_ShowString(30,150,200,16,16,"KEY1:Saturation");
  65.         LCD_ShowString(30,170,200,16,16,"KEY2:Brightness");
  66.         LCD_ShowString(30,190,200,16,16,"KEY_UP:Contrast");
  67.         LCD_ShowString(30,210,200,16,16,"TPAD:Effects");         
  68.   LCD_ShowString(30,230,200,16,16,"OV7670 Init...");          
  69.         while(OV7670_Init())//初始化OV7670
  70.         {
  71.                 LCD_ShowString(30,230,200,16,16,"OV7670 Error!!");
  72.                 delay_ms(200);
  73.           LCD_Fill(30,230,239,246,WHITE);
  74.                 delay_ms(200);
  75.         }
  76.         LCD_ShowString(30,230,200,16,16,"OV7670 Init OK");
  77.         delay_ms(1500);                   
  78.         OV7670_Light_Mode(lightmode);
  79.         OV7670_Color_Saturation(saturation);
  80.         OV7670_Brightness(brightness);
  81.         OV7670_Contrast(contrast);
  82.         OV7670_Special_Effects(effect);         
  83.         TIM6_Int_Init(10000,7199);                        //10Khz计数频率,1秒钟中断                                                                          
  84.         EXTI8_Init();                                                //使能定时器捕获
  85.         OV7670_Window_Set(12,176,240,320);        //设置窗口          
  86.   OV7670_CS=0;                                       
  87.         LCD_Clear(BLACK);
  88.         while(1)
  89.         {       
  90.                
  91.                 camera_refresh();//更新显示

  92.                 Image_Binaryzation();
  93.                
  94.                 Image_Filter();
  95.                
  96.                 Get_Black_Line();       
  97.                
  98.                 Black_Line_handle();
  99.                
  100.                 printf("pos:%d-%d\r\n",middle_dot,Search_Cnt);//打印黑线中点位置和扫描到的黑线点数
  101.                 Search_Cnt=1;
  102.                 middle_dot=0;
  103. //                for(j=0;j<60;j++)
  104. //                        {
  105. //                                printf("pos:%dH%d\r\n",Black_Line[j],j);
  106. //                        }
  107.                
  108.                 #ifdef Send_Uart
  109.             USART_SendData(USART1, 0xff);//向串口1发送数据
  110.                   while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
  111.                         for(i=0;i<60;i++)         
  112.                 {
  113.                         for(j=0;j<80;j++)
  114.                         {
  115.                          USART_SendData(USART1,Pic_Buff[j][i]);//向串口1发送数据
  116.                         while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
  117.                         }
  118.                 }
  119.                 #endif
  120.         }          
  121. }
  122. /*--------读取图像程序-——----—*/
  123. void camera_refresh(void)
  124. {
  125.         //u32 j;
  126.         u16 color;
  127.         u8 YUV_U;
  128. //        u8 YUV_Y;
  129. //        u16 BlackPos;
  130.        
  131.         if(ov_sta)//有帧中断更新?
  132.         {  //u8 i;
  133.                 LCD_Scan_Dir(U2D_L2R);                //从上到下,从左到右  
  134.                 if(lcddev.id==0X1963)LCD_Set_Window((lcddev.width-240)/2,(lcddev.height-320)/2,240,320);//将显示区域设置到屏幕中央
  135.                 else if(lcddev.id==0X5510||lcddev.id==0X5310)LCD_Set_Window((lcddev.width-320)/2,(lcddev.height-240)/2,320,240);//将显示区域设置到屏幕中央
  136.                 LCD_WriteRAM_Prepare();     //开始写入GRAM       
  137.                 OV7670_RRST=0;                                //开始复位读指针
  138.                 OV7670_RCK_L;
  139.                 OV7670_RCK_H;
  140.                 OV7670_RCK_L;
  141.                 OV7670_RRST=1;                               
  142.                 OV7670_RCK_H;

  143.                 for(col=0;col<240;col++)
  144.                 {        
  145.                         if((col%4)==0)h++;
  146.                         for(row=0;row<320;row++)
  147.                         {        
  148.                                         OV7670_RCK_L;       
  149.                                         color=OV7670_DATA;        //读数据
  150.                                         OV7670_RCK_H;

  151.                                         OV7670_RCK_L;
  152.                                         YUV_U=OV7670_DATA;        //读数据
  153.                                         OV7670_RCK_H;

  154.                                 if(((col%4)==0)&&((row%4)==0))
  155.                                 {                                               
  156.                                             v++;
  157.                                                         Pic_Buff[v-1][h-1]=(u8)color;
  158.                                                        
  159.                                 }
  160.                        
  161.                                 color<<=8;
  162.                                 color_r = color&0xf800;
  163.                                 color_b = color>>11;
  164.                                 color >>=5;
  165.                                 color_g =color&0x07e0;                
  166.                                 LCD->LCD_RAM= color_r + color_g + color_b;
  167.                 }
  168.                         v=0;
  169.         }       
  170.                 h=0;
  171.                 ov_sta=0;                                        //清零帧中断标记
  172.                 ov_frame++;
  173.                 LCD_Scan_Dir(DFT_SCAN_DIR);        //恢复默认扫描方向
  174.         }
  175. }          
复制代码

所有资料51hei提供下载:
图像采集处理+定位黑线-2016-4-13.rar (394.57 KB, 下载次数: 75)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:138247 发表于 2019-5-2 15:18 | 只看该作者

谢谢楼主分享。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表