Changeset 363
- Timestamp:
- 01/31/07 17:21:00 (2 years ago)
- Files:
-
- trunk/lib/cc3_ilp/Makefile (modified) (1 diff)
- trunk/lib/cc3_ilp/cc3_conv.c (modified) (2 diffs)
- trunk/lib/cc3_ilp/cc3_conv.h (modified) (1 diff)
- trunk/projects/cmucam2/polly.c (modified) (1 diff)
- trunk/projects/polly/main.c (modified) (6 diffs)
- trunk/projects/polly/polly.c (modified) (4 diffs)
- trunk/projects/polly/polly.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/cc3_ilp/Makefile
r343 r363 2 2 LIBS += jpeg-6b 3 3 4 CSOURCES = cc3_ilp.c cc3_color_track.c cc3_color_info.c cc3_jpg.c cc3_math.c cc3_conv.c cc3_connected_component.c 4 CSOURCES = cc3_ilp.c cc3_color_track.c cc3_color_info.c cc3_jpg.c cc3_math.c cc3_conv.c cc3_connected_component.c cc3_img_writer.c 5 5 6 INCLUDES = cc3_ilp.h cc3_color_track.h cc3_color_info.h cc3_jpg.h cc3_math.h cc3_conv.h cc3_connected_component.h 6 INCLUDES = cc3_ilp.h cc3_color_track.h cc3_color_info.h cc3_jpg.h cc3_math.h cc3_conv.h cc3_connected_component.h cc3_img_writer.h 7 7 8 8 trunk/lib/cc3_ilp/cc3_conv.c
r349 r363 12 12 The function returns 1 upon success and 0 on failure. 13 13 */ 14 int cc3_convolve_img(cc3_image_t img, cc3_kernel_t kernel)14 int cc3_convolve_img(cc3_image_t *img, cc3_kernel_t kernel) 15 15 { 16 16 uint32_t i,j,k,l,mat_div; 17 17 cc3_pixel_t p; 18 18 if(kernel.size>MAX_KERNEL_SIZE) return 0; 19 if( img .height<kernel.size+1 ) return 0;20 if( img .width<kernel.size+1 ) return 0;19 if( img->height<kernel.size+1 ) return 0; 20 if( img->width<kernel.size+1 ) return 0; 21 21 22 22 mat_div=kernel.divisor; 23 for(j=0; j<img .height-kernel.size+1; j++ )24 for(i=0; i<img .width-kernel.size+1; i++ )23 for(j=0; j<img->height-kernel.size+1; j++ ) 24 for(i=0; i<img->width-kernel.size+1; i++ ) 25 25 { 26 26 uint32_t tmp; … … 29 29 for(l=0; l<kernel.size; l++ ) 30 30 { 31 cc3_get_pixel ( &img, i+k, j+l, &p);31 cc3_get_pixel (img, i+k, j+l, &p); 32 32 tmp+=p.channel[0]*kernel.mat[k][l]; 33 33 } 34 34 35 p.channel[0]=tmp / mat_div; 35 cc3_set_pixel ( &img, i, j, &p);36 cc3_set_pixel (img, i, j, &p); 36 37 } 37 38 return 1; trunk/lib/cc3_ilp/cc3_conv.h
r349 r363 14 14 15 15 16 int cc3_convolve_img(cc3_image_t img, cc3_kernel_t kernel);16 int cc3_convolve_img(cc3_image_t *img, cc3_kernel_t kernel); 17 17 18 18 #endif trunk/projects/cmucam2/polly.c
r352 r363 107 107 blur.mat[2][0]=1; blur.mat[2][1]=1; blur.mat[2][2]=1; 108 108 blur.divisor=9; 109 val=cc3_convolve_img( img,blur);109 val=cc3_convolve_img(&img,blur); 110 110 if(val==0) 111 111 { trunk/projects/polly/main.c
r351 r363 8 8 #include <cc3_ilp.h> 9 9 #include <cc3_math.h> 10 #include <cc3_img_writer.h> 10 11 #include "polly.h" 11 12 12 13 //#define MMC_DEBUG 13 14 15 void draw_line_img(double b,double m,double distance,uint8_t conf); 14 16 15 17 /* simple hello world, showing features and compiling*/ … … 18 20 uint32_t last_time, val,i; 19 21 char c; 20 uint8_t *x_axis ;22 uint8_t *x_axis,*h,cnt,conf; 21 23 polly_config_t p_config; 22 24 … … 51 53 cc3_wait_ms (1000); 52 54 x_axis = malloc(cc3_g_current_frame.width); 55 h = malloc(cc3_g_current_frame.width); 53 56 54 p_config.color_thresh= 20;55 p_config.min_blob_size= 20;57 p_config.color_thresh=10; 58 p_config.min_blob_size=30; 56 59 p_config.connectivity=0; 57 60 p_config.horizontal_edges=0; … … 67 70 // p_config.histogram gets filled with the return data 68 71 72 // Prune away points on the histogram that are outliers so they don't 73 // get added into the regression line. 74 cnt=0; 69 75 for(i=0; i<cc3_g_current_frame.width; i++ ) 70 x_axis[i]=i; 71 76 { 77 if(p_config.histogram[i]>0 && p_config.histogram[i]<71) 78 { 79 h[cnt]=p_config.histogram[i]; 80 x_axis[cnt]=i; 81 cnt++; 82 } 83 } 72 84 73 cc3_linear_reg(x_axis, p_config.histogram, cc3_g_current_frame.width,®_line); 85 printf( "cnt = %d\n",cnt ); 86 cc3_linear_reg(x_axis, h, cnt,®_line); 74 87 75 88 printf( "b=%f\n",reg_line.b ); … … 79 92 distance=reg_line.m*(cc3_g_current_frame.width/2)+reg_line.b; 80 93 printf( "distance = %f\n",distance ); 81 94 95 conf=255; 96 if(cnt<20) conf=100; 97 if(reg_line.r_sqr<.3) conf=100; 98 draw_line_img(reg_line.b,reg_line.m,distance,conf); 82 99 // convert_histogram_to_ppm (&polly_img, config.histogram); 83 100 … … 87 104 } 88 105 106 void draw_line_img(double b,double m,double distance,uint8_t conf) 107 { 108 cc3_image_t img; 109 cc3_pixel_t p; 110 uint32_t x; 111 int32_t y; 112 113 img.channels = 1; 114 img.width = cc3_g_current_frame.width; 115 img.height = cc3_g_current_frame.height; 116 img.pix = cc3_malloc_rows (cc3_g_current_frame.height); 117 if (img.pix == NULL) { 118 printf ("Not enough memory...\n"); 119 exit (0); 120 } 121 122 p.channel[0]=0; 123 for(y=0; y<img.height; y++) 124 for(x=0; x<img.width; x++ ) 125 cc3_set_pixel (&img, x, y, &p); 126 127 p.channel[0]=conf; 128 for(x=0; x<img.width; x++ ) 129 { 130 y=(uint32_t)(m*x+b); 131 if(y<0 || y>img.height) y=0; 132 y=img.height-y; 133 cc3_set_pixel (&img, x, y, &p); 134 } 135 cc3_img_write_file_create(&img); 136 } trunk/projects/polly/polly.c
r349 r363 8 8 #include <cc3_ilp.h> 9 9 #include <cc3_conv.h> 10 #include <cc3_img_writer.h> 10 11 #include "polly.h" 11 12 12 13 #define MMC_DEBUG 14 13 15 14 16 ccr_config_t g_cc_conf; … … 107 109 blur.mat[2][0]=1; blur.mat[2][1]=1; blur.mat[2][2]=1; 108 110 blur.divisor=9; 109 val=cc3_convolve_img(img,blur); 111 //val=cc3_img_write_file_create(&img); 112 val=cc3_convolve_img(&img,blur); 113 //val=cc3_img_write_file_create(&img); 110 114 if(val==0) 111 115 { 112 116 printf( "convolve failed\n" ); 117 exit(0); 113 118 } 114 119 } … … 368 373 369 374 370 void generate_polly_histogram (cc3_image_t * img, uint8_t * hist)375 void generate_polly_histogram (cc3_image_t * img, int8_t * hist) 371 376 { 372 377 int x, y; … … 457 462 do { 458 463 #ifdef VIRTUAL_CAM 459 sprintf(filename, "img%.5d .pgm", pgm_cnt);464 sprintf(filename, "img%.5da.pgm", pgm_cnt); 460 465 #else 461 466 sprintf(filename, "c:/img%.5d.pgm", pgm_cnt); trunk/projects/polly/polly.h
r349 r363 18 18 uint8_t vertical_edges; 19 19 uint8_t blur; 20 uint8_t *histogram;20 int8_t *histogram; 21 21 } polly_config_t; 22 22 … … 30 30 int polly( polly_config_t config); 31 31 void connected_component_reduce (cc3_image_t * img, ccr_config_t config); 32 void generate_polly_histogram (cc3_image_t * img, uint8_t * hist);32 void generate_polly_histogram (cc3_image_t * img, int8_t * hist); 33 33 void matrix_to_pgm (cc3_image_t * img); 34 void convert_histogram_to_ppm (cc3_image_t * img, uint8_t * hist);34 void convert_histogram_to_ppm (cc3_image_t * img, int8_t * hist); 35 35 int count (cc3_image_t * img, int x, int y, int steps); 36 36 int reduce (cc3_image_t * img, int x, int y, int steps, int remove);
