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

MedianBlurTest.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 <MedianBlurTest.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   = 2;
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     medianBlur_Filter   *median     = new medianBlur_Filter();
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     /* Setup and parse all the arguments */
00068     rc = arg_parser->add("--test", &test, phARG_INT);
00069     phCHECK_RC(rc,NULL,"arg_parser->add");
00070     rc = arg_parser->add("--nodisplay", (void *)&glbl_disable_displays, phARG_BOOL);
00071     phCHECK_RC(rc,NULL,"arg_parser->add");
00072     rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC);
00073     phCHECK_RC(rc,NULL,"arg_parser->add");
00074    
00075     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00076     phCHECK_RC(rc,NULL,"arg_parser->add");
00077 
00078     rc = arg_parser->add("--channel",&channel,phARG_INT);
00079     phCHECK_RC(rc,NULL,"arg_parser->add");
00080     
00081     rc = arg_parser->parse(argc,argv);
00082     phCHECK_RC(rc,NULL,"arg_parser->parse");
00083 
00084     if (glbl_disable_displays) nDisplays = 0;
00085     
00086 
00087     /* <> Setup the capture device parameters */
00088     capture->set(320,240,capture_path);
00089     capture->setChannel(channel);
00090     /* capture->setFormat(phImageGREY8); */
00091     
00092     rc = system.addCapture(capture);
00093     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00094     
00095     display = new phDisplayInterface *[nDisplays];
00096     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00097     
00098     for (i = 0; i < nDisplays; i++ )
00099     {
00100         sprintf(title,"MedianBlurTest[%u]",i);
00101 
00102 #if defined(PH_HAVE_X11)
00103         display[i] = new X11Display(320,240,title);
00104 #elif defined(PH_HAVE_GDI)
00105         display[i] = new GDIDisplay(320,240,title);
00106 #endif
00107 
00108         rc = system.addDisplay(display[i]);
00109         phPRINT_RC(rc,NULL,"system.addDisplay(display[i:%d])",i);
00110     }
00111 
00112     rc = system.addPipeline(pipeline);
00113     phPRINT_RC(rc,NULL,"system.addPipeline(pipeline)");
00114     
00115     
00116     /* <> Attach the displays to the live sources */
00117     /* Capture -> (a)Capture Display */
00118     /* Capture -> (c)phPipeline -> (b)Processed Output Display */
00119     
00120     /* <> Attach the capture class to the display to display the 
00121      * unprocessed data */
00122     if (nDisplays > 0)
00123         display[0]->setLiveSourceInput(capture->getLiveSourceOutput());
00124         
00125     /* <> Attach the Pipeline output image to the display so the
00126      * display updates when a processing has been completed
00127      * for each loop */
00128     if (nDisplays > 1)
00129         display[1]->setLiveSourceInput(pipeline->getLiveSourceOutput());
00130         
00131     /* <> Attach the capture image to the live source input of the
00132      * Pipeline so processing is done automatically once the 
00133      * pipeline is started. */
00134     pipeline->setLiveSourceInput(capture->getLiveSourceOutput());
00135     
00136     /* <> Add the filter(s) into the pipeline in the order they will 
00137      * be used */
00138     pipeline->add(median);
00139 
00140     
00141     /* <> Startup the system */
00142     rc = system.startup();
00143     phPRINT_RC(rc,NULL,"system.startup()");
00144     
00145     /* <> Keep going until all the windows are closed */
00146     displaysOpen = 1;
00147     while (displaysOpen)
00148     {
00149         /* Sleep a while, don't loop tightly */
00150 
00151         phMSleep(100);
00152         
00153         /* Yielding is optional. This gives up the thread's timeslice
00154          * to prevent slow response in other threads. It consumes more
00155          * CPU cycles than sleeping. Use it instead of sleeping if
00156          * this loop is processing anything */
00157         
00158         /* phYield(); */
00159         
00160         if (nDisplays > 0)
00161         {
00162             displaysOpen = 0;
00163             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00164             {
00165                 if (display[i]->isOpen() == 1)
00166                 {
00167                     displaysOpen = 1;
00168                 }
00169             }
00170         }
00171         
00172         /* Remove this if block when using this code as an example */
00173         /* Set the loop control value to end the loop when testing */
00174         if (test > 0)
00175         { 
00176             displaysOpen = 0;
00177             phSleep(test); /* test's value should be a time (in secs) value > 0*/
00178         }
00179     }
00180 
00181     /* 6.) Shutdown the system */
00182     rc = system.shutdown();
00183     phPRINT_RC(rc,NULL,"system.shutdown()");
00184 
00185 error:
00186     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00187     {
00188         phDelete(display[i]);
00189     }
00190   
00191     phDeleteArray(display);
00192 
00193     phDelete(capture);
00194     phDelete(median);
00195     phDelete(pipeline);
00196 
00197     phFree(capture_path);
00198     phDelete(arg_parser);
00199 
00200     return phSUCCESS;
00201 }




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