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

SubtractFilterTest.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 #include <SubtractFilterTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 
00018 /* ------------------------------------------------------------------------ */
00019 int 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>    Sleep <value> seconds and then close test\n");
00025     printf("\n\n");
00026     exit(1);
00027 }
00028         
00029 /* ------------------------------------------------------------------------ */
00030 int main(int argc, char *argv[] )
00031 {
00032     phFUNCTION("main")
00033 
00034     unsigned int    i               = 0;
00035 
00036     unsigned int        nDisplays       = 1;
00037     int                 displaysOpen    = 1;
00038     char                title[255];
00039     phDisplayInterface  **display       = NULL;
00040 
00041     char        *capture_path   = NULL;
00042     int         channel         = 0;
00043         
00044 #ifdef WIN32
00045     VFWSource       *capture    = new VFWSource();
00046 #else
00047     V4LCapture      *capture    = new V4LCapture();
00048 #endif
00049     
00050     phPipeline      *pipeline   = new phPipeline();
00051     
00052     subtract_Filter *sub        = new subtract_Filter(3);
00053     
00054     /* Utility class to ease the starting and stopping of displays, captures and
00055      * pipelines */
00056     phSystem        system;
00057    
00058     /* Remove the code below when using this code as an example.
00059      * 
00060      * This just checks whether "--test" has been specified with
00061      * a time value argument. It's for testing all the examples
00062      * without the need for human intervention. */
00063     int             test = 0;
00064 
00065     phArgTable      *arg_parser = new phArgTable();
00066 
00067     rc = arg_parser->add("--test",&test,phARG_INT);
00068     phCHECK_RC(rc,NULL,"arg_parser->add");
00069     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00070     phCHECK_RC(rc,NULL,"arg_parser->add");
00071     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00072     phCHECK_RC(rc,NULL,"arg_parser->add");
00073     
00074     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00075     phCHECK_RC(rc,NULL,"arg_parser->add");
00076 
00077     rc = arg_parser->add("--channel",&channel,phARG_INT);
00078     phCHECK_RC(rc,NULL,"arg_parser->add");
00079     
00080     rc = arg_parser->parse(argc,argv);
00081     phCHECK_RC(rc,NULL,"arg_parser->parse");
00082     
00083     if (glbl_disable_displays) nDisplays = 0;
00084     
00085     
00086     /* <> Setup the capture device parameters */
00087     capture->set(320,240,capture_path);
00088     capture->setChannel(channel);
00089 
00090     rc = system.addCapture(capture);
00091     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00092         
00093     display = new phDisplayInterface *[nDisplays];
00094     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00095     
00096     for (i = 0; i < nDisplays; i++ )
00097     {
00098         sprintf(title,"SubtractFilterTest[%u]",i);
00099 #if defined(PH_HAVE_SDL)
00100         display[i] = new SDLDisplay(320,240,title);
00101 #elif defined(WIN32)
00102         display[i] = new GDIDisplay(320,240,title);
00103 #else
00104         display[i] = new X11Display(320,240,title);
00105 #endif
00106 
00107         rc = system.addDisplay(display[i]);
00108         phPRINT_RC(rc,NULL,"system.addDisplay(display[i:%d])",i);
00109     }
00110 
00111     rc = system.addPipeline(pipeline);
00112     phPRINT_RC(rc,NULL,"system.addPipeline(pipeline)");
00113     
00114 
00115     /* <> Attach the displays to the live sources */
00116     /* Capture -> (b)phPipeline -> (a)Processed Output Display */
00117     
00118     /* <> Attach the Pipeline output image to the display so the
00119      * display updates when a processing has been completed
00120      * for each loop */
00121     for (i = 0; i < nDisplays; i++)
00122     {
00123         display[i]->setLiveSourceInput(pipeline->getLiveSourceOutput());
00124     }
00125     
00126     /* <> Attach the capture image to the live source input of the
00127      * Pipeline so processing is done automatically once the 
00128      * pipeline is started. */
00129     pipeline->setLiveSourceInput(capture->getLiveSourceOutput());
00130     
00131     /* <> Add the filter(s) into the pipeline in the order they will 
00132      * be used */
00133     pipeline->add(sub);
00134 
00135 
00136     /* <> Startup the system */
00137     rc = system.startup();
00138     phPRINT_RC(rc,NULL,"system.startup()");
00139     
00140     /* <> Keep going until all the windows are closed */
00141     displaysOpen = 1;
00142     while (displaysOpen)
00143     {
00144         /* Sleep a while, don't loop tightly */
00145 
00146         phMSleep(100);
00147         
00148         /* Yielding is optional. This gives up the thread's timeslice
00149          * to prevent slow response in other threads. It consumes more
00150          * CPU cycles than sleeping. Use it instead of sleeping if
00151          * this loop is processing anything */
00152         
00153         /* phYield(); */
00154         
00155         if (nDisplays > 0)
00156         {
00157             displaysOpen = 0;
00158             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00159             {
00160                 if (display[i]->isOpen() == 1)
00161                 {
00162                     displaysOpen = 1;
00163                 }
00164             }
00165         }
00166         
00167         /* Remove this if block when using this code as an example */
00168         /* Set the loop control value to end the loop when testing */
00169         if (test > 0)
00170         { 
00171             displaysOpen = 0;
00172             phSleep(test); /* test's value should be a time (in secs) value > 0*/
00173         }
00174     }
00175 
00176     /* <> Shutdown the system */
00177     rc = system.shutdown();
00178     phPRINT_RC(rc,NULL,"system.shutdown()");
00179 
00180 
00181 error:
00182     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00183     {
00184         phDelete(display[i]);
00185     }
00186   
00187     phDeleteArray(display);
00188 
00189     phDelete(capture);
00190     
00191     phDelete(sub);
00192   
00193     phDelete(pipeline);
00194 
00195     phFree(capture_path);
00196     phDelete(arg_parser);
00197 
00198     return phSUCCESS;
00199 }




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