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

LiveHistogramBlobTest.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003 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  ---------------------------------------------------------------------------*/
00012 
00013 /* ---------------------------------------------------------------------------*/
00014 #include <LiveHistogramBlobTest.h>
00015 #include <phission.h>
00016 
00017 /* for load_histogram_settings */
00018 #if !defined(WIN32)
00019 #if USE_FILETYPE
00020 #else
00021     #include <sys/file.h>
00022     #include <sys/types.h>
00023     #include <sys/stat.h>
00024     #include <fcntl.h>
00025     #include <unistd.h>
00026 #endif
00027 #endif
00028 
00029 /* ------------------------------------------------------------------------ */
00030 int glbl_disable_displays   = 0;
00031 int glbl_print_histogram    = 0;
00032 int glbl_print_blobs        = 0;
00033 int glbl_save_images        = 0;
00034 int glbl_save_color         = 0;
00035 int glbl_load_color         = 0;
00036 
00037 /* ------------------------------------------------------------------------ */
00038 void usage()
00039 {
00040     printf("\n\nUsage:\n"
00041     "\t--help                display usage\n"
00042     "\t--nodisplay           disable the allocation, opening or any use of a display.\n"
00043     "\t--test <value>        loops <value> times before closing the test\n"
00044     "\t--file <filename>     Save the color information using phColorSave\n"
00045     "\t--histfile <filename> Load the histogram algorithm settings\n"
00046     "\t--hsvfile <filename>  load the hsv threshold filter parameters\n"
00047     "\t--saveimages                Save the histogram and blob images to images/\n"
00048     "\n\n");
00049 
00050     exit(1);
00051 }
00052 
00053 /* ------------------------------------------------------------------------ */
00054 #define phLocation_MID_X  (1<<1)
00055 #define phLocation_MID_Y  (1<<2)
00056 #define phLocation_RIGHT  (1<<3)
00057 #define phLocation_LEFT   (1<<4)
00058 #define phLocation_TOP    (1<<5)
00059 #define phLocation_BOTTOM (1<<6)
00060 
00061 /* ---------------------------------------------------------------------- */
00062 int load_histogram_settings( const char   *filename, 
00063                              uint32_t     *x1,
00064                              uint32_t     *y1,
00065                              uint32_t     *x2,
00066                              uint32_t     *y2,
00067                              uint32_t     *bins,
00068                              uint32_t     *drawrect)
00069 {
00070     phFUNCTION("phColorLoad")
00071 
00072     FILE        *fp         = NULL;
00073 
00074     /* open the output file */
00075     fp = fopen(filename, "r");
00076     phCHECK_PTR(fp,"fopen","fopen(%s,\"r\")",filename);
00077 
00078     rc = ph_file_lock(fp);
00079     phPRINT_RC(rc,NULL,"ph_file_lock(%p)",fp);
00080 
00081     rc = fscanf(fp,"%u %u %u %u %u %u", x1, y1, x2, y2, bins, drawrect  );
00082     if (rc == EOF) goto success;
00083         
00084 success:
00085     rc = ph_file_unlock(fp);
00086     phPRINT_RC(rc,NULL,"ph_file_unlock(%p)",fp);
00087 
00088     fclose(fp);
00089     fp = NULL;
00090 
00091     return phSUCCESS;
00092 error:
00093     if (fp != NULL)
00094     {
00095         fclose(fp);
00096     }
00097     return phFAIL;
00098 }
00099 
00100 
00101 /* ------------------------------------------------------------------------ */
00102 void hsvthresh_apply_colors( hsvthreshold_Filter   *hsvthreshold,
00103                              uint32_t              nColors,
00104                              phColor               *colors )
00105 {
00106     /* Set up the hsvthreshold filter */
00107     if (hsvthreshold != NULL)
00108     {
00109         int use_h = 0;
00110         int use_s = 0;
00111         int use_v = 0;
00112         int lh = 0;
00113         int ls = 0;
00114         int lv = 0;
00115         int uh = 0;
00116         int us = 0;
00117         int uv = 0;
00118         uint32_t index = 0;
00119 
00120         /* Use threshold */
00121         if (nColors > index)
00122         {
00123             //phPRINT("\tUse:               ");
00124             //phColorPrint(-1,(*colors)[index]);
00125             use_h = colors[index].array.v[0];
00126             use_s = colors[index].array.v[1];
00127             use_v = colors[index].array.v[2];
00128         }
00129         index++;
00130         /* lower thresholds */
00131         if (nColors > index)
00132         {
00133             //phPRINT("\tLower Threshold:   ");
00134             //phColorPrint(-1,(*colors)[index]);
00135             lh = colors[index].array.v[0];
00136             ls = colors[index].array.v[1];
00137             lv = colors[index].array.v[2];
00138         }
00139         index++;
00140         /* upper thresholds */
00141         if (nColors > index)
00142         {
00143             //phPRINT("\tUpper Threshold:   ");
00144             //phColorPrint(-1,(*colors)[index]);
00145             uh = colors[index].array.v[0];
00146             us = colors[index].array.v[1];
00147             uv = colors[index].array.v[2];
00148         }
00149         
00150         hsvthreshold->lock();
00151         hsvthreshold->set(use_h,use_s,use_v,
00152                         lh,ls,lv,
00153                         uh,us,uv);
00154         hsvthreshold->enable();
00155         hsvthreshold->unlock();
00156     }
00157     else if (hsvthreshold != NULL)
00158     {
00159         hsvthreshold->disable();
00160     }
00161 
00162     //phPRINT("Done with colors.\n\n");
00163 }
00164 
00165 /* ------------------------------------------------------------------------ */
00166 void hsvthresh_load_colors( hsvthreshold_Filter   *hsvthreshold,
00167                             const char            *color_file,
00168                             uint32_t              *nColors,
00169                             phColor               **colors
00170                           )
00171 {
00172     phFUNCTION("hsvthresh_load_colors")
00173     uint32_t i       = 0;
00174     
00175     rc = phColorLoad( color_file, 0, nColors, colors );
00176     phPRINT_RC(rc,NULL,"phColorLoad");
00177 
00178     hsvthresh_apply_colors( hsvthreshold, *nColors, *colors );
00179 }
00180 
00181 /* ------------------------------------------------------------------------ */
00182 int main( int argc, char *argv[] )
00183 {
00184     phFUNCTION("main")
00185 
00186     uint32_t        i           = 0;
00187     uint32_t        j           = 0;
00188 
00189     char            *capture_path   = NULL;
00190     int             channel         = 0;
00191     
00192     /* Display variables */
00193     int             displaysOpen= 1;
00194     char            title[255];
00195  
00196     /* --------------------------------------------------------------------- */
00197     phSystem            system;
00198 #ifdef WIN32
00199     VFWSource           *capture            = new VFWSource();
00200 #else
00201     V4LCapture          *capture            = new V4LCapture();
00202 #endif
00203 
00204     convert_Filter      *hist_convert       = new convert_Filter();
00205     convert_Filter      *blob_convert       = new convert_Filter();
00206     gaussian3x3_Filter  *hist_gauss         = new gaussian3x3_Filter();
00207     gaussian3x3_Filter  *blob_gauss         = new gaussian3x3_Filter();
00208 
00209     phColor             outcolor            = phColorRGB24_new(0,255,255);
00210     
00211     /* --------------------------------------------------------------------- */
00212     /* HSV Threshold variable */
00213     hsvthreshold_Filter *hsvthresh          = new hsvthreshold_Filter(0,0,0);
00214     //hsvthreshold_Filter *hist_hsvthresh     = new hsvthreshold_Filter(0,0,0);
00215     char                *hsvthresh_file     = NULL;
00216     phColor             *hsvthresh_colors   = NULL;
00217     uint32_t            hsvthresh_ncolors   = 0;
00218 
00219     /* --------------------------------------------------------------------- */
00220     /* HISTOGRAM Variables ------------------------------------------------- */
00221     /* fractional size of the main window */
00222     const uint32_t      x_box_fraction  = 7;
00223     const uint32_t      y_box_fraction  = 7;
00224     const uint32_t      box_location    = phLocation_MID_X | phLocation_BOTTOM;
00225    
00226     /* histogram rect coords */
00227     uint32_t            bw = 0;
00228     uint32_t            bh = 0;
00229     uint32_t            x1 = 0;
00230     uint32_t            y1 = 0;
00231     uint32_t            x2 = 0;
00232     uint32_t            y2 = 0;
00233    
00234     /* --------------------------------------------------------------------- */
00235     /* Histogram Variables ------------------------------------------------- */
00236     histogram_Filter    *histogram          = new histogram_Filter();
00237     phHistogramData     *histData           = new phHistogramData();
00238     uint32_t            bins                = 64;
00239     uint32_t            draw_rect           = 1;
00240     char                *histogram_file      = NULL;
00241    
00242     /* --------------------------------------------------------------------- */
00243     /* BLOB Variables ------------------------------------------------------ */
00244     blob_Filter         *blob               = new blob_Filter();
00245     /* default values, blob won't complain; will be changed with hist vals*/
00246     phColor             blob_color          = phColorRGBA32_new(0,0,0,0);
00247     phColor             threshold_color     = phColorRGBA32_new(0,0,0,0);
00248     /* blob data output from the blob filter */
00249     phBlobData          *blobData           = new phBlobData();
00250     const int32_t       min_size            = 100;
00251 
00252     phColor             save_color_array[2];
00253     phColor             *load_color_array = NULL;
00254     char                *filename = NULL;
00255 
00256     /* --------------------------------------------------------------------- */
00257     uint32_t            width       = 320;
00258     uint32_t            height      = 240;
00259     uint32_t            nDisplays   = 4;
00260     phDisplayInterface  **displays  = NULL;
00261     char                *titles[]   = { "capture", 
00262                                         "histogram", 
00263                                         "blob",
00264                                         "histogram_data" };
00265     phLiveObject        *sources[]  = { capture->getLiveSourceOutput(),
00266                                         histogram->getLiveSourceOutput(),
00267                                         blob->getLiveSourceOutput(),
00268                                         histData->getImage() };
00269 
00270     phFilter            *hist_filters[] = { hist_gauss, 
00271                                             hist_convert,
00272                                             //hist_hsvthresh,
00273                                             histogram};
00274     phFilter            *blob_filters[] = { blob_gauss,
00275                                             blob_convert,
00276                                             //hsvthresh,
00277                                             blob};
00278 
00279 
00280     phImage blobimg;
00281     char    blobfilename[255];
00282     int32_t blobcount = 0;
00283     phImage histimg;
00284     char    histfilename[255];
00285     int32_t histcount = 0;
00286 
00287     histimg.connect(histogram->getLiveSourceOutput());
00288     blobimg.connect(blob->getLiveSourceOutput());
00289 
00290     /* --------------------------------------------------------------------- */
00291     uint32_t        nPipelines      = 2;                                        
00292     phPipeline      **pipelines     = NULL;
00293     phFilter        **filters[]     ={ hist_filters, 
00294                                        blob_filters };
00295     uint32_t        nFilters[]      ={ sizeof(hist_filters) / sizeof(phFilter *), 
00296                                        sizeof(blob_filters) / sizeof(phFilter *) };
00297 
00298     phArgTable      *arg_parser = new phArgTable();
00299 
00300     /* Remove the code below when using this code as an example.
00301      * 
00302      * This just checks whether "--test" has been specified with
00303      * a time value argument. It's for testing all the examples
00304      * without the need for human intervention. */
00305     int             test = 0;
00306 
00307     /* Setup and parse all the arguments */
00308     rc = arg_parser->add("--test",&test,phARG_INT);
00309     phCHECK_RC(rc,NULL,"arg_parser->add");
00310     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00311     phCHECK_RC(rc,NULL,"arg_parser->add");
00312     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00313     phCHECK_RC(rc,NULL,"arg_parser->add");
00314     
00315     rc = arg_parser->add("--file",&filename,phARG_CHAR);
00316     phCHECK_RC(rc,NULL,"arg_parser->add");
00317     rc = arg_parser->add("--savecolor",&glbl_save_color,phARG_BOOL);
00318     phCHECK_RC(rc,NULL,"arg_parser->add");
00319     rc = arg_parser->add("--loadcolor",&glbl_load_color,phARG_BOOL);
00320     phCHECK_RC(rc,NULL,"arg_parser->add");
00321     
00322 
00323     rc = arg_parser->add("--histfile",&histogram_file,phARG_CHAR);
00324     phCHECK_RC(rc,NULL,"arg_parser->add");
00325 
00326     rc = arg_parser->add("--hsvfile",&hsvthresh_file,phARG_CHAR);
00327     phCHECK_RC(rc,NULL,"arg_parser->add");
00328 
00329     rc = arg_parser->add("--saveimages",&glbl_save_images,phARG_BOOL);
00330     phCHECK_RC(rc,NULL,"arg_parser->add");
00331     
00332     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00333     phCHECK_RC(rc,NULL,"arg_parser->add");
00334 
00335     rc = arg_parser->add("--channel",&channel,phARG_INT);
00336     phCHECK_RC(rc,NULL,"arg_parser->add");
00337     
00338     rc = arg_parser->parse(argc,argv);
00339     phCHECK_RC(rc,NULL,"arg_parser->parse");
00340 
00341 
00342     if ((glbl_save_color) && (glbl_load_color))
00343     {
00344         phPRINT("You specified both --savecolor and --loadcolor, jerk!\n");
00345         glbl_save_color = glbl_load_color = 0;
00346     }
00347     
00348     if (test > 0)
00349     {
00350         glbl_print_histogram = 0;
00351         glbl_print_blobs = 1;
00352     }
00353     if (glbl_disable_displays) 
00354     {
00355         nDisplays = 0;
00356     }
00357   
00358     /* --------------------------------------------------------------------- */
00359     /* CAPTURES */
00360   
00361     /* Set up the capture class */
00362     capture->set(width,height,capture_path);
00363     capture->setChannel(channel);
00364     capture->setColour(64000);
00365     capture->setHue(65700);
00366 #if 0
00367     capture->setColour(45000);
00368     capture->setHue(32700);
00369 #endif
00370     capture->setContrast(32000);
00371     capture->setBrightness(28000);
00372 
00373     rc = system.add(capture);
00374     phPRINT_RC(rc,NULL,"system.add(capture)");
00375     
00376     /* --------------------------------------------------------------------- */
00377     /* FILTER SETTINGS */
00378    
00379     /* CONVERT */
00380     /* Set the convert filter parameters to convert to HSV before histogramming */
00381     hist_convert->set(phImageHSV24); /* already added to pipeline above */
00382     blob_convert->set(phImageHSV24); /* already added to pipeline above */
00383   
00384     /* HSV thresholding */
00385     if (hsvthresh_file != NULL)
00386     {   
00387         hsvthresh_load_colors( hsvthresh,
00388                                hsvthresh_file,
00389                                &hsvthresh_ncolors,
00390                                &hsvthresh_colors );
00391         //hsvthresh_apply_colors( hist_hsvthresh, hsvthresh_ncolors, hsvthresh_colors );
00392     }
00393     else
00394     {
00395         hsvthresh->set(  0,   0,   0,
00396                          0, 20,  175,
00397                          255, 255, 255);
00398         //hist_hsvthresh->set(  0,   0,   0,
00399         //                      0, 20,  175,
00400         //                    255, 255, 255);
00401     }
00402   
00403     /* HISTOGRAM */
00404     /* Set the histogram parameters */
00405 
00406     if (histogram_file != NULL)
00407     {
00408         load_histogram_settings(histogram_file,&x1,&y1,&x2,&y2,&bins,&draw_rect);
00409     }
00410     else
00411     {
00412         bw = (capture->getWidth() / x_box_fraction);
00413         bh = (capture->getHeight() / y_box_fraction);
00414     
00415         if (box_location & phLocation_RIGHT)
00416         {
00417             x1 = capture->getWidth() - bw;
00418         }
00419         else if (box_location & phLocation_MID_X)
00420         {
00421             x1 = (capture->getWidth() / 2) - (bw / 2);
00422         }
00423         else if (box_location & phLocation_LEFT)
00424         {
00425             x1 = 0;
00426         }
00427 
00428         if (box_location & phLocation_BOTTOM)
00429         {
00430             y1 = capture->getHeight() - bh;
00431         }
00432         else if (box_location & phLocation_MID_Y)
00433         {
00434             y1 = (capture->getHeight() / 2) - (bh / 2);
00435         }
00436         else if (box_location & phLocation_TOP)
00437         {
00438             y1 = 0;
00439         }
00440         x2 = x1 + bw;
00441         y2 = y1 + bh;
00442     }
00443     
00444     rc = histogram->set(x1,/* x1 */
00445                         y1,/* y1 */
00446                         x2,/* x2 */
00447                         y2,/* y2 */
00448                         bins, /* bins */
00449                         draw_rect,/* draw_rect */
00450                         &outcolor /* histogram rectangle output color & format */
00451                         );
00452     phCHECK_RC(rc,NULL,"histogram->set failed");
00453    
00454     /* BLOB */
00455     /* Set the initial blob parameters so it won't complain */
00456     rc = blob->set( &blob_color,
00457                     &threshold_color,
00458                     1,
00459                     &outcolor,
00460                     1,
00461                     1,
00462                     min_size);
00463     phCHECK_RC(rc,NULL,"blob->set failed");
00464     
00465     /* --------------------------------------------------------------------- */
00466     /* DATA OBJECTS */
00467     
00468     /* Connect the blob data and histogram data objects */
00469     rc = blobData->connect(blob->getLiveBlobOutput());
00470     phCHECK_RC(rc,NULL,"blobData->connect()");
00471    
00472     rc = histData->connect(histogram->getLiveHistogramOutput());
00473     phCHECK_RC(rc,NULL,"histData->connect()");
00474 
00475     /* --------------------------------------------------------------------- */
00476     /* PIPELINES */
00477     pipelines = new phPipeline *[nPipelines];
00478     phCHECK_PTR(pipelines,"new","new phPipelines[%d] failed",nPipelines);
00479    
00480     for (i = 0; i < nPipelines; i++ )
00481     {
00482         pipelines[i] = new phPipeline();
00483         phCHECK_PTR(pipelines[i],"new","new phPipline() failed");
00484     
00485         /* Add the pipeline to the system */
00486         rc = system.add(pipelines[i]);
00487         phPRINT_RC(rc,NULL,"system.add(pipelines[%d])",i);
00488 
00489         /* Attach the image to the live source input of the
00490          * Pipeline so processing is done automatically once the 
00491          * pipeline is started. */
00492         rc = pipelines[i]->setLiveSourceInput(capture->getLiveSourceOutput());
00493         phCHECK_RC(rc,NULL,"pipelines[i]->setLiveSourceInput() failed");
00494 
00495         //phPRINT("nFilters[%d]=%d\n",i,nFilters[i]);
00496         /* Add the filter(s) into the pipeline in the order they will be used */
00497         for (j = 0; j < nFilters[i]; j++ )
00498         {
00499             //phPRINT("%d:%d-%s\n",i,j,filters[i][j]->getName());
00500             rc = pipelines[i]->add(filters[i][j]);
00501             phCHECK_RC(rc,NULL,"pipelines[%d]->add(%p) failed",i,filters[j]);
00502         }
00503     }
00504 
00505     /* --------------------------------------------------------------------- */
00506     /* DISPLAYS */
00507 
00508     /* allocate the array */
00509     displays = new phDisplayInterface *[nDisplays];
00510     phCHECK_PTR(displays,"new","new phDisplayInterface *[%d]",nDisplays);
00511 
00512     /* Cycle through the titles/sources arrays and set up the displays */
00513     for (i = 0; i < nDisplays; i++ )
00514     {
00515         sprintf(title,titles[i]);
00516 #if defined(PH_HAVE_X11)
00517         displays[i] = new X11Display(width,height,title);
00518 #elif defined(PH_HAVE_GDI)
00519         displays[i] = new GDIDisplay(width,height,title);
00520 #endif
00521         phCHECK_NULLPTR(displays[i],"new","new X11Display(%d,%d,%s)",width,height,title);
00522 
00523         if (i < 3)
00524             displays[i]->move(20 + (i * (width + 10)),20);
00525 
00526         rc = system.add(displays[i]);
00527         phPRINT_RC(rc,NULL,"system.add(displays[%d])",i);
00528     
00529         rc = displays[i]->setLiveSourceInput(sources[i]);
00530         phCHECK_RC(rc,NULL,"displays[%d]->setLiveSourceInput(sources[i]:%p)",i,sources[i]);
00531     }
00532   
00533     /* --------------------------------------------------------------------- */
00534     /* Startup the system */
00535     rc = system.startup();
00536     phPRINT_RC(rc,NULL,"train_system.startup()");
00537     
00538     /* Keep going until all the windows are closed */
00539    
00540     displaysOpen = 1;
00541     while ((system.displaysOpen() == system.displayCount()) && (displaysOpen))
00542     {
00543         /* Get the most recent histogram data */
00544         rc = histData->update();
00545         phCHECK_RC(rc,NULL,"histData->update() failed");
00546 
00547         /* Continually reload the histogram settings */
00548         if (histogram_file != NULL)
00549         {
00550             load_histogram_settings(histogram_file,&x1,&y1,&x2,&y2,&bins,&draw_rect);
00551             rc = histogram->set(x1,/* x1 */
00552                                 y1,/* y1 */
00553                                 x2,/* x2 */
00554                                 y2,/* y2 */
00555                                 bins, /* bins */
00556                                 draw_rect,/* draw_rect */
00557                                 &outcolor /* histogram rectangle output color & format */
00558                                 );
00559             phCHECK_RC(rc,NULL,"histogram->set failed");
00560         }
00561 
00562         if (glbl_print_histogram) histData->print_data();
00563  
00564         blob_color      = histData->getColor();
00565         threshold_color = histData->getThreshold();
00566 
00567         /* let's read in the color file continuously and set it as our segmentation color */
00568         if ((filename != NULL) && (glbl_load_color))
00569         {
00570             uint32_t tempnum = 0;
00571             if (load_color_array != NULL)
00572             {
00573                 memset(load_color_array,0,sizeof(phColor)*2);
00574             }
00575             phColorLoad(filename,2,&tempnum,(phColor **)&load_color_array);
00576             phPRINT("Read %d\n",tempnum);
00577             /* -1 defaults the printing to stdout */
00578             blob_color = load_color_array[0];
00579             threshold_color = load_color_array[1];
00580             phColorPrint(-1,blob_color);
00581             phColorPrint(-1,threshold_color);
00582         
00583             histData->setColor(blob_color);
00584             histData->setThreshold(threshold_color);
00585         }
00586 
00587 #if 0
00588         /* Adjust the value/thresholds and reapply to the hist data object
00589          * so you can visualize what's being matched */
00590 //        blob_color.hsv24.h = 7;
00591 //        threshold_color.hsv24.h = 7;
00592         
00593 //        blob_color.hsv24.v = 227;
00594         threshold_color.hsv24.s = 160;
00595         threshold_color.hsv24.v = 60;
00596         
00597         histData->setColor(blob_color);
00598         histData->setThreshold(threshold_color);
00599 #endif
00600         histData->generateImage(height);
00601 
00602 
00603         /* if filename is given it will save the color values to the file */
00604         if ((filename != NULL) && (glbl_save_color))
00605         {
00606             save_color_array[0] = blob_color;
00607             save_color_array[1] = threshold_color;
00608             phColorSave(filename,2,save_color_array);
00609             /* -1 defaults the printing to stdout */
00610             phColorPrint(-1,blob_color);
00611             phColorPrint(-1,threshold_color);
00612         }
00613 
00614         blob->set(&blob_color,&threshold_color,
00615                   1,&outcolor,1,1,min_size);
00616         
00617         rc = blobData->update();
00618         phCHECK_RC(rc,NULL,"");
00619         
00620         if (glbl_print_blobs && blobData->getTotalBlobs(min_size))
00621         {
00622             blobData->print_data(min_size);
00623         }
00624 
00625         /* if the file changes, it needs to be updated */
00626         if (hsvthresh_file != NULL)
00627         {   
00628             hsvthresh_load_colors( hsvthresh,
00629                                    hsvthresh_file,
00630                                    &hsvthresh_ncolors,
00631                                    &hsvthresh_colors );
00632             //hsvthresh_apply_colors( hist_hsvthresh, hsvthresh_ncolors, hsvthresh_colors );
00633         }
00634 
00635         /* Save images as they are processed */
00636         if (glbl_save_images)
00637         {
00638             rc = blobimg.update( phLiveObjectNOWAIT );
00639             if( rc == phLiveObjectUPDATED )
00640             {
00641                 sprintf(histfilename,"images/hist%08d.jpg", histcount++ );
00642                 sprintf(blobfilename,"images/blob%08d.jpg", blobcount++ );
00643             
00644                 rc = histimg.update( phLiveObjectWAIT );
00645                 
00646                 phPRINT("%s\n",histfilename);
00647                 histimg.save( histfilename );
00648                 blobimg.save( blobfilename );
00649             }
00650         }
00651         /* Yielding is optional. This gives up the thread's timeslice
00652          * to prevent slow response in other threads. It consumes more
00653          * CPU cycles than sleeping. Use it instead of sleeping if
00654          * this loop is processing anything */
00655         
00656         phYield();
00657 
00658         if (nDisplays > 0)
00659         {
00660             displaysOpen = 0;
00661             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00662             {
00663                 if (displays[i]->isOpen() == 1)
00664                 {
00665                     displaysOpen = 1;
00666                 }
00667             }
00668         }
00669         
00670         /* Remove this if block when using this code as an example */
00671         /* Set the loop control value to end the loop when testing */
00672         if (test > 0)
00673         { 
00674             test--;
00675             if (test == 0)
00676                 displaysOpen = 0;
00677         }
00678     }
00679     /* 6.) Shutdown the system */
00680     rc = system.shutdown();
00681     phPRINT_RC(rc,NULL,"system.shutdown()");
00682 
00683     rc = blobData->disconnect();
00684     phCHECK_RC(rc,NULL,"blobData->disconnect()");
00685    
00686     rc = histData->disconnect();
00687     phCHECK_RC(rc,NULL,"histData->disconnect()");
00688     
00689 error:
00690     for (i = 0; (i < nDisplays) && (displays != NULL); i++)
00691     {
00692         phDelete(displays[i]);
00693     }
00694   
00695     phDeleteArray(displays);
00696 
00697     phDelete(hsvthresh)
00698     phDelete(hist_convert);
00699     phDelete(hist_gauss);
00700     phDelete(blob_convert);
00701     phDelete(blob_gauss);
00702     phDelete(blob);
00703     phDelete(histogram);
00704 
00705     phDelete(blobData);
00706     phDelete(histData);
00707    
00708     for (i = 0; (i < nPipelines) && (pipelines != NULL); i++ )
00709     {
00710         phDelete(pipelines[i]);
00711     }
00712    
00713     phDeleteArray(pipelines);
00714     
00715     phDelete(capture);
00716     phFree(histogram_file);
00717     phFree(hsvthresh_file);
00718     phFree(filename);
00719     
00720     phFree(capture_path);
00721     phDelete(arg_parser);
00722 
00723     return phSUCCESS;
00724 }




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