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

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




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