Modules-old/ImageProc/lua_field_lines.cpp
/*
Simple state machine for field line detection:
==colorField -> &colorLine -> ==colorField
Use lineState(0) to initialize, then call with color labels
Returns width of line when detected, otherwise 0
*/
Simple state machine for field line detection:
colorField -> &colorLine -> ==colorField
Use lineState(0) to initialize, then call with color labels
Returns width of line when detected, otherwise 0
Simple state machine for field line detection : colorField - > &colorLine - > == colorField Use lineState ( 0 ) to initialize then call with color labels Returns width of line when detected otherwise 0
int lineState(uint8_t label)
{
  enum {STATE_NONE, STATE_FIELD, STATE_LINE};
  static int state = STATE_NONE;
  static int width = 0;
  switch (state) {
  case STATE_NONE:
    if (label & colorField){
      state = STATE_FIELD;
		}
    break;
  case STATE_FIELD:
		if (label & colorLine) {
      state = STATE_LINE;
      width = 1;
    }
    else if (label != colorField) {
      state = STATE_NONE;
    }
    break;
  case STATE_LINE:
    if (label & colorLine){
      width++;
      return width;
    }
    else if (label & colorField){
      state = STATE_FIELD;
      return width;
    }
    else {
      state = STATE_NONE;
    }
  /*
     if ( !(label & colorField) ) {
    if (label & colorField){
      state = STATE_FIELD;
      return width;
    }
    else if (!(label & colorLine)) {
      state = STATE_NONE;
    }
    else {
      width++;
    }
    */
  }
  return 0;
}
int lineState ( uint8_t label ) { enum { STATE_NONE , STATE_FIELD , STATE_LINE } ; static int state = STATE_NONE ; static int width = 0 ; switch ( state ) { case STATE_NONE : if ( label & colorField ) { state = STATE_FIELD ; } break ; case STATE_FIELD : if ( label & colorLine ) { state = STATE_LINE ; width = 1 ; } else if ( label != colorField ) { state = STATE_NONE ; } break ; case STATE_LINE : if ( label & colorLine ) { width ++ ; } else if ( label & colorField ) { state = STATE_FIELD ; return width ; } else { state = STATE_NONE ; } } return 0 ; }
Simple state machine for field line detection:
colorField -> &colorLine -> ==colorField
Use lineState(0) to initialize, then call with color labels
Returns width of line when detected, otherwise 0
Simple state machine for field line detection : colorField - > &colorLine - > == colorField Use lineState ( 0 ) to initialize then call with color labels Returns width of line when detected otherwise 0
//else if (label & colorLine){ state = STATE_LINE; width = 1; } // //return width; // /*
    // if ( !(label & colorField) ) {
    if (label & colorField){
      state = STATE_FIELD;
      return width;
    }
    else if (!(label & colorLine)) {
      state = STATE_NONE;
    }
    else {
      width++;
    }
    */