#include "common.h" #include "image.h" #include "gpio.h" #include "exti.h" #include "uart.h" #include "FTM.h" #include "delay.h" #include "isr.h" unsigned char threshold=135; unsigned char Is_SendPhoto=0; unsigned char Pix_data[V][H]={0},Bina_data[V][H]={0}; int LeftBorder[V]={0},RightBorder[V]={0}, CenterLine[V]={0}; u16 CCD_V,CCD_H; s8 Sumleft,Sumright; unsigned chartop_line=40,top_line1=50,top_line2=48; long count,WhiteNum; unsigned char width_count=50; unsigned char width_min=50; unsigned char V_count=0; unsigned char jump_point; unsigned char last_top; unsigned char top_top_line=49; unsigned char THRE[20]; long thre_sum=0; unsigned char thread_count; unsigned char center_min=30; unsigned char left_line,right_line; unsigned int left_count,right_count; unsigned char Bina_Data[H]={0}; u32 S_count=0; extern u32 start4s; void CameraInit() { exti_init(PORTE,1,rising_down); disable_irq(91); exti_init(PORTE,0,falling_down); } void Binarization(void) { u16i; for(i=0;i<280;i++) { if(Pix_data[32]>threshold) { Bina_Data = 1; } else { Bina_Data = 0; } } } void Get_Center(void) { for(CCD_H=155;CCD_H>1;CCD_H--) { if((Bina_Data[CCD_H]) && (Bina_Data[CCD_H-1]==0) &&(Bina_Data[CCD_H-2]==0)) { RightBorder[CCD_V]=CCD_H; break; } else RightBorder[CCD_V]=0; } for(CCD_H=125;CCD_H<H-2;CCD_H++) { if((Bina_Data[CCD_H]==0) && (Bina_Data[CCD_H+1]==0) &&(Bina_Data[CCD_H+2]==0)) { LeftBorder[CCD_V]=CCD_H; break; } else LeftBorder[CCD_V]=280; } CenterLine[CCD_V]=(LeftBorder[CCD_V]+RightBorder[CCD_V])/2; } void BinaData() { inti=0,j=0; unsigned char *p; for(i=0;i<V;i++) { p=Pix_data; for(j=0;j<H;j++) { if(*(p+j)>=threshold) { Bina_data[j]=1; } else Bina_data[j]=0; } } } void AllFilt() { count=0; for(CCD_V=1;CCD_V<V-1;CCD_V++) { for(CCD_H=1;CCD_H<H-1;CCD_H++) { if(Bina_data[CCD_V][CCD_H]==1) { if((Bina_data[CCD_V-1][CCD_H]==1 || Bina_data[CCD_V+1][CCD_H]==1)&& (Bina_data[CCD_V][CCD_H-1]==1 || Bina_data[CCD_V][CCD_H+1]==1)) { Bina_data[CCD_V][CCD_H]=1; count++; } else Bina_data[CCD_V][CCD_H]=0; } else if(Bina_data[CCD_V][CCD_H]==0) { if((Bina_data[CCD_V-1][CCD_H]==0 || Bina_data[CCD_V+1][CCD_H]==0)&& (Bina_data[CCD_V][CCD_H-1]==0 || Bina_data[CCD_V][CCD_H+1]==0)) { Bina_data[CCD_V][CCD_H]=0; } else { Bina_data[CCD_V][CCD_H]=1; count++; } } } } } void get_center() { unsigned char *p; static unsigned char last_center=140; for(CCD_V=0;CCD_V<LINE;CCD_V++) { p=Bina_data[CCD_V]; for(CCD_H=140;CCD_H>1;CCD_H--) { if((*(p+CCD_H)==0) && (*(p+CCD_H-1)==0) &&(*(p+CCD_H-2)==0)) { RightBorder[CCD_V]=CCD_H; break; } else RightBorder[CCD_V]=18; } for(CCD_H=140;CCD_H<H-2;CCD_H++) { if((*(p+CCD_H)==0) && (*(p+CCD_H+1)==0) &&(*(p+CCD_H+2)==0)) { LeftBorder[CCD_V]=CCD_H; break; } else LeftBorder[CCD_V]=262; } CenterLine[CCD_V]=(LeftBorder[CCD_V]+RightBorder[CCD_V])/2; if(fabsf(CenterLine[4]-last_center)>=8) CenterLine[4]=last_center; last_center=CenterLine[4]; // if((LeftBorder[CCD_V]-RightBorder[CCD_V])>width_count) // width_count=LeftBorder[CCD_V]-RightBorder[CCD_V]; } for(CCD_V=LINE;CCD_V<V;CCD_V++) { p=Bina_data[CCD_V]; for(CCD_H=(unsigned char )CenterLine[CCD_V-1];CCD_H>1;CCD_H--) { if((*(p+CCD_H)==0) && (*(p+CCD_H-1)==0) &&(*(p+CCD_H-2)==0)) { RightBorder[CCD_V]=CCD_H; break; } else RightBorder[CCD_V]=18; } for(CCD_H=(unsigned char )CenterLine[CCD_V-1];CCD_H<H-2;CCD_H++) { if((*(p+CCD_H)==0) && (*(p+CCD_H+1)==0) &&(*(p+CCD_H+2)==0)) { LeftBorder[CCD_V]=CCD_H; break; } else LeftBorder[CCD_V]=262; } CenterLine[CCD_V]=(LeftBorder[CCD_V]+RightBorder[CCD_V])/2; //if((LeftBorder[CCD_V]-RightBorder[CCD_V])>width_count) // width_count=LeftBorder[CCD_V]-RightBorder[CCD_V]; } } 求大神解读一下,
|