Modules-old/ImageProcRobocup/lua_field_lines.cpp
//We always add pixel from top to bottom
We always add pixel from top to bottom
We always add pixel from top to bottom
void addVerticalPixel(int i, int j, double connect_th, int max_gap, int width){
  int seg_updated=0;
  for (int k=0;k<num_segments;k++){
    if(segments[k].state==1){
      double xProj = segments[k].xMean + segments[k].invgrad*(j-segments[k].yMean);
      double xErr = i-xProj;if (xErr<0) xErr=-xErr;
      if (xErr<connect_th){
        updateStat(&segments[k],i,j,max_gap);
        segments[k].count++;
        segments[k].invgrad=(double) 
		      (segments[k].xy- segments[k].x*segments[k].y/segments[k].count)
		      /(segments[k].yy-segments[k].y*segments[k].y/segments[k].count);
        if ((segments[k].invgrad>1.0) ||(segments[k].invgrad<-1.0)){
          segments[k].state=2; 
          segments[k].count=0;
        }
    	  segments[k].updated=1;
        segments[k].x1=i;
        segments[k].y1=j;
        seg_updated=seg_updated+1;
        if (width > segments[k].max_width){
          segments[k].max_width = width;
        }
      }
    }
  }
  if ((seg_updated==0)&&(num_segments<MAX_SEGMENTS)){
    initStat(&segments[num_segments],i,j);
    num_segments++;
  }
}
void addVerticalPixel ( int i , int j , double connect_th , int max_gap , int width ) { int seg_updated = 0 ; for ( int k = 0 ; k < num_segments ; k ++ ) { if ( segments [ k ] . state == 1 ) { double xProj = segments [ k ] . xMean + segments [ k ] . invgrad * ( j - segments [ k ] . yMean ) ; double xErr = i - xProj ; if ( xErr < 0 ) xErr = - xErr ; if ( xErr < connect_th ) { updateStat ( & segments [ k ] , i , j , max_gap ) ; segments [ k ] . count ++ ; segments [ k ] . invgrad = ( double ) ( segments [ k ] . xy - segments [ k ] . x * segments [ k ] . y / segments [ k ] . count ) / ( segments [ k ] . yy - segments [ k ] . y * segments [ k ] . y / segments [ k ] . count ) ; if ( ( segments [ k ] . invgrad > 1.0 ) || ( segments [ k ] . invgrad < -1.0 ) ) { segments [ k ] . state = 2 ; segments [ k ] . count = 0 ; } segments [ k ] . updated = 1 ; segments [ k ] . x1 = i ; segments [ k ] . y1 = j ; seg_updated = seg_updated + 1 ; if ( width > segments [ k ] . max_width ) { segments [ k ] . max_width = width ; } } } } if ( ( seg_updated == 0 ) && ( num_segments < MAX_SEGMENTS ) ) { initStat ( & segments [ num_segments ] , i , j ) ; num_segments ++ ; } }
We always add pixel from top to bottom
We always add pixel from top to bottom
//Find best matching active segment //kill anything that exceeds 45 degree //printf("New segment %dstart:%d,%d\n",num_segments,i,j);