高级会员
- 积分
- 620
- 威望
- 334
- 贡献
- 166
- 兑换币
- 0
- 注册时间
- 2012-4-12
- 在线时间
- 60 小时
- 毕业学校
- 成都大学
|
3#
楼主 |
发表于 2012-6-29 00:58:39
|
只看该作者
- void Black_Extract(void)
- {
- volatile int get_black_cnt,
- get_black_cnt1,
- base_point_flag;
- volatile byte i=0,j=0,left_temp=0,right_temp=0;
- volatile int k,m,n,o;
- volatile byte start_flag1=0,start_flag2=0;
- volatile word left_line=0,right_line=0,left_line1=0,right_line1=0;
- volatile word left_edge=0,right_edge=0;
- volatile char ins_black_center=0;
- black_lost_cnt=0;
- get_black_cnt =0;
- black_lost_cnt1 =0;
- black_lost_cnt=0;
- base_point_flag=0;
- Flag_Lost=0;
- SER_NUM=6;//搜索范围赋初值
- //Line_Center[0] = Line_Center[IMAGE_ROW-1];//每场的末尾给新的一场的开始,让图像连续,这句很重要
- //后10行两边都查找,取中间点
- start_flag1=0;start_flag2=0;
- left_edge=0;right_edge=0; //左右跳变清零
- //###########################二十行搜索##########################
- erzhihua(135);
- for(i=0;i<20;i++)
- {
- for(j=43;j>3;j--)
- {
- if(ImageSample_Buffer[i][j-1]==1&&ImageSample_Buffer[i][j-2]==1&&ImageSample_Buffer[i][j-3]==1&&ImageSample_Buffer[i][j]==0&&ImageSample_Buffer[i][j+1]==0&&ImageSample_Buffer[i][j+2]==0)
- {
- start_flag1=1;
- left_edge=j; //记录左跳变沿位置
- left_line=left_edge;
- }
- }//左边搜索结束
- for(j=43;j<IMAGE_COL-3;j++)
- {
- if(ImageSample_Buffer[i][j+1]==1&&ImageSample_Buffer[i][j+2]==1&&ImageSample_Buffer[i][j+3]==1&&ImageSample_Buffer[i][j]==0&&ImageSample_Buffer[i][j-1]==0&&ImageSample_Buffer[i][j-2]==0)
- {
- start_flag2=1;
- right_edge=j; //记录右跳变沿位置
- right_line=right_edge;
- }
- }//右边搜索结束,找到左右跳变沿
- //一行搜索结束
- if(start_flag1==1 && start_flag2==1) //1.有左右跳变沿
- {
- SCI_Write('11') ;
- if((right_line - left_line >= WHITE_LINE_MIN0)&&(right_line - left_line <= WHITE_LINE_MAX0)) //黑线宽度在规定范围内
- { //@@@@@@@@@过滤过宽的白线和过细的白线
- Line_Center_Temp=(byte)((right_line+left_line+1)>>1); //取中心,考虑到了每行的搜索到的最后一个点
- Line_Center[i]=Line_Center_Temp;
- get_black_cnt++;//找到有效行,加1
- }
- else
- {
- black_lost_cnt++; //丢失行加1
- get_black_cnt=0; //继续从头再找
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- }
- }
- else if(start_flag1==0 && start_flag2==1) //2.只有右跳变沿,黑线向左弯
- {
- SCI_Write('22') ;
- if((right_line >= WHITE_LINE_MIN0) && (right_line <=WHITE_LINE_MAX0)) //黑线宽度在规定范围内
- {
- Line_Center_Temp=(byte)(right_line>>1);
- Line_Center[i]=Line_Center_Temp;
- get_black_cnt++;
- }
- else
- {
- black_lost_cnt++; //丢失行加1
- get_black_cnt=0; //继续从头再找
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- }
- }
- else if(start_flag1==1 && start_flag2==0) //3.只有左跳变沿,黑线向右弯
- {
- SCI_Write('33') ;
- if((IMAGE_COL - left_line >= WHITE_LINE_MIN0) && (IMAGE_COL - left_line <= WHITE_LINE_MAX0)) //黑线宽度在规定范围内
- {
- Line_Center_Temp=(byte)((left_line+IMAGE_COL)>>1);
- Line_Center[i]=Line_Center_Temp;
- get_black_cnt++;//找到有效行,加1
- }
- else
- {
- black_lost_cnt++; //丢失行加1
- get_black_cnt=0; //继续从头再找
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- }
- }
- else if(start_flag1==0 && start_flag2==0) //4.无左右跳变沿,这行舍弃,计数加1
- {
- SCI_Write('44') ;
- black_lost_cnt++; //丢失行加1
- get_black_cnt=0; //继续从头再找
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- }
- /*******判断是否为基准行**************/
- if(get_black_cnt>=4)//找到有效行,跳到下一个循环
- {
- if(fabs(Line_Center[i]-Line_Center[i+1]) <COM_NUM &&
- fabs(Line_Center[i+1]-Line_Center[i+2])<COM_NUM &&
- fabs(Line_Center[i+2]-Line_Center[i+3])<COM_NUM )
- { //若4点连续,认为找到基准线了
- base_point_flag=1; //表示基准点已经找到
- Down_Limit=i+1; //最近有效行
- Down_Limit1=Down_Limit;
- break; //跳出for循环
- }
- else //若不连续,继续全行搜索
- {
- get_black_cnt=0;
- }
- }
- if(black_lost_cnt>=15) //前20行未找到基准行
- {
- duoji_kongzhi=duoji_kongzhi1;
- break; //跳出for循环
- }
- }
- //是否返回继续找基准行
- if(base_point_flag==0)
- {
- return;
- }
- //##########################继续往前搜索##########################
- for(i=Down_Limit1;i<IMAGE_ROW;i++)
- {
- start_flag1=0;
- start_flag2=0; //左右标志位置0
- left_line1=left_line;
- right_line1=right_line;
- k=left_line-SER_NUM; //SER_NUM为搜索范围
- if(k<0) k=0;
- m=left_line+SER_NUM;
- if(m>IMAGE_COL) m=IMAGE_COL;
- n=right_line-SER_NUM;
- if(n<0) n=0;
- o=right_line+SER_NUM;
- if(o>IMAGE_COL)o=IMAGE_COL; //确定左右搜索范围
- for(k;k<m;k++) //搜索左边
- {
- if(ImageSample_Buffer[i][k+1]==0&&ImageSample_Buffer[i][k+2]==0&&ImageSample_Buffer[i][k+3]==0&&ImageSample_Buffer[i][k]==1&&ImageSample_Buffer[i][k-1]==1&&ImageSample_Buffer[i][k-2]==1)
- {
- start_flag1=1;
- left_edge=k; //记录左跳变沿位置
- left_line=left_edge;
- }
- } //左边搜索结束
- for(n;n<o;n++)
- {
- if(ImageSample_Buffer[i][n+1]==1&&ImageSample_Buffer[i][n+2]==1&&ImageSample_Buffer[i][n+3]==1&&ImageSample_Buffer[i][n]==0&&ImageSample_Buffer[i][n-1]==0&&ImageSample_Buffer[i][n-2]==0)
- {
- start_flag2=1;
- right_edge=n; //记录右跳变沿位置
- right_line=right_edge;
- }
- } //右边搜索结束
- //按照基准行做相同判断
- if(start_flag1==1 && start_flag2==1) //1.有左右跳变沿
- {
- SCI_Write('55') ;
- if((right_line - left_line >= WHITE_LINE_MIN0)&&(right_line - left_line <= WHITE_LINE_MAX0)) //黑线宽度在规定范围内
- { //@@@@@@@@@过滤过宽的白线和过细的白线
- Line_Center_Temp=(byte)((right_line+left_line+1)>>1); //取中心,考虑到了每行的搜索到的最后一个点
- Line_Center[i]=Line_Center_Temp;
- get_black_cnt1++;//找到有效行,加1
- }
- else
- {
- black_lost_cnt1++; //丢失行加1
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- left_line=left_line1; //使用上一行的双线标志
- right_line=right_line1;
- SER_NUM++;//扩大搜索范围
- }
- }
- else if(start_flag1==0 && start_flag2==1) //2.只有右跳变沿,黑线向左弯
- {
- SCI_Write('66') ;
- if((right_line >= WHITE_LINE_MIN0) && (right_line <=WHITE_LINE_MAX0)) //黑线宽度在规定范围内
- {
- Line_Center_Temp=(byte)(right_line>>1);
- Line_Center[i]=Line_Center_Temp;
- get_black_cnt1++;
- }
- else
- {
- black_lost_cnt1++; //丢失行加1
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- left_line=left_line1; //使用上一行的双线标志
- right_line=right_line1;
- SER_NUM++;//扩大搜索范围
- }
- }
- else if(start_flag1==1 && start_flag2==0) //3.只有左跳变沿,黑线向右弯
- {
- SCI_Write('77') ;
- if((IMAGE_COL - left_line >= WHITE_LINE_MIN0) && (IMAGE_COL - left_line <= WHITE_LINE_MAX0)) //黑线宽度在规定范围内
- {
- Line_Center_Temp=(byte)((left_line+IMAGE_COL)>>1);
- Line_Center[i]=Line_Center_Temp;
- get_black_cnt1++;//找到有效行,加1
- }
- else
- {
- black_lost_cnt1++; //丢失行加1
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- left_line=left_line1; //使用上一行的双线标志
- right_line=right_line1;
- SER_NUM++;//扩大搜索范围
- }
- }
- else if(start_flag1==0 && start_flag2==0) //4.无左右跳变沿,这行舍弃,计数加1
- {
- SCI_Write('88') ;
- black_lost_cnt1++; //丢失行加1
- Line_Center[i]=Line_Center[i-1]; //赋值上一行,不赋值则为上一场的值
- left_line=left_line1; //使用上一行的双线标志
- right_line=right_line1;
- SER_NUM++;//扩大搜索范围
- }
- if(black_lost_cnt1>=15) //后25行丢线行数过多,采用上一场值,并跳出
- {
- duoji_kongzhi=duoji_kongzhi1;
- break; //跳出for循环
- }
- }
- }
复制代码 |
|