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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3262|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

stm32手寫識(shí)別源程序代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:385269 發(fā)表于 2018-8-11 15:13 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
stm32手寫識(shí)別

單片機(jī)源程序如下:
  1. #include "sys.h"
  2. #include "delay.h"
  3. #include "usart.h"
  4. #include "led.h"                           
  5. #include "lcd.h"  
  6. #include "key.h"      
  7. #include "malloc.h"
  8. #include "sdio_sdcard.h"  
  9. #include "w25qxx.h"   
  10. #include "ff.h"  
  11. #include "exfuns.h"   
  12. #include "text.h"
  13. #include "atk_ncr.h"
  14. #include "touch.h"         


  15. //最大記錄的軌跡點(diǎn)數(shù)

  16. atk_ncr_point READ_BUF[200];                                         

  17. //畫水平線
  18. //x0,y0:坐標(biāo)
  19. //len:線長度
  20. //color:顏色
  21. void gui_draw_hline(u16 x0,u16 y0,u16 len,u16 color)
  22. {
  23.         if(len==0)return;
  24.         LCD_Fill(x0,y0,x0+len-1,y0,color);        
  25. }
  26. //畫實(shí)心圓
  27. //x0,y0:坐標(biāo)
  28. //r:半徑
  29. //color:顏色
  30. void gui_fill_circle(u16 x0,u16 y0,u16 r,u16 color)
  31. {                                                                                          
  32.         u32 i;
  33.         u32 imax = ((u32)r*707)/1000+1;
  34.         u32 sqmax = (u32)r*(u32)r+(u32)r/2;
  35.         u32 x=r;
  36.         gui_draw_hline(x0-r,y0,2*r,color);
  37.         for (i=1;i<=imax;i++)
  38.         {
  39.                 if ((i*i+x*x)>sqmax)// draw lines from outside  
  40.                 {
  41.                          if (x>imax)
  42.                         {
  43.                                 gui_draw_hline (x0-i+1,y0+x,2*(i-1),color);
  44.                                 gui_draw_hline (x0-i+1,y0-x,2*(i-1),color);
  45.                         }
  46.                         x--;
  47.                 }
  48.                 // draw lines from inside (center)  
  49.                 gui_draw_hline(x0-x,y0+i,2*x,color);
  50.                 gui_draw_hline(x0-x,y0-i,2*x,color);
  51.         }
  52. }  
  53. //兩個(gè)數(shù)之差的絕對(duì)值
  54. //x1,x2:需取差值的兩個(gè)數(shù)
  55. //返回值:|x1-x2|
  56. u16 my_abs(u16 x1,u16 x2)
  57. {                        
  58.         if(x1>x2)return x1-x2;
  59.         else return x2-x1;
  60. }  
  61. //畫一條粗線
  62. //(x1,y1),(x2,y2):線條的起始坐標(biāo)
  63. //size:線條的粗細(xì)程度
  64. //color:線條的顏色
  65. void lcd_draw_bline(u16 x1, u16 y1, u16 x2, u16 y2,u8 size,u16 color)
  66. {
  67.         u16 t;
  68.         int xerr=0,yerr=0,delta_x,delta_y,distance;
  69.         int incx,incy,uRow,uCol;
  70.         if(x1<size|| x2<size||y1<size|| y2<size)return;
  71.         delta_x=x2-x1; //計(jì)算坐標(biāo)增量
  72.         delta_y=y2-y1;
  73.         uRow=x1;
  74.         uCol=y1;
  75.         if(delta_x>0)incx=1; //設(shè)置單步方向
  76.         else if(delta_x==0)incx=0;//垂直線
  77.         else {incx=-1;delta_x=-delta_x;}
  78.         if(delta_y>0)incy=1;
  79.         else if(delta_y==0)incy=0;//水平線
  80.         else{incy=-1;delta_y=-delta_y;}
  81.         if( delta_x>delta_y)distance=delta_x; //選取基本增量坐標(biāo)軸
  82.         else distance=delta_y;
  83.         for(t=0;t<=distance+1;t++ )//畫線輸出
  84.         {  
  85.                 gui_fill_circle(uRow,uCol,size,color);//畫點(diǎn)
  86.                 xerr+=delta_x ;
  87.                 yerr+=delta_y ;
  88.                 if(xerr>distance)
  89.                 {
  90.                         xerr-=distance;
  91.                         uRow+=incx;
  92.                 }
  93.                 if(yerr>distance)
  94.                 {
  95.                         yerr-=distance;
  96.                         uCol+=incy;
  97.                 }
  98.         }  
  99. }
  100. int main(void)
  101. {         
  102.          u8 i=0;                    
  103.         u8 tcnt=0;   
  104.         u8 res[10];
  105.         u8 key;                    
  106.         u16 pcnt=0;
  107.         u8 mode=4;                                        //默認(rèn)是混合模式                        
  108.          u16 lastpos[2];                                //最后一次的數(shù)據(jù)
  109.          
  110.         delay_init();                     //延時(shí)函數(shù)初始化         
  111.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置中斷優(yōu)先級(jí)分組為組2:2位搶占優(yōu)先級(jí),2位響應(yīng)優(yōu)先級(jí)
  112.         uart_init(115200);                 //串口初始化為115200
  113.          LED_Init();                                          //初始化與LED連接的硬件接口
  114.         KEY_Init();                                        //初始化按鍵
  115.         LCD_Init();                                           //初始化LCD     
  116.         W25QXX_Init();                                //初始化W25Q128
  117.         tp_dev.init();                                //初始化觸摸屏
  118.          my_mem_init(SRAMIN);                //初始化內(nèi)部內(nèi)存池
  119.         exfuns_init();                                //為fatfs相關(guān)變量申請(qǐng)內(nèi)存  
  120.          f_mount(fs[0],"0:",1);                 //掛載SD卡
  121.          f_mount(fs[1],"1:",1);                 //掛載FLASH.
  122.         alientek_ncr_init();                //初始化手寫識(shí)別
  123.         POINT_COLOR=RED;      
  124.          while(font_init())                         //檢查字庫
  125.         {            
  126.                 LCD_ShowString(30,50,200,16,16,"Font Error!");
  127.                 delay_ms(200);                                 
  128.                 LCD_Fill(30,50,240,66,WHITE);//清除顯示            
  129.         }
  130. RESTART:
  131.         Show_Str(30,10,200,16,"戰(zhàn)艦 STM32開發(fā)板",16,0);                                             
  132.         Show_Str(30,30,200,16,"手寫識(shí)別實(shí)驗(yàn)",16,0);                                             
  133.         Show_Str(30,50,200,16,"正點(diǎn)原子@ALIENTEK",16,0);                                             
  134.         Show_Str(30,70,200,16,"KEY0:MODE KEY_UP:Adjust",16,0);                           
  135.         Show_Str(30,90,200,16,"識(shí)別結(jié)果:",16,0);               
  136.         LCD_DrawRectangle(19,114,lcddev.width-20,lcddev.height-5);
  137.         POINT_COLOR=BLUE;      
  138.         Show_Str(96,207,200,16,"手寫區(qū)",16,0);         
  139.         tcnt=100;
  140.         tcnt=100;
  141.         while(1)
  142.         {
  143.                 key=KEY_Scan(0);
  144.                 if(key==WKUP_PRES&&(tp_dev.touchtype&0X80)==0)
  145.                 {
  146.                         TP_Adjust();          //屏幕校準(zhǔn)
  147.                         LCD_Clear(WHITE);
  148.                         goto RESTART;        //重新加載界面
  149.                 }
  150.                 if(key==KEY0_PRES)        
  151.                 {
  152.                         LCD_Fill(20,115,219,314,WHITE);//清除當(dāng)前顯示
  153.                         mode++;
  154.                         if(mode>4)mode=1;
  155.                         switch(mode)
  156.                         {
  157.                                 case 1:
  158.                                         Show_Str(80,207,200,16,"僅識(shí)別數(shù)字",16,0);        
  159.                                         break;                     
  160.                                 case 2:
  161.                                         Show_Str(64,207,200,16,"僅識(shí)別大寫字母",16,0);        
  162.                                         break;                     
  163.                                 case 3:
  164.                                         Show_Str(64,207,200,16,"僅識(shí)別小寫字母",16,0);        
  165.                                         break;                     
  166.                                 case 4:
  167.                                         Show_Str(88,207,200,16,"全部識(shí)別",16,0);        
  168.                                         break;         
  169.                         }
  170.                         tcnt=100;
  171.                 }                  
  172.                  tp_dev.scan(0);//掃描
  173.                  if(tp_dev.sta&TP_PRES_DOWN)//有按鍵被按下
  174.                 {                                 
  175.                         delay_ms(1);//必要的延時(shí),否則老認(rèn)為有按鍵按下.
  176.                          tcnt=0;//松開時(shí)的計(jì)數(shù)器清空                              
  177.                         if((tp_dev.x[0]<(lcddev.width-20-2)&&tp_dev.x[0]>=(20+2))&&(tp_dev.y[0]<(lcddev.height-5-2)&&tp_dev.y[0]>=(115+2)))
  178.                         {                        
  179.                                 if(lastpos[0]==0XFFFF)
  180.                                 {
  181.                                         lastpos[0]=tp_dev.x[0];
  182.                                         lastpos[1]=tp_dev.y[0];
  183.                                 }
  184.                                 lcd_draw_bline(lastpos[0],lastpos[1],tp_dev.x[0],tp_dev.y[0],2,BLUE);//畫線
  185.                                 lastpos[0]=tp_dev.x[0];
  186.                                 lastpos[1]=tp_dev.y[0];
  187.                                 if(pcnt<200)//總點(diǎn)數(shù)少于200
  188.                                 {
  189.                                         if(pcnt)
  190.                                         {
  191.                                                 if((READ_BUF[pcnt-1].y!=tp_dev.y[0])&&(READ_BUF[pcnt-1].x!=tp_dev.x[0]))//x,y不相等
  192.                                                 {
  193.                                                         READ_BUF[pcnt].x=tp_dev.x[0];
  194.                                                         READ_BUF[pcnt].y=tp_dev.y[0];
  195.                                                         pcnt++;
  196.                                                 }        
  197.                                         }else
  198.                                         {
  199.                                                 READ_BUF[pcnt].x=tp_dev.x[0];
  200.                                                 READ_BUF[pcnt].y=tp_dev.y[0];
  201.                                                 pcnt++;
  202.                                         }                  
  203.                                 }                                                                                       
  204.                         }   
  205.                 }else //按鍵松開了
  206.                 {
  207.                         lastpos[0]=0XFFFF;
  208.                         tcnt++;
  209.                         delay_ms(10);         
  210.                         //延時(shí)識(shí)別
  211.                         i++;                     
  212.                         if(tcnt==40)
  213.                         {
  214.                                 if(pcnt)//有有效的輸入                 
  215.                                 {
  216.                                         printf("總點(diǎn)數(shù):%d\r\n",pcnt);
  217.                                         alientek_ncr(READ_BUF,pcnt,6,mode,(char*)res);
  218.                                         printf("識(shí)別結(jié)果:%s\r\n",res);
  219.                                         pcnt=0;                                                               
  220.                                           POINT_COLOR=BLUE;//設(shè)置畫筆藍(lán)色
  221.                                          LCD_ShowString(30+72,90,200,16,16,res);         
  222. ……………………

  223. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
實(shí)驗(yàn)45 手寫識(shí)別實(shí)驗(yàn).rar (1.82 MB, 下載次數(shù): 14)


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

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 亚洲一区二区在线免费观看 | 成人午夜免费视频 | 免费一级毛片 | 日韩在线播放中文字幕 | 中文字幕在线第二页 | 国产视频h| 91国产精品 | 人人草人人干 | 久久久久欧美 | 波多野结衣一二三区 | 久久一区二区三区电影 | 久久精品国产一区二区电影 | 欧美精品一二三 | 美女拍拍拍网站 | 羞羞涩涩在线观看 | 91成人在线 | 一区二区三区中文字幕 | 国产成人免费视频网站视频社区 | 免费网站国产 | 国内精品视频在线观看 | 日韩在线中文字幕 | 欧美性生交大片免费 | 国产精品一区二区在线免费观看 | 国产成人免费视频网站高清观看视频 | 国产中文字幕在线观看 | av中文在线 | 在线日韩视频 | www.日本国产 | 成人午夜在线视频 | 91国自产| 中文字幕精品一区二区三区精品 | 操久久 | 欧美日韩一区二区在线 | 精品国产精品三级精品av网址 | 亚洲综合天堂网 | 在线观看国产视频 | 亚洲国产免费 | 一区二区三区视频在线免费观看 | 拍拍无遮挡人做人爱视频免费观看 | 犬夜叉在线观看 | 欧美成人aaa级毛片在线视频 |