Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phautoblob.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU General Public License for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifndef _PHAUTOBLOB_H
00027 #define _PHAUTOBLOB_H
00028 
00029 #include <stdint.h>
00030 #include <ImageDefinitions.h>
00031 
00032 /* ---------------------------------------------------------------------- */
00033 #ifdef __cplusplus
00034 extern "C" 
00035 {
00036 #endif
00037 
00038 /* ------------------------------------------------------------------------ */
00039 typedef struct auto_coord_t
00040 {
00041     uint32_t x;
00042     uint32_t y;
00043 } auto_coord_type;
00044 
00045 /* ------------------------------------------------------------------------ */
00046 #define phSEGMENT_CONNECTION_COUNT 6
00047 typedef struct auto_line_s
00048 {
00049     int32_t     index;
00050     uint32_t    length;
00051 
00052     auto_coord_type  a;
00053     auto_coord_type  b;
00054 
00055     /* for use only in the row_ptr_array */
00056     /* These don't denote that the lines linked to are actually part
00057      * of a blob; only that the lines belong to the same row */
00058     struct auto_line_s  *next;
00059     int32_t         next_index;
00060     struct auto_line_s  *previous;
00061     int32_t         previous_index;
00062 
00063     /* 1.) For use as blob linked segments */
00064     /* a.) connects the ends of each series of segments */
00065     /* the last_* pointers are used during traversal */
00066     struct auto_line_s *last_up; 
00067     struct auto_line_s *last_down;
00068     /* b.) connects the first segments of each series */
00069     struct auto_line_s *first_up;
00070     struct auto_line_s *first_down;
00071     /* c.) left/right connections within a series */
00072     /* These are also used in traversal */
00073     struct auto_line_s *left;
00074     struct auto_line_s *right;
00075     
00076     /* Can be used to reconstruct the pointers above when
00077      * all the segments are stored in an array (for example,
00078      * the way they are stored in the line pool). This is 
00079      * useful only when MEMCPYing the line pool to another
00080      * memory segment, at which point all the pointers above
00081      * will become invalid. */
00082     int32_t first_up_index;
00083     int32_t first_down_index;
00084     int32_t last_up_index;
00085     int32_t last_down_index;
00086     int32_t left_index;
00087     int32_t right_index;
00088     
00089     /* These are equal to the named pointers/variables above with the 
00090      * exception that they make the code used for traversing a 
00091      * grouping of interconnected line segments */
00092     struct auto_line_s  *connection[phSEGMENT_CONNECTION_COUNT];
00093     int32_t             connection_index[phSEGMENT_CONNECTION_COUNT];
00094 
00095     /* Blob index value; Used when traversing the list of line segments
00096      * to identify blob groupings and it speeds searching also */
00097     /* Instead of wasting half the bit space available for the sole 
00098      * reason of having -1 as a value, MAX_INT will be used to denote
00099      * no blob grouping ID */
00100     int32_t blob_index; /* MAX_INT == no blob */
00101    
00102     /* Used in the iterative traversing of the line segment connections
00103      * to identify membership in a blob. These are made part of the 
00104      * structure for the case where user code wants to traverse as well,
00105      * not as much extra setup is required. This does add to memory
00106      * usage though.*/
00107     uint32_t        visited;
00108     struct auto_line_s  *previous_visit;
00109     int32_t         previous_visit_index; /* INT_MAX == no previous */
00110 
00111     int32_t         value_low[phCOLOR_MAXELEMS];
00112     int32_t         value[phCOLOR_MAXELEMS];
00113     int32_t         value_high[phCOLOR_MAXELEMS];
00114     
00115 } auto_line_segment;
00116 
00117 /* Helper macros for the 'connections' array */
00118 /* The values are reordered compared to the order of the named pointer/variables
00119  * because of the traversal algorithm. The unused connections are still kept
00120  * around for consistency */
00121 /* Order of traversal Right:0,Up:1,Left:2,Down:3 */
00122 #define LAST_UP_VAL     (1)
00123 #define LAST_DOWN_VAL   (3)
00124 #define FIRST_UP_VAL    (4) /* not 1, not used in traversal */
00125 #define FIRST_DOWN_VAL  (5) /* not 3, not used in traversal */
00126 #define LEFT_VAL        (2)
00127 #define RIGHT_VAL       (0)
00128 
00129 /* These are never modified */
00130 #define OPPOSITE_DIR_BIT(dir)       (1<<((dir+2) %4))
00131 
00132 #define LAST_UP_PTR(segptr)         (segptr->connection[LAST_UP_VAL])
00133 #define LAST_DOWN_PTR(segptr)       (segptr->connection[LAST_DOWN_VAL])
00134 #define UP_PTR(s)                   LAST_UP_PTR(s)
00135 #define DOWN_PTR(s)                 LAST_DOWN_PTR(s)
00136 #define FIRST_UP_PTR(segptr)        (segptr->connection[FIRST_UP_VAL])
00137 #define FIRST_DOWN_PTR(segptr)      (segptr->connection[FIRST_DOWN_VAL])
00138 #define LEFT_PTR(segptr)            (segptr->connection[LEFT_VAL])
00139 #define RIGHT_PTR(segptr)           (segptr->connection[RIGHT_VAL])
00140 
00141 #define LAST_UP_INDEX(segptr)       (segptr->connection_index[LAST_UP_VAL])
00142 #define LAST_DOWN_INDEX(segptr)     (segptr->connection_index[LAST_DOWN_VAL])
00143 #define UP_INDEX(s)                 LAST_UP_INDEX(s)
00144 #define DOWN_INDEX(s)               LAST_DOWN_INDEX(s)
00145 #define FIRST_UP_INDEX(segptr)      (segptr->connection_index[FIRST_UP_VAL])
00146 #define FIRST_DOWN_INDEX(segptr)    (segptr->connection_index[FIRST_DOWN_VAL])
00147 #define LEFT_INDEX(segptr)          (segptr->connection_index[LEFT_VAL])
00148 #define RIGHT_INDEX(segptr)         (segptr->connection_index[RIGHT_VAL])
00149 
00150 #if 0
00151 /* Order fo visiting: Right, Up, Left, Down (think "Karel the Robot") */
00152 typedef enum visited_e
00153 {
00154     RightVisited    = (1<<0),
00155     UpVisited       = (1<<1),
00156     LeftVisited     = (1<<2),
00157     DownVisited     = (1<<3)
00158 } visited_enum;
00159 #endif
00160 /* ------------------------------------------------------------------------ */
00161 typedef struct phautoblob_t 
00162 {
00163     int32_t     index;
00164     uint32_t    mass; /* number of pixels covered */
00165 
00166     /* first segment visited */
00167     /* last segment visited */
00168     /* These could be used as starting points for traversing the line
00169      * blob grouping in two different directions */
00170     auto_line_segment   *first_segment;
00171     auto_line_segment   *last_segment;
00172     int32_t         first_segment_index;
00173     int32_t         last_segment_index;
00174 
00175     uint32_t cx;
00176     uint32_t cy;
00177     uint32_t x1;
00178     uint32_t y1;
00179     uint32_t x2;
00180     uint32_t y2;
00181     uint32_t w;
00182     uint32_t h;
00183 
00184     struct phautoblob_t*    next;
00185     struct phautoblob_t*    previous;
00186     
00187     int32_t             next_index;
00188     int32_t             previous_index;
00189     
00190     int32_t         value           [phCOLOR_MAXELEMS];
00191     int32_t         value_low       [phCOLOR_MAXELEMS];
00192     int32_t         value_high      [phCOLOR_MAXELEMS];
00193 
00194 } phautoblob;
00195 
00196 /* ------------------------------------------------------------------------ */
00197 typedef struct phautoblob_data_t
00198 {
00199     uint32_t            nlines;
00200     auto_line_segment  *lines;
00201     uint32_t            lines_size;
00202 
00203     uint32_t            nrows;
00204     auto_line_segment **rows;
00205     uint32_t            rows_size;
00206     int32_t            *rowindex;
00207     uint32_t            rowindex_size;    
00208 
00209     uint32_t            nblobs;
00210     phautoblob         *blobs;
00211     uint32_t            blobs_size;
00212 
00213 #define phBLOB_COLOR (0)
00214 #define phBLOB_NEIGHBOR (1)
00215     int32_t             blob_method;
00216     
00217 } phautoblob_data;
00218 
00219 /* ------------------------------------------------------------------------ */
00220 typedef struct phautoblob_args_t
00221 {
00222     uint8_t           **imgptr;
00223     uint32_t            width;
00224     uint32_t            height;
00225     uint8_t             depth;
00226     uint32_t            format;
00227 
00228     uint32_t            color_count;
00229     phColor           **incolor;
00230     phColor           **threshold;
00231     volatile uint32_t  *nColors;
00232  
00233     int32_t             lower_threshold [phCOLOR_MAXELEMS];
00234     int32_t             upper_threshold [phCOLOR_MAXELEMS];
00235     int32_t             loop_threshold  [phCOLOR_MAXELEMS];
00236 
00237 } phautoblob_args;
00238 
00239 /* ---------------------------------------------------------------------- */
00240 /*
00241    phblob_new
00242 
00243    phblob_args_get / phblob_args_set
00244    image_settings
00245     imgptr
00246     width
00247     height
00248     depth
00249     format
00250    
00251    color_count
00252    incolor_ptr
00253    threshold_ptr
00254    nColors
00255 
00256    total_lines
00257    line_array
00258    line_array_size
00259 
00260    rowptr_array_ptr
00261    rowptr_array_size
00262 
00263    row_index_array_ptr
00264    row_index_array_size
00265 
00266    lower_threshold
00267    upper_threshold
00268    loop_threshold
00269  */
00270 /* --------------------------------------------------------------------- */
00271 int phautoblob_data_new  ( phautoblob_data **data );
00272 int phautoblob_data_init ( phautoblob_data *data  );
00273 int phautoblob_data_reset( phautoblob_data *data  );
00274 int phautoblob_data_free ( phautoblob_data **data );
00275 int phautoblob_data_copy ( phautoblob_data *in,
00276                            phautoblob_data *out);
00277 
00278 /* --------------------------------------------------------------------- */
00279 int phautoblob_data_relink_line_ptrs( phautoblob_data *data );
00280 
00281 /* --------------------------------------------------------------------- */
00282 int phautoblob_find_line_segments_color     ( phautoblob_args *args,
00283                                               phautoblob_data *data );
00284 int phautoblob_find_line_segments_neighbor  ( phautoblob_args *args,
00285                                               phautoblob_data *data );
00286 int phautoblob_link_line_segments           ( phautoblob_args *args,
00287                                               phautoblob_data *data );
00288 
00289 /* --------------------------------------------------------------------- */
00290 #define phBLOB_DRAW_ALL (1<<0)
00291 /* #define phBLOB_DRAW_LARGEST */
00292 /* #define phBLOB_DRAW_SMALLEST */
00293 #define phBLOB_DRAW_INDEX (1<<1)
00294 #define phBLOB_COLOR_BLACK (1<<2)
00295 /* phBLOB_COLOR_BLACK uses black instead of the passed color */
00296 /* index goes unused unless phBLOB_DRAW_INDEX is specified */
00297 int phautoblob_draw_blob_rects( uint8_t         *imgptr,
00298                                 uint32_t        width,
00299                                 uint32_t        height,
00300                                 uint32_t        format,
00301                                 const phColor   *color,
00302                                 phautoblob_data *data,
00303                                 int32_t         index,
00304                                 uint32_t        min_size,
00305                                 uint32_t        flag );
00306 /* --------------------------------------------------------------------- */
00307 int phautoblob_color_lines(uint8_t         *imgptr,
00308                            uint32_t         width,
00309                            uint32_t         height,
00310                            uint32_t         format,
00311                            const phColor   *color,
00312                            phautoblob_data *data,
00313                            uint32_t         blob_min_size,
00314                            uint32_t         index,
00315                            uint32_t         flag );
00316 /* --------------------------------------------------------------------- */
00317 int phautoblob_create_blobs(uint32_t        width,
00318                             uint32_t        height,
00319                             /* creates the blob list in the data object */
00320                             phautoblob_data *data );
00321                                
00322 /* --------------------------------------------------------------------- */
00323 typedef int32_t (*ph_compare_fn)(void *arr, int32_t i, int32_t j);
00324 typedef int32_t (*ph_swap_fn)   (void *arr, int32_t i, int32_t j);
00325 
00326 int phautoblob_sort_blobs( phautoblob_data *data );
00327 
00328 /* ---------------------------------------------------------------------- */
00329 #ifdef __cplusplus
00330 } /* extern "C" */
00331 #endif
00332 
00333 
00334 #endif /* _PHAUTOBLOB_H */




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:06 2007 for phission by  doxygen 1.4.4