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

BlobifyMatchTest.cpp

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  ---------------------------------------------------------------------------*/
00012 #include <BlobifyMatchTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 
00018 /* ------------------------------------------------------------------------ */
00019 void usage()
00020 {
00021     printf("\n\nUsage:\n");
00022     printf("\t--help            Display usage\n");
00023     printf("\t--nodisplay       Disable the allocation, opening or any use of a display.\n");
00024     printf("\t--test <value>    Iterate through <value> frames\n");
00025     printf("\t--file <filename> Use <filename> prefix for the input images (ppm)\n");
00026     printf("\n\n");
00027     exit(1);
00028 }
00029  
00030 /* ------------------------------------------------------------------------ */
00031 int main(int argc, char *argv[] )
00032 {
00033     phFUNCTION("main")
00034 
00035     unsigned int    i = 0;
00036 
00037     /* Used to read in test image for blobbing */
00038     unsigned int        nimages         = 2;
00039     unsigned int        j               = 0;
00040     phImage             inputimage;
00041     phImage             *file_images    = NULL;
00042     char                imgfilename[255];
00043     char                *filename       = NULL;
00044     
00045     /* Display variables */
00046     unsigned int        nDisplays       = 1;
00047     int                 displaysOpen    = 1;
00048     char                title[255];
00049     phDisplayInterface  **display       = NULL;
00050     
00051     /* The filter pipeline */
00052     phPipeline      *pipeline           = new phPipeline();
00053 
00054     /* Empty: Used to make sure the live source is working */
00055     empty_Filter    *empty              = new empty_Filter();
00056     blobify_Filter  *blob               = new blobify_Filter();
00057     match_Filter    *match              = new match_Filter();
00058     
00059     /* Utility class to ease the starting and stopping of displays, captures and
00060      * pipelines */
00061     phSystem        *system             = new phSystem();
00062    
00063     /* Remove the code below when using this code as an example.
00064      * 
00065      * This just checks whether "--test" has been specified with
00066      * a time value argument. It's for testing all the examples
00067      * without the need for human intervention. */
00068     int             test = 0;
00069 
00070     phArgTable      *arg_parser = new phArgTable();
00071 
00072     /* Setup and parse all the arguments */
00073     rc = arg_parser->add("--test", &test, phARG_INT);
00074     phCHECK_RC(rc,NULL,"arg_parser->add");
00075     rc = arg_parser->add("--nodisplay", (void *)&glbl_disable_displays, phARG_BOOL);
00076     phCHECK_RC(rc,NULL,"arg_parser->add");
00077     rc = arg_parser->add("--file", &filename, phARG_CHAR);
00078     phCHECK_RC(rc,NULL,"arg_parser->add");
00079     rc = arg_parser->add("--nimages", &nimages, phARG_INT);
00080     phCHECK_RC(rc,NULL,"arg_parser->add");
00081     rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC);
00082     phCHECK_RC(rc,NULL,"arg_parser->add");
00083     
00084     rc = arg_parser->parse(argc,argv);
00085     phCHECK_RC(rc,NULL,"arg_parser->parse");
00086    
00087     if (glbl_disable_displays) nDisplays = 0;
00088     
00089     file_images = new phImage[nimages];
00090     
00091     /* load the images */
00092     for (i = 0; i < nimages; i++)
00093     {
00094         if (filename == NULL)
00095             sprintf(imgfilename,"../images/thisisatest_%04d.ppm",i);
00096         else
00097             sprintf(imgfilename,"%s_%04d.ppm",filename,i);
00098         
00099         rc = file_images[i].load(imgfilename);
00100         phCHECK_RC(rc,NULL,"image loading failed");
00101     }
00102 
00103     display = new phDisplayInterface *[nDisplays];
00104     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00105     
00106     for (i = 0; i < nDisplays; i++ )
00107     {
00108         sprintf(title,"BlobifyMatchTest[%u]",i);
00109 
00110 #if defined(PH_HAVE_X11)
00111         display[i] = new X11Display(320,240,title);
00112 #elif defined(PH_HAVE_GDI)
00113         display[i] = new GDIDisplay(320,240,title);
00114 #endif
00115 
00116         rc = system->addDisplay(display[i]);
00117         phPRINT_RC(rc,NULL,"system->addDisplay(display[i:%d])",i);
00118     }
00119 
00120     rc = system->addPipeline(pipeline);
00121     phPRINT_RC(rc,NULL,"system->addPipeline(pipeline)");
00122           
00123     
00124     /* <> Attach the displays to the live sources */
00125     /* Image -> (b)phPipeline -> (a)Processed Output Display */
00126     
00127     /* <> Attach the Pipeline output image to the display so the
00128      * display updates when a processing has been completed
00129      * for each loop */
00130     if (nDisplays > 0)
00131         display[0]->setLiveSourceInput(pipeline->getLiveSourceOutput());
00132     if (nDisplays > 1)
00133         display[1]->setLiveSourceInput(&inputimage);
00134     
00135     /* <> Attach the image to the live source input of the
00136      * Pipeline so processing is done automatically once the 
00137      * pipeline is started. */
00138     pipeline->setLiveSourceInput(&inputimage);
00139     
00140     /* <> Add the filter(s) into the pipeline in the order they will 
00141      * be used */
00142     //pipeline->add(empty);
00143     match->set(255,0,0,0,phGreenChannel,phMatchOverlay);
00144     pipeline->add(match);
00145     
00146     blob->set(1,255,255,0,0,1);
00147     pipeline->add(blob);
00148     
00149     
00150     /* <> Startup the system */
00151     rc = system->startup();
00152     phPRINT_RC(rc,NULL,"system->startup()");
00153     
00154     /* <> Keep going until all the windows are closed */
00155     displaysOpen = 1;
00156     while (displaysOpen)
00157     {
00158         /* Sleep a little between frames, otherwise we get an 
00159          * insane frame rate */
00160         /* Sleep a while, don't loop tightly */
00161 
00162         phMSleep(100);
00163         
00164         /* Yielding is optional. This gives up the thread's timeslice
00165          * to prevent slow response in other threads. It consumes more
00166          * CPU cycles than sleeping. Use it instead of sleeping if
00167          * this loop is processing anything */
00168         
00169         /* phYield(); */
00170 
00171         rc = inputimage.setImage(file_images[j]);
00172         phPRINT_RC(rc,NULL,"setImage failed");
00173         if (rc != 0) { displaysOpen = 0; continue; }
00174         
00175         j++;
00176         if (j >= nimages) j = 0;
00177         
00178         if (nDisplays > 0)
00179         {
00180             displaysOpen = 0;
00181             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00182             {
00183                 if (display[i]->isOpen() == 1)
00184                 {
00185                     displaysOpen = 1;
00186                 }
00187             }
00188         }
00189         
00190         /* Remove this if block when using this code as an example */
00191         /* Set the loop control value to end the loop when testing */
00192         if (test > 0)
00193         { 
00194             test--;
00195             if (test == 0)
00196                 displaysOpen = 0;
00197         }
00198     }
00199 
00200     /* <> Shutdown the system */
00201     rc = system->shutdown();
00202     phPRINT_RC(rc,NULL,"system->shutdown()");
00203 
00204 
00205 error:
00206     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00207     {
00208         phDelete(display[i]);
00209     }
00210   
00211     phDeleteArray(display);
00212 
00213     phDelete(blob);
00214     phDelete(match);
00215     
00216     phDelete(empty);
00217     phDelete(pipeline);
00218 
00219     phDelete(system);
00220 
00221     phDeleteArray(file_images);
00222 
00223     phFree(filename);
00224     phDelete(arg_parser);
00225 
00226     return phSUCCESS;
00227 }




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:04 2007 for phission by  doxygen 1.4.4