Changeset 158

Show
Ignore:
Timestamp:
03/04/06 13:01:36 (3 years ago)
Author:
anthony_rowe
Message:

get mean added to cmucam2 prject

Files:

Legend:

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

    r157 r158  
    1414{ 
    1515 pkt->mean.channel[i]=0; 
     16 pkt->scratch_mean[i]=0; 
    1617 pkt->deviation.channel[i]=0; 
     18 pkt->min.channel[i]=255; 
     19 pkt->max.channel[i]=0; 
    1720} 
    1821pkt->scratch_x=0; 
     
    3336        cc3_get_pixel( img, x, 0, &cp );         
    3437        if(cc3_g_current_frame.coi==CC3_ALL ) {  
    35          
     38                uint8_t i; 
     39                for(i=0; i<3; i++ ) 
     40                { 
     41                pkt->scratch_mean[i]+=cp.channel[i]; 
     42                if(cp.channel[i]<pkt->min.channel[i]) pkt->min.channel[i]=cp.channel[i];         
     43                if(cp.channel[i]>pkt->max.channel[i]) pkt->max.channel[i]=cp.channel[i]; 
     44                }        
    3645         
    3746        } else 
    3847        { 
    39          
    40          
     48            uint8_t i; 
     49                i=cc3_g_current_frame.coi; 
     50                pkt->scratch_mean[i]+=cp.channel[i]; 
     51                if(cp.channel[i]<pkt->min.channel[i]) pkt->min.channel[i]=cp.channel[i];         
     52                if(cp.channel[i]>pkt->max.channel[i]) pkt->max.channel[i]=cp.channel[i]; 
    4153        } 
    4254 
     
    5264uint8_t cc3_color_info_scanline_finish(cc3_color_info_pkt_t *pkt) 
    5365{ 
     66uint8_t i; 
     67for(i=0; i<3; i++ ) 
     68{ 
     69        pkt->deviation.channel[i]=((pkt->max.channel[i]-pkt->mean.channel[i])+ 
     70                (pkt->mean.channel[i]-pkt->min.channel[i]))/2; 
     71} 
    5472 
    5573return 1; 
  • trunk/lib/cc3_ilp/cc3_color_info.h

    r157 r158  
    1111    cc3_pixel_t mean; 
    1212    cc3_pixel_t deviation; 
     13    cc3_pixel_t min,max; 
    1314    uint16_t scratch_x,scratch_y; 
     15    uint32_t scratch_mean[3]; 
    1416} cc3_color_info_pkt_t; 
    1517 
  • trunk/projects/cmucam2/cmucam2.c

    r155 r158  
    22#include <cc3_ilp.h> 
    33#include <cc3_color_track.h> 
     4#include <cc3_color_info.h> 
    45#include <math.h> 
    56#include <stdbool.h> 
     
    3233char *cmucam2_cmds[CMUCAM2_CMD_END]; 
    3334 
     35void cmucam2_get_mean(cc3_color_info_pkt_t *t_pkt, uint8_t poll_mode, uint8_t line_mode  ); 
     36void cmucam2_write_s_packet(cc3_color_info_pkt_t *pkt); 
    3437void cmucam2_track_color(cc3_track_pkt_t *t_pkt, uint8_t poll_mode, uint8_t line_mode  ); 
    3538int32_t cmucam2_get_command(int32_t *cmd, int32_t *arg_list); 
     
    4649uint8_t error,poll_mode,line_mode; 
    4750cc3_track_pkt_t t_pkt; 
     51cc3_color_info_pkt_t s_pkt; 
    4852     
    4953    set_cmucam2_commands(); 
     
    120124            break;  
    121125        case TRACK_COLOR: 
    122             { 
    123126            if(n!=0 && n!=6) { error=1; break; } else print_ACK(); 
    124127            if(n==6) 
     
    133136            cmucam2_track_color(&t_pkt, poll_mode, line_mode  ); 
    134137            break; 
     138 
     139        case GET_MEAN: 
     140                if(n!=0) { error=1; break; } else print_ACK(); 
     141                cmucam2_get_mean(&s_pkt, poll_mode, line_mode  ); 
     142            break; 
    135143        case SET_SERVO: 
    136144            if(n!=2) { error=1; break; } else print_ACK(); 
    137145            cc3_servo_set(arg_list[0], arg_list[1] );  
    138             } 
    139146            break; 
    140147        default: 
     
    154161} 
    155162 
    156  
     163void cmucam2_get_mean(cc3_color_info_pkt_t *s_pkt, uint8_t poll_mode, uint8_t line_mode  ) 
     164
     165cc3_image_t img; 
     166uint16_t i; 
     167            img.channels=3; 
     168            img.width=cc3_g_current_frame.width; 
     169            img.height=1;  // image will hold just 1 row for scanline processing 
     170            img.pix = malloc(3 * img.width); 
     171            do  
     172            { 
     173                cc3_pixbuf_load(); 
     174                if(cc3_color_info_scanline_start(s_pkt)!=0 ) 
     175                { 
     176                        for(i=0; i<cc3_g_current_frame.height; i++ ) 
     177                        { 
     178                        cc3_pixbuf_read_rows(img.pix, img.width, 1);     
     179                        cc3_color_info_scanline(&img, s_pkt); 
     180                        } 
     181                        cc3_color_info_scanline_finish(s_pkt); 
     182                        cmucam2_write_s_packet(s_pkt); 
     183                } 
     184                if(!cc3_uart_has_data(0) ) break; 
     185            } while(poll_mode!=1); 
     186             
     187            free(img.pix);  
     188
    157189 
    158190void cmucam2_track_color(cc3_track_pkt_t *t_pkt, uint8_t poll_mode, uint8_t line_mode  ) 
     
    239271} 
    240272 
     273void cmucam2_write_s_packet(cc3_color_info_pkt_t *pkt) 
     274{ 
     275printf( "S %d %d %d %d %d %d\r", pkt->mean.channel[0], pkt->mean.channel[1], 
     276                pkt->mean.channel[2], pkt->deviation.channel[0], pkt->deviation.channel[1],  
     277                pkt->deviation.channel[2]); 
     278 
     279} 
    241280 
    242281void print_ACK()