Rose-Hulman Robotics Team

Changeset 217

Show
Ignore:
Timestamp:
09/28/08 16:52:19 (3 years ago)
Author:
spenceal
Message:

commenting vision.h, moving jaus code

Location:
trunk/software/rb
Files:
1 added
2 modified
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/software/rb/vision/pathplan.c

    r213 r217  
    115115                                                lines[cur_line].end.x = xe; 
    116116                                                lines[cur_line].end.y = ye; 
    117                                                 lines[cur_line].len = sqrt((xs-xe)*(xs-xe) + (ys-ye)*(ys-ye)); 
    118117                                                cur_line++; 
    119118                                        } 
  • trunk/software/rb/vision/vision.h

    r214 r217  
    2727        CvPoint start; 
    2828        CvPoint end; 
    29         int len; 
    3029} CvLine; 
    3130 
     
    3332 
    3433/* Structs and constants */ 
    35 /* Pixle byte orders */ 
     34/* 
     35 * Pixel byte orders 
     36 * This represents the orders in which OpenCV stores pixels 
     37 * The union lets us access everything as the same type but still use sensical 
     38 * names 
     39 */ 
    3640typedef union { 
    37         struct {  
    38                 uint8_t b; 
    39                 uint8_t g; 
    40                 uint8_t r; 
     41        struct { 
     42                uint8_t b; // Blue 
     43                uint8_t g; // Green 
     44                uint8_t r; // Red 
    4145        } __attribute__ ((packed)) bgr; 
    4246        struct { 
    43                 uint8_t h; 
    44                 uint8_t s; 
    45                 uint8_t v; 
     47                uint8_t h; // Hue 
     48                uint8_t s; // Saturation 
     49                uint8_t v; // Value 
    4650        } __attribute__ ((packed)) hsv; 
    4751} __attribute__ ((packed)) px_t; 
    4852 
    49 /* limits on pixel values, used for threshnold stuff */ 
     53/* 
     54 * Limits on pixel values, used for threshnold stuff 
     55 * 
     56 * For a pixel to be classified as beloging to `target' it must be inbetween 
     57 * min and max. We use HSV for this because it allows us to cluster things more 
     58 * effectively than BGR. 
     59 */ 
    5060typedef struct { 
    5161        uint8_t hue_min; uint8_t hue_max; 
    5262        uint8_t sat_min; uint8_t sat_max; 
    5363        uint8_t val_min; uint8_t val_max; 
    54         px_t target; // What to set this pixel to if it's found 
     64        px_t target; 
    5565} px_params_t; 
    5666 
    57 /* Callback function for classifying pixles */ 
     67/* 
     68 * Callback function tyep for classifying pixels 
     69 * 
     70 * Actual callback functions should be named get_<what> where what represents 
     71 * the thing that thye classify. 
     72 * 
     73 * \param in        Raw input imaged (check this) 
     74 * \param out       Image as it has been clasified so far (check this) 
     75 * \param x         X value of the pixle to look at 
     76 * \param y         Y value of the pixle to look at 
     77 * \param px_params Parameters to classify based on 
     78 * \retval A PX_??? that represents how pixle (x,y) should be classified 
     79 */ 
    5880typedef px_t (*get_type_cb_t)(const IplImage *, IplImage *, int, int, 
    5981                              px_params_t); 
    6082 
    61 /* Standard pixel values */ 
     83/* 
     84 * Standard pixel values 
     85 * 
     86 * The classified image will be represented by these colors 
     87 */ 
    6288const static px_t PX_SKY      = {.bgr = {.r =  0, .g =  0, .b = -1}}; // Blue 
    6389const static px_t PX_GRASS    = {.bgr = {.r =  0, .g = -1, .b =  0}}; // Green 
     
    6995 
    7096 
    71 /* Function API */ 
    72 /* Utiltiies */ 
     97/*** Function API ***/ 
     98 
     99/** 
     100 * Utilities 
     101 **/ 
     102 
     103/* 
     104 * Find the first non-grass point starting at `start' 
     105 * Each time, increment y by `1' and x by `x_inc', 
     106 * 
     107 * This is useful for determining how far the robot could move from point 
     108 * `start' in a particlar directoin before running into an obsticle. 
     109 */ 
    73110CvPoint  find_obsticle     (IplImage *out, CvPoint2D32f start, float x_inc); 
     111 
     112/* 
     113 * Determine if the path between points `start' and `end' is clear. That is, 
     114 * returnt true if and only if every point between start and end consists of 
     115 * grass. 
     116 */ 
    74117int      is_clear          (IplImage *out, CvPoint start, CvPoint end); 
     118 
     119/* 
     120 * Return a point leftmost occurance of `target' at a particular horizontal (y) 
     121 * line. This scanns all points (x = 0..width, y = y_line) in the image `out' 
     122 * and returns the first point that is of the type `target. 
     123 */ 
    75124CvPoint  find_px_at_y      (IplImage *out, int y_line, px_t target); 
     125 
     126/* 
     127 * Attempt to find fit a slope to a line in a given box. 
     128 * 
     129 * The goal of this function is to return a mathematical representation of a 
     130 * course boundry so that the slope of a line at that point can be exteded in 
     131 * order to fill in gaps that occure in the line. 
     132 */ 
    76133double   find_slope_in_box (IplImage *out, CvRect box, 
    77134                            go_regression_stat_t *reg); 
    78135 
    79 /* runs callback for mark_* */ 
     136/* 
     137 * Runs callback functions for mark_* 
     138 * 
     139 * Each callback funcion only specifies the type for a particular pixle. This 
     140 * function loops though all pixels in the input image in order to generate a 
     141 * complete output image. It calls `get_type_cb' once for each pixle in the 
     142 * image. 
     143 * 
     144 * \param in          Input  image in HSV colorspace 
     145 * \param out         Output image in BGR colorspace 
     146 * \param px_params   Pixel parameters to pass to the get_type_cb function. 
     147 *                    This allows the same get_type_cb to be tweeked for the 
     148 *                    particular color of the grass/lines, etc. 
     149 * \param get_type_cb The callback function to call for each pixel. 
     150 */ 
    80151px_t     mark_type         (const IplImage *in, IplImage *out, 
    81152                            px_params_t px_params, get_type_cb_t get_type_cb); 
    82153 
    83154 
    84 /* Grass/obsticle/sky finding */ 
     155 
     156/** 
     157 * Grass, Sky, Obsticle finding 
     158 **/ 
     159 
     160/* 
     161 * Callback function for detecting grass, sky, and obsticles. 
     162 * 
     163 * This is the first callback issued. It works by determining if the pixel in 
     164 * question matches the given pixel parameters, if so it is designated as 
     165 * grass, otherwise it is designated as an obsticle. 
     166 * 
     167 * The exception to this is if the pixel is above the horizon, in that case it 
     168 * is designated as sky. 
     169 * 
     170 * See get_type_cb_t for parameter details 
     171 */ 
    85172px_t     get_grass         (const IplImage *in, IplImage *out, int x, int y, 
    86173                            px_params_t px_params); 
     174 
     175// TODO: Discuss the flow (mark_grass -> mark_type -> get_grass) 
     176/* 
     177 * Mark all grass in the input image as grass in the output image. 
     178 * 
     179 * For any pixel in the input image that is grass write a green pixel to the 
     180 * output image. 
     181 */ 
    87182void     mark_grass        (const IplImage *in, IplImage *out); 
    88183 
    89 /* Line finding */ 
     184 
     185 
     186/** 
     187 * Line finding 
     188 **/ 
     189 
     190/* 
     191 * Determine whether a pixel is a line. This based mostly on the HSV value of 
     192 * the pixels but also does some more advanced logic to prevent barrels and 
     193 * such from being incorrectly shown as lines. 
     194 * 
     195 * See get_type_cb_t for parameter details 
     196 */ 
    90197px_t     get_lines         (const IplImage *in, IplImage *out, int x, int y, 
    91198                            px_params_t px_params); 
     199 
     200/* 
     201 * Mark all lines as in the image, this may call call get_type/get_lines for 
     202 * both white and yellow lines. 
     203 */ 
    92204void     mark_lines        (const IplImage *in, IplImage *out); 
     205 
     206/* 
     207 * Expand lines to fill gaps 
     208 * 
     209 * This expands lines so that small areas in the lines that were missed get 
     210 * filled in. This also helps to keep the robot a little bit away from the 
     211 * actual line. 
     212 */ 
    93213void     expand_lines      (const IplImage *o1, IplImage *o2); 
     214 
     215/* 
     216 * This partitions the image into a grid of boxes and attempts to draw the 
     217 * slope of the white line in each box. This is mostly used for debugging 
     218 * find_slope_in_box at the moment. 
     219 */ 
    94220void     mark_slopes       (IplImage *out); 
    95221 
    96 /* Path planning */ 
    97 CvPoint  get_path_strait   (IplImage *out, CvPoint goal); 
    98 CvPoint  get_path_left     (IplImage *out, int dist_limit); 
    99 CvLine  *get_path_curvey   (IplImage *out, CvPoint goal, int *nlines); 
    100  
    101 /* Debuggin */ 
     222 
     223 
     224/** 
     225 * Debuggin 
     226 **/ 
     227 
     228/* 
     229 * Print out an image in a textual format so that it can be imported into other 
     230 * software such as gnuplot or Weka. 
     231 */ 
    102232void print_image(IplImage *img); 
     233 
     234/* 
     235 * Prints out the given label as well as a timestamps for the current time. 
     236 * This is used for profiling the software 
     237 */ 
    103238void print_time(char *label); 
    104239 
    105240 
    106241 
    107 /* Pixel access functions */ 
     242/** 
     243 * Pixel access functions 
     244 * 
     245 * IplImages as a 1d array of bytes, this makes it slightly tricky because each 
     246 * pixel is 3 bytes and offsets have to be calculated manually. 
     247 **/ 
     248 
     249/* 
     250 * Determine whether px1 is identical to px2 
     251 */ 
    108252inline int   IS_PX(px_t px1, px_t px2); 
     253 
     254/* 
     255 * Fetch a pixel out of an IplImage. 
     256 */ 
    109257inline px_t GET_PX(const IplImage *img, int x, int y); 
     258 
     259/* 
     260 * Set a pixel (x,y) in the IplImage to `val' 
     261 */ 
    110262inline void SET_PX(IplImage *img, int x, int y, px_t val); 
    111263