Changeset 349

Show
Ignore:
Timestamp:
01/21/07 22:19:45 (2 years ago)
Author:
anthony_rowe
Message:

polly update

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/hal/virtual-cam/cc3_hal.h

    r302 r349  
    3434#define VIRTUAL_FIFO_SIZE    (640*480*3) 
    3535uint8_t virtual_fifo[VIRTUAL_FIFO_SIZE]; 
    36 int virtual_fifo_index; 
     36uint32_t virtual_fifo_index; 
    3737 
    3838typedef enum { 
  • trunk/lib/cc3_ilp/cc3_conv.c

    r343 r349  
    2020if( img.width<kernel.size+1 ) return 0; 
    2121 
    22 mat_div=kernel.size*kernel.size
     22mat_div=kernel.divisor
    2323for(j=0; j<img.height-kernel.size+1; j++ ) 
    2424        for(i=0; i<img.width-kernel.size+1; i++ ) 
  • trunk/lib/cc3_ilp/cc3_conv.h

    r343 r349  
    99typedef struct{ 
    1010uint8_t mat[MAX_KERNEL_SIZE][MAX_KERNEL_SIZE]; 
     11uint8_t divisor; 
    1112uint32_t size; 
    1213} cc3_kernel_t; 
    1314 
    1415 
    15 int convolve(cc3_image_t img, cc3_kernel_t kernel); 
     16int cc3_convolve_img(cc3_image_t img, cc3_kernel_t kernel); 
    1617 
    1718#endif 
  • trunk/projects/polly/Makefile

    r340 r349  
    33 
    44# C files to compile 
    5 CSOURCES=main.c polly.c conv.c lreg.c 
     5CSOURCES=main.c polly.c 
    66 
    77# header files 
    8 INCLUDES=polly.h conv.h lreg.h 
     8INCLUDES=polly.h 
    99 
    1010# header files 
  • trunk/projects/polly/main.c

    r341 r349  
    77#include <cc3.h> 
    88#include <cc3_ilp.h> 
     9#include <cc3_math.h> 
    910#include "polly.h" 
    1011 
    11 #define MMC_DEBUG 
    12  
    13  
     12//#define MMC_DEBUG 
    1413 
    1514 
     
    1716int main (void) 
    1817{ 
    19   uint32_t last_time, val
     18  uint32_t last_time, val,i
    2019  char c; 
    21  
     20  uint8_t *x_axis; 
     21  polly_config_t p_config; 
    2222 
    2323  // setup system     
     
    5050  // sample wait command in ms  
    5151  cc3_wait_ms (1000); 
     52  x_axis = malloc(cc3_g_current_frame.width); 
     53          
     54  p_config.color_thresh=20; 
     55  p_config.min_blob_size=20; 
     56  p_config.connectivity=0; 
     57  p_config.horizontal_edges=0; 
     58  p_config.vertical_edges=1; 
     59  p_config.blur=1; 
     60  p_config.histogram=malloc(cc3_g_current_frame.width);  
    5261 
    5362  while (1) { 
    54         polly_config_t p_config; 
    55         p_config.color_thresh=20; 
    56         p_config.min_blob_size=20; 
    57         p_config.connectivity=0; 
    58         p_config.horizontal_edges=0; 
    59         p_config.vertical_edges=1; 
    60         p_config.blur=1; 
    61         polly(p_config); 
     63        double distance; 
     64        cc3_linear_reg_data_t reg_line; 
     65 
     66        polly(p_config);  // p_config.histogram gets filled with the return data 
     67 
     68        for(i=0; i<cc3_g_current_frame.width; i++ ) 
     69                x_axis[i]=i; 
     70     
     71 
     72        cc3_linear_reg(x_axis, p_config.histogram, cc3_g_current_frame.width,&reg_line); 
     73 
     74        printf( "b=%f\n",reg_line.b );      
     75        printf( "m=%f\n",reg_line.m );      
     76        printf( "r^2=%f\n",reg_line.r_sqr );      
     77 
     78        distance=reg_line.m*(cc3_g_current_frame.width/2)+reg_line.b; 
     79        printf( "distance = %f\n",distance );  
     80     
     81    //  convert_histogram_to_ppm (&polly_img, config.histogram); 
    6282         
    6383        } 
  • trunk/projects/polly/polly.c

    r343 r349  
    77#include <cc3.h> 
    88#include <cc3_ilp.h> 
     9#include <cc3_conv.h> 
    910#include "polly.h" 
    10 #include "conv.h" 
    11 #include "lreg.h" 
    1211 
    1312#define MMC_DEBUG 
    1413 
     14ccr_config_t g_cc_conf; 
    1515 
    1616// Constants for connected component blob reduce 
     
    3030  uint32_t last_time, val,i; 
    3131  char c; 
    32   filter_t blur; 
     32  cc3_kernel_t blur; 
    3333  cc3_pixel_t p; 
    3434  cc3_image_t polly_img; 
    3535  cc3_image_t img; 
    36   uint8_t *range; 
    37   uint8_t *x_axis; 
     36   
    3837  cc3_pixel_t mid_pix; 
    3938  cc3_pixel_t right_pix; 
    4039  cc3_pixel_t down_pix; 
    41   reg_data_t reg_line; 
     40  
    4241 
    4342 // limit the recursive depth 
     
    7473        return 0; 
    7574   
    76   range = malloc(polly_img.width); 
    77   if(range==NULL) 
     75  if(config.histogram==NULL) 
    7876        return 0; 
    7977 
     
    108106        blur.mat[1][0]=1; blur.mat[1][1]=1; blur.mat[1][2]=1; 
    109107        blur.mat[2][0]=1; blur.mat[2][1]=1; blur.mat[2][2]=1; 
    110         val=convolve(img,blur); 
     108        blur.divisor=9; 
     109        val=cc3_convolve_img(img,blur); 
    111110        if(val==0) 
    112111                { 
     
    149148    matrix_to_pgm (&polly_img); 
    150149#endif 
    151     generate_polly_histogram (&polly_img, range); 
     150    generate_polly_histogram (&polly_img, config.histogram); 
    152151   
    153     x_axis = malloc(polly_img.width); 
     152    /*x_axis = malloc(polly_img.width); 
    154153    for(i=0; i<polly_img.width; i++ ) 
    155154        x_axis[i]=i; 
    156155     
    157156 
    158      lreg(x_axis, range, polly_img.width,&reg_line); 
     157     lreg(x_axis, config.histogram, polly_img.width,&reg_line); 
    159158 
    160159     printf( "a=%f\n",reg_line.a );      
     
    166165     printf( "distance = %f\n",distance );  
    167166     
    168     convert_histogram_to_ppm (&polly_img, range); 
     167    convert_histogram_to_ppm (&polly_img, config.histogram); 
    169168 
    170169 
     
    176175    printf( "H " ); 
    177176    for(int i=5; i<polly_img.width; i+=5) 
    178             printf( "%d ",polly_img.height-range[i] ); 
     177            printf( "%d ",polly_img.height-config.histogram[i] ); 
    179178    printf( "\r" ); 
    180  
     179*/ 
    181180 
    182181  free (img.pix);               // don't forget to free! 
    183182  free (polly_img.pix);                
    184   free (x_axis);              
    185   free (range);                
     183 // free (x_axis);              
    186184 
    187185} 
     
    406404      break; 
    407405  } 
     406 
     407  // Downsample Histogram  
     408//  for (x = 0; x < width - 5; x += 5) { 
     409//    int min; 
     410//    min = 100; 
     411//    for (int i = 0; i < 5; i++) { 
     412//      if (hist[x + i] < min) 
     413//        min = hist[x + i]; 
     414//    } 
     415//    for (int i = 0; i < 5; i++) 
     416//      hist[x + i] = min; 
     417// } 
     418 
     419 
     420} 
    408421/* 
    409   // Downsample Histogram  
    410   for (x = 0; x < width - 5; x += 5) { 
    411     int min; 
    412     min = 100; 
    413     for (int i = 0; i < 5; i++) { 
    414       if (hist[x + i] < min) 
    415         min = hist[x + i]; 
    416     } 
    417     for (int i = 0; i < 5; i++) 
    418       hist[x + i] = min; 
    419   } 
    420 */ 
    421  
    422  
    423  
    424  
    425 } 
    426  
    427422void convert_histogram_to_ppm (cc3_image_t * img, uint8_t * hist) 
    428423{ 
     
    448443  } 
    449444} 
    450  
     445*/ 
    451446 
    452447 
  • trunk/projects/polly/polly.h

    r333 r349  
     1#ifndef _POLLY_H_ 
     2#define _POLLY_H_ 
     3 
    14// Constants for connected component blob reduce 
    25#define SELECTED        255 
     
    1518        uint8_t vertical_edges; 
    1619        uint8_t blur; 
     20        uint8_t *histogram; 
    1721} polly_config_t; 
    1822 
     
    2327} ccr_config_t; 
    2428 
    25 ccr_config_t g_cc_conf; 
    2629 
    2730int polly( polly_config_t config); 
     
    3538 
    3639 
    37  
     40#endif