找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2522|回复: 0
收起左侧

飞思卡尔小车摄像头组图像识别程序

[复制链接]
ID:446814 发表于 2018-12-15 16:48 | 显示全部楼层 |阅读模式
包含图像二值化

单片机源程序如下:
  1. /*!
  2. *     COPYRIGHT NOTICE
  3. *     Copyright (c) 2013,山外科技

  4. *
  5. *     除注明出处外,以下所有内容版权均属山外科技所有,未经允许,不得用于商业用途,
  6. *     修改内容时必须保留山外科技的版权声明。
  7. *
  8. * @file       main.c
  9. * @brief      山外K60 UD版平台主程序
  10. * @author     山外科技
  11. * @version    v6.0
  12. * @date       2016-09-25
  13. */
  14. #include "include.h"
  15. #include "motor.h"
  16. #include "camera.h"
  17. #include "servo.h"
  18. #include "image_process.h"
  19. #include "menu.h"
  20. #include "flash.h"
  21. #include "ultrasonic.h"
  22. #include "switch.h"
  23. #include "bluetooth.h"
  24. #include "isr.h"
  25. uint8 cnt;



  26. #if defined CAR_1

  27. #define VSYNC_  PTD17
  28. #define HREF_   PTD16
  29. #define PCLK_   PTD18

  30. #endif
  31. /*
  32. #if defined CAR_2

  33. #define VSYNC_  PTC17 //PTD14
  34. #define HREF_   PTC16 //PTD13
  35. #define PCLK_   PTC18 //PTD12

  36. #endif
  37. */
  38. volatile Image gImage;//(60,10)

  39. //! 初始化摄像头
  40. inline static void CameraInit()
  41. {
  42.     IICWriteGpio_inintOV();//初始化设置SCCB引脚
  43.     while (ov7725_probe() == 0)//初始化寄存器
  44.         ;
  45.     ov7725_set_image_size(IMAGE_SIZE);//设置图像大小

  46.     CameraSetImageBuffer(gImage);
  47.     CameraInterruptInit();//中断初始化
  48. }

  49. //! 拨码开关的值
  50. volatile float switch_val = 0;

  51. typedef void (*func_t)(void);
  52. volatile
  53. float k, b;
  54. float SpeedDiffCoeff2(float servoduty)
  55. {
  56.     return k / 1000 * fabsf(servoduty) + b;
  57. }

  58. void PortEHandler(void)
  59. {
  60.     PORT_FUNC(E, 27, nrf_handler);
  61. }
  62. void main()
  63. {
  64.     SwitchInit();
  65.     switch_val = GetSwitchValue();
  66.    
  67.     led_init(LED0);
  68.     led_init(LED1);
  69.     led_init(LED2);
  70.     led_init(LED3);
  71. //    switch ((int)switch_val)
  72. //    {
  73. //    case 0:
  74. //        break;
  75. //    case 1:
  76. //        ((func_t)(80 * 0x400 + 0x411))();
  77. //        break;
  78. //    case 2:
  79. //        ((func_t)(150 * 0x400 + 0x411))();
  80. //        break;
  81. //    default:
  82. //        break;
  83. //    }
  84.    
  85. //    while(!nrf_init())                  //初始化NRF24L01+ ,等待初始化成功为止
  86. //    {
  87. //        led(LED0, LED_ON);
  88. //    }
  89.     led(LED0, LED_OFF);
  90.     set_vector_handler(PORTE_VECTORn, PortEHandler);
  91.     NVIC_EnableIRQ(PORTE_IRQn);

  92.     led(LED0, LED_OFF);
  93.     led(LED1, LED_OFF);
  94.     led(LED2, LED_OFF);
  95.     led(LED3, LED_OFF);
  96.     //LoadFlashData(switch_val);
  97.     SpeedCountInit();//编码器速度
  98.     OLED_Init();
  99.     CameraInit();
  100.     ServoInit();
  101.     MotorInit();
  102.     MenuInterruptInit();
  103.    
  104.   //  BluetoothInit();
  105.     enable_irq(DMA4_IRQn);
  106.    
  107.     CameraGetImage(gImage);
  108.    
  109.     for (;;)
  110.     {
  111.         CameraWait();
  112.         ExtractArray(imgbuff, (uint8_t const (*)[10])gImage);//得到bool型(60,80)型数组imgbuff
  113.         CameraGetImage(gImage);
  114.         ImageProcess(imgbuff);//图像处理




  115.                
  116.         //SpeedControl();

  117. //if(cnt==0)
  118. //        roundabout0();
  119. //if(cnt==1)
  120. //        roundabout1();
  121. //if(cnt==2)
  122.         //roundabout2();



  123.                
  124.         ServoControl();
  125.         motor_run();
  126.         if (gMenuQueryImage)//菜单oled??
  127.         {
  128.                 memcpy(gOledImageBuffer, gImage, DATALINE * DATACOUNT);
  129.                 gMenuQueryImage = 0;
  130.         }
  131.          
  132.       

  133. #if 1
  134.         //BluetoothSend();
  135. #else
  136.         /* pid debugging code */
  137.         int16_t iSpeedL = speed_l;
  138.         int16_t iSpeedR = speed_r;
  139.         
  140.         uart_putchar(UART0, 0x03);
  141.         uart_putchar(UART0, 0xFC);
  142.         uart_putbuff(UART0, (void *)&iSpeedL, sizeof iSpeedL);
  143.         uart_putbuff(UART0, (void *)&iSpeedR, sizeof iSpeedR);
  144.         uart_putchar(UART0, 0xFC);
  145.         uart_putchar(UART0, 0x03);
  146. #endif
  147.     }
  148. }
复制代码

所有资料51hei提供下载:
可跑1.1.7z (1013.65 KB, 下载次数: 65)
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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