Changeset 217
- Timestamp:
- 09/28/08 16:52:19 (3 years ago)
- Location:
- trunk/software/rb
- Files:
-
- 1 added
- 2 modified
- 1 copied
-
jaus (added)
-
jaus/jaus.py (copied) (copied from trunk/software/rb/vision/jaus.py)
-
vision/pathplan.c (modified) (1 diff)
-
vision/vision.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/rb/vision/pathplan.c
r213 r217 115 115 lines[cur_line].end.x = xe; 116 116 lines[cur_line].end.y = ye; 117 lines[cur_line].len = sqrt((xs-xe)*(xs-xe) + (ys-ye)*(ys-ye));118 117 cur_line++; 119 118 } -
trunk/software/rb/vision/vision.h
r214 r217 27 27 CvPoint start; 28 28 CvPoint end; 29 int len;30 29 } CvLine; 31 30 … … 33 32 34 33 /* 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 */ 36 40 typedef 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 41 45 } __attribute__ ((packed)) bgr; 42 46 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 46 50 } __attribute__ ((packed)) hsv; 47 51 } __attribute__ ((packed)) px_t; 48 52 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 */ 50 60 typedef struct { 51 61 uint8_t hue_min; uint8_t hue_max; 52 62 uint8_t sat_min; uint8_t sat_max; 53 63 uint8_t val_min; uint8_t val_max; 54 px_t target; // What to set this pixel to if it's found64 px_t target; 55 65 } px_params_t; 56 66 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 */ 58 80 typedef px_t (*get_type_cb_t)(const IplImage *, IplImage *, int, int, 59 81 px_params_t); 60 82 61 /* Standard pixel values */ 83 /* 84 * Standard pixel values 85 * 86 * The classified image will be represented by these colors 87 */ 62 88 const static px_t PX_SKY = {.bgr = {.r = 0, .g = 0, .b = -1}}; // Blue 63 89 const static px_t PX_GRASS = {.bgr = {.r = 0, .g = -1, .b = 0}}; // Green … … 69 95 70 96 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 */ 73 110 CvPoint 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 */ 74 117 int 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 */ 75 124 CvPoint 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 */ 76 133 double find_slope_in_box (IplImage *out, CvRect box, 77 134 go_regression_stat_t *reg); 78 135 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 */ 80 151 px_t mark_type (const IplImage *in, IplImage *out, 81 152 px_params_t px_params, get_type_cb_t get_type_cb); 82 153 83 154 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 */ 85 172 px_t get_grass (const IplImage *in, IplImage *out, int x, int y, 86 173 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 */ 87 182 void mark_grass (const IplImage *in, IplImage *out); 88 183 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 */ 90 197 px_t get_lines (const IplImage *in, IplImage *out, int x, int y, 91 198 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 */ 92 204 void 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 */ 93 213 void 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 */ 94 220 void mark_slopes (IplImage *out); 95 221 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 */ 102 232 void 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 */ 103 238 void print_time(char *label); 104 239 105 240 106 241 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 */ 108 252 inline int IS_PX(px_t px1, px_t px2); 253 254 /* 255 * Fetch a pixel out of an IplImage. 256 */ 109 257 inline 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 */ 110 262 inline void SET_PX(IplImage *img, int x, int y, px_t val); 111 263

