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

X11PipelineTest.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 <X11PipelineTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 int glbl_do_timing = 0;
00018 
00019 /* ------------------------------------------------------------------------ */
00020 void usage()
00021 {
00022     printf("\n\nUsage:\n");
00023     printf("\t--help            Display usage\n");
00024     printf("\t--nodisplay       Disable the allocation, opening or any use of a display.\n");
00025     printf("\t--test <value>    Loop <value> times and then close test\n");
00026     printf("\n\n");
00027     
00028     exit(1);
00029 }
00030 
00031 /* ------------------------------------------------------------------------ */
00032 /* ------------------------------------------------------------------------ */
00033 int main(int argc, char *argv[] )
00034 {
00035     phFUNCTION("main")
00036 
00037     unsigned int    i               = 0;
00038 
00039     unsigned int        nDisplays   = 1;
00040     int                 displaysOpen= 1;
00041     char                title[255];
00042     phDisplayInterface  **display   = NULL;
00043 
00044     char            *capture_path   = NULL;
00045     int             channel         = 0;
00046     
00047 #ifdef WIN32
00048     VFWSource       *capture    = new VFWSource();
00049 #else
00050     V4LCapture      *capture    = new V4LCapture();
00051 #endif
00052     
00053     phPipeline      *pipeline   = new phPipeline();
00054     
00055     empty_Filter    *empty      = new empty_Filter();
00056 #if PH_HAVE_OPENCV
00057     cv_canny_Filter *canny      = new cv_canny_Filter(50,105);
00058 #else
00059     canny_Filter    *canny      = new canny_Filter(50,105);
00060 #endif
00061     inverse_Filter  *inverse    = new inverse_Filter();
00062     
00063     /* Utility class to ease the starting and stopping of displays, captures and
00064      * pipelines */
00065     phSystem        system;
00066    
00067     /* Remove the code below when using this code as an example.
00068      * 
00069      * This just checks whether "--test" has been specified with
00070      * a time value argument. It's for testing all the examples
00071      * without the need for human intervention. */
00072     int             test = 0;
00073 
00074     phArgTable      *arg_parser = new phArgTable();
00075 
00076     /* Setup and parse all the arguments */
00077     rc = arg_parser->add("--test",&test,phARG_INT);
00078     phCHECK_RC(rc,NULL,"arg_parser->add");
00079     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
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->add("--path",&capture_path,phARG_CHAR);
00085     phCHECK_RC(rc,NULL,"arg_parser->add");
00086     rc = arg_parser->add("--channel",&channel,phARG_INT);
00087     phCHECK_RC(rc,NULL,"arg_parser->add");
00088     
00089     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00090     phCHECK_RC(rc,NULL,"arg_parser->add");
00091 
00092     rc = arg_parser->add("--channel",&channel,phARG_INT);
00093     phCHECK_RC(rc,NULL,"arg_parser->add");
00094     
00095     rc = arg_parser->add("--timing",&glbl_do_timing,phARG_BOOL);
00096     phCHECK_RC(rc,NULL,"arg_parser->add");
00097     
00098     rc = arg_parser->parse(argc,argv);
00099     phCHECK_RC(rc,NULL,"arg_parser->parse");
00100     
00101     if (glbl_disable_displays) nDisplays = 0;
00102     if (test) glbl_do_timing = 1;
00103     
00104 
00105     /* 1.) Setup the capture device parameters */
00106     capture->set(320,240,capture_path);
00107     capture->setChannel(channel);
00108     
00109     rc = system.addCapture(capture);
00110     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00111     
00112     display = new phDisplayInterface *[nDisplays];
00113     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00114 
00115     for (i = 0; i < nDisplays; i++ )
00116     {
00117         sprintf(title,"X11PipelineTest[%u]",i);
00118         
00119         display[i] = new X11Display(320,240,title);
00120 
00121         rc = system.addDisplay(display[i]);
00122         phPRINT_RC(rc,NULL,"system.addDisplay(display[%u])",i);
00123     }
00124     
00125     rc = system.addPipeline(pipeline);
00126     phPRINT_RC(rc,NULL,"system.addPipeline(pipeline)");
00127 
00128     
00129     /* <> Attach the displays to the live sources */
00130     /* Capture -> (b)phPipeline -> (a)Processed Output Display */
00131     
00132     /* <> Attach the Pipeline output image to the display so the
00133      * display updates when a processing has been completed
00134      * for each loop */
00135     for (i = 0; i < nDisplays; i++)
00136     {
00137         display[i]->setLiveSourceInput(pipeline->getLiveSourceOutput());
00138     }
00139     
00140     /* <> Attach the capture image to the live source input of the
00141      * Pipeline so processing is done automatically once the 
00142      * pipeline is started. */
00143     pipeline->setLiveSourceInput(capture->getLiveSourceOutput());
00144     
00145     /* <> Add the filter(s) into the pipeline in the order they will 
00146      * be used */
00147     pipeline->add(empty);
00148     pipeline->add(canny);
00149     pipeline->add(inverse);
00150 
00151     /* Since timing in the pipeline is disabled by default, enable it */
00152     if (glbl_do_timing)
00153     {
00154         rc = pipeline->enableTiming();
00155         phPRINT_RC(rc,NULL,"pipeline->enableTiming()");
00156     }
00157 
00158     /* <> Startup the system */
00159     rc = system.startup();
00160     phPRINT_RC(rc,NULL,"system.startup()");
00161     
00162     /* <> Keep going until all the windows are closed */
00163     displaysOpen = 1;
00164     while (displaysOpen)
00165     {
00166         if (glbl_do_timing)
00167         {
00168             /* Reset the average calculations and sleep a second */
00169             rc = pipeline->resetAverage();
00170             phPRINT_RC(rc,NULL,"pipeline->resetAverage()");
00171             
00172             phMSleep(1000);
00173             
00174             /* Report the average using the phTimeStamp report facility
00175              * to allow for portable/robust reporting */
00176             pipeline->averageRuntime().report("X11PipelineTest - Filtering Average");
00177             phPRINT_RC(rc,NULL,"pipeline->averageRuntime()");
00178         }
00179         else
00180         {
00181             /* Sleep a while, don't loop tightly */
00182             phMSleep(100);
00183         }
00184         
00185         /* Yielding is optional. This gives up the thread's timeslice
00186          * to prevent slow response in other threads. It consumes more
00187          * CPU cycles than sleeping. Use it instead of sleeping if
00188          * this loop is processing anything */
00189         
00190         /* phYield(); */
00191    
00192         if (nDisplays > 0)
00193         {
00194             displaysOpen = 0;
00195             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00196             {
00197                 if (display[i]->isOpen() == 1)
00198                 {
00199                     displaysOpen = 1;
00200                 }
00201             }
00202         }
00203         
00204         /* Remove this if block when using this code as an example */
00205         /* Set the loop control value to end the loop when testing */
00206         if (test > 0)
00207         { 
00208             test--;
00209             if (test == 0) 
00210                 displaysOpen = 0;
00211         }
00212     }
00213 
00214 error:
00215     /* <> Shutdown the system */
00216     rc = system.shutdown();
00217     phPRINT_RC(rc,NULL,"system.shutdown()");
00218 
00219     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00220     {
00221         phDelete(display[i]);
00222     }
00223   
00224     phDeleteArray(display);
00225 
00226     phDelete(capture);
00227     
00228     phDelete(empty);
00229     phDelete(canny);
00230     phDelete(inverse);
00231   
00232     phDelete(pipeline);
00233 
00234     phFree(capture_path);
00235     phDelete(arg_parser);
00236 
00237     return phSUCCESS;
00238 }




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