Changeset 418

Show
Ignore:
Timestamp:
02/17/07 18:24:56 (2 years ago)
Author:
anthony_rowe
Message:

Get Histogram

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/cc3-ilp/Makefile

    r380 r418  
    22LIBS += jpeg-6b 
    33 
    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 
     4CSOURCES = 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 cc3_histogram.c 
    55 
    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 
     6INCLUDES = 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 cc3_histogram.h 
    77 
    88 
  • trunk/projects/cmucam2/cmucam2.c

    r417 r418  
    33#include <cc3_color_track.h> 
    44#include <cc3_color_info.h> 
     5#include <cc3_histogram.h> 
    56#include <math.h> 
    67#include <stdbool.h> 
     
    4748  DOWN_SAMPLE, 
    4849  GET_POLLY, 
     50  GET_HISTOGRAM, 
    4951  TRACK_WINDOW, 
    5052  GET_TRACK, 
     
    5860char *cmucam2_cmds[CMUCAM2_CMD_END]; 
    5961 
     62static void cmucam2_get_histogram(cc3_histogram_pkt_t *h_pkt, bool poll_mode, bool quite); 
    6063static void cmucam2_get_mean (cc3_color_info_pkt_t * t_pkt, 
    6164                              bool poll_mode, 
     
    7073static void print_NCK (void); 
    7174static void cmucam2_write_t_packet (cc3_track_pkt_t * pkt); 
     75static void cmucam2_write_h_packet (cc3_histogram_pkt_t *pkt); 
    7276void cmucam2_send_image_direct (bool auto_led); 
    7377 
     
    8084  cc3_track_pkt_t t_pkt; 
    8185  cc3_color_info_pkt_t s_pkt; 
     86  cc3_histogram_pkt_t h_pkt; 
    8287 
    8388  set_cmucam2_commands (); 
     
    8792  poll_mode = false; 
    8893  line_mode = false; 
     94  h_pkt.bins=28; 
    8995  t_pkt.track_invert = false; 
    9096  t_pkt.noise_filter = 0; 
     
    149155 
    150156     case LED_0: 
    151         if (n != 1 && arg_list[0]>2 ) { 
     157        if (n != 1 || arg_list[0]>2 ) { 
    152158          error = true; 
    153159          break; 
     
    195201  
    196202     case TRACK_INVERT: 
    197         if (n != 1 && arg_list[0]>1 ) { 
     203        if (n != 1 || arg_list[0]>1 ) { 
    198204          error = true; 
    199205          break; 
     
    436442        break; 
    437443 
     444         
     445      case GET_HISTOGRAM: 
     446        if (n != 1 || arg_list[0]>2) { 
     447          error = true; 
     448          break; 
     449        } 
     450        else 
     451          print_ACK (); 
     452          h_pkt.channel=arg_list[0]; 
     453          cmucam2_get_histogram(&h_pkt, poll_mode, 0); 
     454        break; 
     455 
    438456 
    439457      case SET_SERVO: 
     
    501519  free(row); 
    502520} 
     521 
     522void cmucam2_get_histogram(cc3_histogram_pkt_t *h_pkt, bool poll_mode, bool quite) 
     523{ 
     524  cc3_image_t img; 
     525  img.channels = 3; 
     526  img.width = cc3_g_pixbuf_frame.width; 
     527  img.height = 1;               // image will hold just 1 row for scanline processing 
     528  img.pix = malloc (3 * img.width); 
     529  h_pkt->hist=malloc(h_pkt->bins*sizeof(uint32_t)); 
     530  do { 
     531    cc3_pixbuf_load (); 
     532    if (cc3_histogram_scanline_start (h_pkt) != 0) { 
     533      while (cc3_pixbuf_read_rows (img.pix, 1)) { 
     534        cc3_histogram_scanline (&img, h_pkt); 
     535      } 
     536      cc3_histogram_scanline_finish (h_pkt); 
     537      while (!cc3_uart_has_data (0)) { if(fgetc(stdin)=='\r' ) free(img.pix); free(h_pkt->hist); return; } 
     538      if(!quite) cmucam2_write_h_packet (h_pkt); 
     539    } 
     540    if (!cc3_uart_has_data (0)) 
     541    { 
     542      if(fgetc(stdin)=='\r' ) 
     543        break; 
     544    } 
     545  } while (!poll_mode); 
     546 
     547  free (img.pix); 
     548  free (h_pkt->hist); 
     549 
     550 
     551} 
     552 
    503553 
    504554void cmucam2_get_mean (cc3_color_info_pkt_t * s_pkt, 
     
    633683} 
    634684 
     685void cmucam2_write_h_packet (cc3_histogram_pkt_t *pkt) 
     686{ 
     687uint32_t i; 
     688uint32_t total_pix; 
     689 
     690  total_pix=cc3_g_pixbuf_frame.width*cc3_g_pixbuf_frame.height; 
     691  printf ("H" ); 
     692  for(i=0; i<pkt->bins; i++ ) 
     693  { 
     694        pkt->hist[i]=(pkt->hist[i]*256)/total_pix; 
     695        if(pkt->hist[i]>255) pkt->hist[i]=255; 
     696        printf( " %d",pkt->hist[i] ); 
     697  } 
     698 printf( "\r" );  
     699} 
     700 
    635701void cmucam2_write_s_packet (cc3_color_info_pkt_t * pkt) 
    636702{ 
     
    674740  cmucam2_cmds[NOISE_FILTER] = "NF"; 
    675741  cmucam2_cmds[GET_TRACK] = "GT"; 
     742  cmucam2_cmds[GET_HISTOGRAM] = "GH"; 
    676743  cmucam2_cmds[LED_0] = "L0"; 
    677744  cmucam2_cmds[TRACK_INVERT] = "TI"; 
     
    691758  *cmd = 0; 
    692759  c = 0; 
    693   while (c != '\r' && c != '\n') { 
     760  while (c != '\r' ) { 
    694761    c = fgetc (stdin); 
    695762    if (length < (MAX_LINE - 1)) {