Changeset 285
- Timestamp:
- 01/10/07 16:56:40 (2 years ago)
- Files:
-
- trunk/lib/cc3_ilp/cc3_ilp.c (modified) (1 diff)
- trunk/projects/polly/main.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/cc3_ilp/cc3_ilp.c
r279 r285 33 33 uint8_t num_channels = cc3_g_current_frame.coi == CC3_ALL ? 3 : 1; 34 34 35 cc3_set_led (1);36 35 37 36 size_x = cc3_g_current_frame.width; trunk/projects/polly/main.c
r284 r285 8 8 #include <cc3_ilp.h> 9 9 10 //#define VIRTUAL_CAM 10 11 11 12 #define COLOR_THRESH 25 … … 25 26 void connected_component_reduce (cc3_image_t * img, int min_blob_size); 26 27 void generate_histogram (cc3_image_t * img, uint8_t * hist); 27 void matrix_to_p pm (cc3_image_t * img);28 void matrix_to_pgm (cc3_image_t * img); 28 29 void convert_histogram_to_ppm (cc3_image_t * img, uint8_t * hist); 29 30 int count (cc3_image_t * img, int x, int y, int steps); 30 31 int reduce (cc3_image_t * img, int x, int y, int steps, int remove); 32 void write_raw_fifo_ppm(); 31 33 32 34 … … 72 74 // sample wait command in ms 73 75 cc3_wait_ms (1000); 74 cc3_set_led (0);75 76 76 77 // setup an image structure … … 99 100 cc3_pixel_t down_pix; 100 101 102 cc3_set_led(2); 103 while(!cc3_read_button()); 104 cc3_clr_led(2); 105 106 107 // clear polly working image 101 108 p.channel[0] = 0; 102 109 for (int y = 0; y < HEIGHT; y++) … … 106 113 107 114 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 108 120 cc3_pixbuf_read_rows (img.pix, cc3_g_current_frame.height); 109 121 … … 129 141 130 142 connected_component_reduce (&polly_img, MIN_BLOB_SIZE); 143 matrix_to_pgm (&polly_img); 144 131 145 generate_histogram (&polly_img, range); 132 146 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" ); 135 150 136 151 } … … 397 412 398 413 399 void matrix_to_p pm (cc3_image_t * img)400 { 401 static intcnt = 0;402 char str[32];414 void matrix_to_pgm (cc3_image_t * img) 415 { 416 static uint32_t pgm_cnt = 0; 417 char filename[32]; 403 418 FILE *fp; 404 419 int width, height; 405 420 cc3_pixel_t p; 406 421 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 407 447 width = img->width; 408 448 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 }417 449 fprintf (fp, "P5\n%d %d 255\n", width, height); 418 450 for (int y = 0; y < height; y++) { … … 422 454 } 423 455 } 456 fflush(fp); 424 457 fclose (fp); 425 458 426 459 } 460 461 462 void 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 }
