摄像头小车

所属分类:单片机开发
开发工具:C/C++
文件大小:5097KB
下载次数:2
上传日期:2020-05-17 19:26:42
上 传 者stark1307
说明:  基于STM32F103,keil5平台,使用正点原子OV7725摄像头,对采取到的图像灰度二值化,获取黑线位置控制电机转向,能够较为平稳控制,对于1,m/s以内的速度可以达到20fps不离线
(Based on STM32F103, keil5 platform, using the positive point atom ov7725 camera, binarization of the gray level of the image taken, obtaining the black line position to control the motor steering, which can be more stable control, and the speed within 1, M / s can reach 20fps without offline)

文件列表:
摄像头小车 (0, 2019-05-23)
摄像头小车\CORE (0, 2019-05-23)
摄像头小车\CORE\core_cm3.c (17273, 2017-11-03)
摄像头小车\CORE\core_cm3.h (85714, 2017-11-03)
摄像头小车\CORE\startup_stm32f10x_hd.s (15632, 2017-11-03)
摄像头小车\HARDWARE (0, 2019-05-23)
摄像头小车\HARDWARE\BEEP (0, 2019-05-23)
摄像头小车\HARDWARE\BEEP\beep.c (756, 2017-11-03)
摄像头小车\HARDWARE\BEEP\beep.h (696, 2017-11-03)
摄像头小车\HARDWARE\EXTI (0, 2019-05-23)
摄像头小车\HARDWARE\EXTI\exti.c (2837, 2018-08-28)
摄像头小车\HARDWARE\EXTI\exti.h (826, 2017-11-03)
摄像头小车\HARDWARE\KEY (0, 2019-05-23)
摄像头小车\HARDWARE\KEY\key.c (2357, 2018-08-28)
摄像头小车\HARDWARE\KEY\key.h (1059, 2017-11-03)
摄像头小车\HARDWARE\LCD (0, 2019-07-25)
摄像头小车\HARDWARE\LCD\font.h (35016, 2017-11-03)
摄像头小车\HARDWARE\LCD\ILI93xx.c (83165, 2017-11-03)
摄像头小车\HARDWARE\LCD\lcd.c (85323, 2019-07-25)
摄像头小车\HARDWARE\LCD\lcd.h (7561, 2017-11-03)
摄像头小车\HARDWARE\LED (0, 2019-05-23)
摄像头小车\HARDWARE\LED\led.c (1304, 2018-08-26)
摄像头小车\HARDWARE\LED\led.h (638, 2017-11-03)
摄像头小车\HARDWARE\OV7670 (0, 2019-05-23)
摄像头小车\HARDWARE\OV7670\ov7670.c (6819, 2017-11-03)
摄像头小车\HARDWARE\OV7670\ov7670.h (1273, 2017-11-03)
摄像头小车\HARDWARE\OV7670\ov7670cfg.h (4336, 2017-11-03)
摄像头小车\HARDWARE\OV7670\sccb.c (3699, 2017-11-03)
摄像头小车\HARDWARE\OV7670\sccb.h (1056, 2017-11-03)
摄像头小车\HARDWARE\OV7725 (0, 2019-05-23)
摄像头小车\HARDWARE\OV7725\ov7725.c (7844, 2017-11-12)
摄像头小车\HARDWARE\OV7725\ov7725.h (1268, 2017-11-03)
摄像头小车\HARDWARE\OV7725\ov7725config.h (5873, 2017-11-09)
摄像头小车\HARDWARE\OV7725\sccb.c (3699, 2016-11-09)
摄像头小车\HARDWARE\OV7725\sccb.h (1056, 2016-11-09)
摄像头小车\HARDWARE\TIMER (0, 2019-05-23)
摄像头小车\HARDWARE\TIMER\timer.c (4066, 2018-09-05)
摄像头小车\HARDWARE\TIMER\timer.h (1050, 2018-09-05)
摄像头小车\HARDWARE\TPAD (0, 2019-05-23)
摄像头小车\HARDWARE\TPAD\tpad.c (4735, 2017-11-03)
... ...

#include "led.h" #include "delay.h" #include "key.h" #include "sys.h" #include "lcd.h" #include "usart.h" #include "string.h" #include "ov7725.h" #include "tpad.h" #include "timer.h" #include "exti.h" #include "stdio.h" #define OV7725_WINDOW_WIDTH 320 #define OV7725_WINDOW_HEIGHT 240 void OV7725_refresh(void); extern u8 ov_sta; //在exit.c里 面定义 int inc; u8 key; int main(void) { u8 lightmode=0; s8 saturation=0,brightness=0,contrast=2; delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(9600); //串口初始化为 115200 LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 LCD_Init(); //初始化LCD TIM34_PWM_Init(720,999); //1000Hz PWM POINT_COLOR=BLUE; //设置字体为红色 LCD_ShowString(30,150,200,16,16,"OV7725 Init..."); TIM6_Int_Init(10000,7199); while(1) //初始化OV7725 { if(OV7725_Init()==0) { OV7725_Window_Set(OV7725_WINDOW_WIDTH,OV7725_WINDOW_HEIGHT,1);//VGA模式输出 OV7725_Light_Mode(lightmode); OV7725_Color_Saturation(saturation); OV7725_Brightness(brightness); OV7725_Contrast(contrast); OV7725_Special_Effects(0);//黑白 OV7725_CS=0; break; } } TIM6_Int_Init(10000,7199); //10Khz计数频率,1秒钟中断 EXTI8_Init(); //使能外部中断8,捕获帧中断 LCD_Clear(BLACK); LCD_ShowString(30,150,200,16,16,"cnt: ,v: cm/s"); LCD_ShowString(30,180,200,16,16,"LPWM: ,RPWM: "); LCD_ShowString(30,210,200,16,16,"Frame: ,xup: "); while(1) { if(PFin(3)==1) { OV7725_refresh(); //更新显示 } else { TIM3->CCR2 = 0; TIM3->CCR1 = 0; while(!PFin(3)); } } } extern u8 ov_frame; u8 xup; u8 llast; u16 Left_PWM,Right_PWM; void OV7725_refresh(void) { u16 up; static u8 last; u8 upcnt; int dev; volatile unsigned short i,j; u16 color,red,green,blue,gray; if(ov_sta)//有帧中断更新 { OV7725_RRST=0; //开始复位读指针 OV7725_RCK_L; OV7725_RCK_H; OV7725_RCK_L; OV7725_RRST=1; //复位读指针结束 OV7725_RCK_H; for(i=0;i<240;i++) //x { for(j=0;j<320;j++) //y { if(j!=130) { OV7725_RCK_L; OV7725_RCK_H; OV7725_RCK_L; OV7725_RCK_H; } else { OV7725_RCK_L; color=GPIOC->IDR&0XFF; //读数据 OV7725_RCK_H; color<<=8; OV7725_RCK_L; color|=GPIOC->IDR&0XFF; //读数据 OV7725_RCK_H; red = (color & 0xF800) >> 8; green = (color & 0x07E0) >> 3; blue = (color & 0x001F) << 3; gray =(red*76+green*150+blue*29)>>8; if(gray<80) { up+=i; upcnt++; LCD_Fast_DrawPoint(i,j,0xffff); } else LCD_Fast_DrawPoint(i,j,0); } } } ov_sta=0; ov_frame++; xup=up/upcnt; dev=xup-120; last=xup; llast=last; if(upcnt>=100||xup==0) { TIM3->CCR2 =0; TIM3->CCR1 = 0; return; } if(dev>=50||dev<=-50) //50~100 { if(dev>=50) { Left_PWM=720; Right_PWM=300; } else { Left_PWM=300; Right_PWM=720; } } else if(dev>=20||dev<=-20) //20~50 { if(dev>=20) { Left_PWM=650; Right_PWM=400; } else { Left_PWM=400; Right_PWM=650; } } else //0~20 { if(dev>8||dev<-8) { if(dev>5) { Left_PWM=650; Right_PWM=500; } else { Left_PWM=500; Right_PWM=650; } } else { Right_PWM=500; Left_PWM=Right_PWM-(dev<<4); } } if(PFin(3)==0) { Left_PWM=0; Right_PWM=0; } TIM3->CCR2 =Right_PWM;//l TIM3->CCR1 = Left_PWM;//r LCD_ShowNum(70,180,Right_PWM,3,16); LCD_ShowNum(150,180,Left_PWM,3,16); LCD_ShowNum(142,210,xup,3,16); } }

近期下载者

相关文件


收藏者