Changeset 285

Show
Ignore:
Timestamp:
01/10/07 16:56:40 (2 years ago)
Author:
anthony_rowe
Message:

polly update

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/cc3_ilp/cc3_ilp.c

    r279 r285  
    3333  uint8_t num_channels = cc3_g_current_frame.coi == CC3_ALL ? 3 : 1; 
    3434 
    35   cc3_set_led (1); 
    3635 
    3736  size_x = cc3_g_current_frame.width; 
  • trunk/projects/polly/main.c

    r284 r285  
    88#include <cc3_ilp.h> 
    99 
     10//#define VIRTUAL_CAM 
    1011 
    1112#define COLOR_THRESH   25 
     
    2526void connected_component_reduce (cc3_image_t * img, int min_blob_size); 
    2627void generate_histogram (cc3_image_t * img, uint8_t * hist); 
    27 void matrix_to_ppm (cc3_image_t * img); 
     28void matrix_to_pgm (cc3_image_t * img); 
    2829void convert_histogram_to_ppm (cc3_image_t * img, uint8_t * hist); 
    2930int count (cc3_image_t * img, int x, int y, int steps); 
    3031int reduce (cc3_image_t * img, int x, int y, int steps, int remove); 
     32void write_raw_fifo_ppm(); 
    3133 
    3234 
     
    7274  // sample wait command in ms  
    7375  cc3_wait_ms (1000); 
    74   cc3_set_led (0); 
    7576 
    7677  // setup an image structure  
     
    99100    cc3_pixel_t down_pix; 
    100101 
     102        cc3_set_led(2); 
     103         while(!cc3_read_button()); 
     104        cc3_clr_led(2); 
     105           
     106 
     107    // clear polly working image 
    101108    p.channel[0] = 0; 
    102109    for (int y = 0; y < HEIGHT; y++) 
     
    106113 
    107114    cc3_pixbuf_load (); 
     115    cc3_pixbuf_set_coi (CC3_ALL); 
     116    write_raw_fifo_ppm(); 
     117    cc3_pixbuf_set_coi (CC3_GREEN); 
     118    cc3_pixbuf_rewind(); 
     119 
    108120    cc3_pixbuf_read_rows (img.pix, cc3_g_current_frame.height); 
    109121 
     
    129141 
    130142    connected_component_reduce (&polly_img, MIN_BLOB_SIZE); 
     143    matrix_to_pgm (&polly_img); 
     144 
    131145    generate_histogram (&polly_img, range); 
    132146    convert_histogram_to_ppm (&polly_img, range); 
    133     matrix_to_ppm (&polly_img); 
    134  
     147    matrix_to_pgm (&polly_img); 
     148     
     149    printf( "Frame done\n" ); 
    135150 
    136151  } 
     
    397412 
    398413 
    399 void matrix_to_ppm (cc3_image_t * img) 
    400 { 
    401   static int cnt = 0; 
    402   char str[32]; 
     414void matrix_to_pgm (cc3_image_t * img) 
     415{ 
     416  static uint32_t pgm_cnt = 0; 
     417  char filename[32]; 
    403418  FILE *fp; 
    404419  int width, height; 
    405420  cc3_pixel_t p; 
    406421 
     422  
     423  do {  
     424#ifdef VIRTUAL_CAM 
     425          sprintf(filename, "c:/img%.5d.pgm", pgm_cnt); 
     426#else 
     427          sprintf(filename, "img%.5d.pgm", pgm_cnt); 
     428#endif 
     429        fp = fopen(filename, "r"); 
     430        if(fp!=NULL ) {  
     431                printf( "%s already exists...\n",filename );  
     432                pgm_cnt++;  
     433                fclose(fp); 
     434                } 
     435    } while(fp!=NULL); 
     436    pgm_cnt++;  
     437 
     438    // print file that you are going to write to stderr 
     439    fprintf(stderr,"%s\r\n", filename); 
     440    fp = fopen(filename, "w"); 
     441    if(fp==NULL || pgm_cnt>200 ) 
     442    { 
     443        cc3_set_led(3); 
     444        while(1); 
     445    } 
     446   
    407447  width = img->width; 
    408448  height = img->height; 
    409  
    410   sprintf (str, "out_%d.pgm", cnt); 
    411   cnt++; 
    412   fp = fopen (str, "w"); 
    413   if (fp == NULL) { 
    414     printf ("Can't open file...\n"); 
    415     exit (0); 
    416   } 
    417449  fprintf (fp, "P5\n%d %d 255\n", width, height); 
    418450  for (int y = 0; y < height; y++) { 
     
    422454    } 
    423455  } 
     456  fflush(fp); 
    424457  fclose (fp); 
    425458 
    426459} 
     460 
     461 
     462void write_raw_fifo_ppm() 
     463{ 
     464  uint32_t x, y; 
     465  uint32_t size_x, size_y; 
     466  FILE *f; 
     467  static uint32_t ppm_cnt=0; 
     468  char filename[32]; 
     469  uint8_t *row = cc3_malloc_rows(1); 
     470 
     471   do {  
     472#ifdef VIRTUAL_CAM 
     473        sprintf(filename, "c:/img%.5d.ppm", ppm_cnt); 
     474#else 
     475        sprintf(filename, "img%.5d.ppm", ppm_cnt); 
     476#endif 
     477        f = fopen(filename, "r"); 
     478        if(f!=NULL ) {  
     479                printf( "%s already exists...\n",filename );  
     480                ppm_cnt++;  
     481                fclose(f); 
     482                } 
     483    } while(f!=NULL); 
     484    ppm_cnt++;  
     485 
     486    // print file that you are going to write to stderr 
     487    fprintf(stderr,"%s\r\n", filename); 
     488    f = fopen(filename, "w"); 
     489    if(f==NULL || ppm_cnt>200 ) 
     490    { 
     491        cc3_set_led(3); 
     492        while(1); 
     493    } 
     494 
     495  size_x = cc3_g_current_frame.width; 
     496  size_y = cc3_g_current_frame.height; 
     497 
     498  fprintf(f,"P3\n%d %d\n255\n",size_x,size_y ); 
     499   
     500  for (y = 0; y < size_y; y++) { 
     501    cc3_pixbuf_read_rows(row, 1); 
     502    for (x = 0; x < size_x * 3U; x++) { 
     503      uint8_t p = row[x]; 
     504      fprintf(f,"%d ",p); 
     505    } 
     506  fprintf(f,"\n"); 
     507  } 
     508  fflush(f); 
     509  fclose(f);  
     510  free(row); 
     511}