Example #1
0
void decipherImage(int direction) {
  // Convert RGB camera frame to binary
  BinaryRGBFrame(cameraFrame); 
  //WaitUs(3000000);
  // Try to identify the forms and make a list of it.
  // CAN IDENTIFY MULTIPLE FORMS IN THE SAME IMAGE.
  // pattern defined in pattern.h
  numFormsThisFrame = IdentifyForm(cameraFrame, formsListThisFrame, pattern);  

  // No forms identified this frame
  if (numFormsThisFrame == 0) {
    DrawBitmap(0, 0, IDB_NOFORMS, bitmap, &screenBuffer);
    DrawLCD(&screenBuffer);
    canCross[direction]=-1;
  }
  
  // Parse the list of the form and print result on the Pob-Terminal and the LCD Screen
  // Draw bitmap and store into screenBuffer, then output screenBuffer
  // to the LCD screen. Note: This displays BIGA when a Trefle is observed?
  for (formsThisFrameIdx = 0; formsThisFrameIdx < numFormsThisFrame; formsThisFrameIdx++) {
  // Switch on the Pattern ID observed this frame
    switch (formsListThisFrame[formsThisFrameIdx].id) {
	 // TRACK
      case IDP_0_CROSS:
        DrawBitmap(0, 0, IDB_CROSS, bitmap, &screenBuffer);
        DrawLCD(&screenBuffer);
        canCross[direction]=IDP_0_CROSS;
        break;  
        
      // ROBOT        
      case IDP_1_BIGA:
        DrawBitmap(0, 0, IDB_BIGA, bitmap, &screenBuffer);
        DrawLCD(&screenBuffer);
        canCross[direction]=IDP_5_TRIANGLE;
        break;
        
      // TRAIN
      case IDP_2_KING:
        DrawBitmap(0, 0, IDB_KING, bitmap, &screenBuffer);
        DrawLCD(&screenBuffer);
        canCross[direction]=IDP_2_KING;
        break;
      
      // TRACK
      case IDP_3_TOWER:
        DrawBitmap(0, 0, IDB_TOWER, bitmap, &screenBuffer);
        DrawLCD(&screenBuffer);
        canCross[direction]=IDP_0_CROSS;
        break; 
      
      // NOT USED
      case IDP_4_TREFLE:
        DrawBitmap(0, 0, IDB_BIGA, bitmap, &screenBuffer);
        DrawLCD(&screenBuffer);
        break; 
      
      // ROBOT  
      case IDP_5_TRIANGLE:
        DrawBitmap(0, 0, IDB_TRIANGLE, bitmap, &screenBuffer);
        DrawLCD(&screenBuffer);
        canCross[direction]=IDP_5_TRIANGLE;
        break;
      
      // SAFE
      default:
        canCross[direction]=-1;
        break;
    }        
  }
}
int main (void)
{	
	UInt8 i=0,Nb_Identify=0;
	
	// List of form
	Form ListOfForm[MAX_OF_FORM];

	// Struct of three pointers on the RGB components
	UInt8 * FrameFromCam;

	//The pixels will be stocked in the LCD buffer
	UInt8 LCD_Buffer [LCD_WIDTH*LCD_HEIGHT*BITS] ;
	GraphicBuffer ScreenBuffer ;

	// System and LCD screen initialization
	InitPobeye2();
	InitI2C(I2C_100_KHZ);
	InitCameraPobeye2();
	InitLCD();	


	InitPobProto();
	SwitchOnAllServo();
	
	// Get the pointer of the red,green and blue video buffer
	FrameFromCam = GetRGBFrame();
		
	// Init the Graphic buffer with 128 per 64, one pixel per bit and LCD_Buffer
	InitGraphicBuffer( &ScreenBuffer, LCD_WIDTH,LCD_HEIGHT,ONE_BIT,LCD_Buffer);

	// clear the graphic buffer
	ClearGraphicBuffer(&ScreenBuffer);

	while(1)
	{		
		// grab the RGB components
		GrabRGBFrame();				
		
		// Binary the three RGB Buffer
		BinaryRGBFrame(FrameFromCam); 
		
		// Try to identify the forms and make a list of it
		Nb_Identify=IdentifyForm(FrameFromCam,ListOfForm,pattern);	

		// Parse the list of the form and print result on the Pob-Terminal and the LCD Screen
		for (i=0;i<Nb_Identify;i++)
		{
			switch (ListOfForm[i].id)
			{
			case IDP_0_CROSS:
				// Draw bitmap on the buffer and the LCD screen
				DrawBitmap(0,0,IDB_CROSS,bitmap,&ScreenBuffer);
				DrawLCD(&ScreenBuffer);
				MoveBot(RUN);
			break;
				
//			case IDP_1_BIGA:
//				DrawBitmap(0,0,IDB_BIGA,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;

			case IDP_2_KING:
				DrawBitmap(0,0,IDB_KING,bitmap,&ScreenBuffer);
				DrawLCD(&ScreenBuffer);
				MoveBot(LEFT);
			break;

//			case IDP_3_TOWER:
//				DrawBitmap(0,0,IDB_TOWER,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;
			
//			case IDP_4_TREFLE:
//				DrawBitmap(0,0,IDB_BIGA,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;
			
//			case IDP_5_TRIANGLE:
//				DrawBitmap(0,0,IDB_TRIANGLE,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;
			
			default:
				MoveBot(STOP);
			break;
			
			}				
		}		
	if (Nb_Identify == 0)
		{
		DrawBitmap(0,0,IDB_NOFORMS,bitmap,&ScreenBuffer);
		DrawLCD(&ScreenBuffer);
		}
	}
	return 0;
}